56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
import argparse
|
|
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="Generate latency graph from CSV.")
|
|
parser.add_argument("--input", required=True, help="Input CSV file")
|
|
parser.add_argument("--output", required=True, help="Output PNG path")
|
|
parser.add_argument("--user", required=True, help="Username for graph title")
|
|
args = parser.parse_args()
|
|
|
|
# Load CSV
|
|
df = pd.read_csv(args.input)
|
|
|
|
# Convert to float
|
|
df["Latency(s)"] = pd.to_numeric(df["Latency(s)"], errors="coerce")
|
|
df = df.dropna(subset=["Latency(s)"])
|
|
|
|
latencies = df["Latency(s)"].values
|
|
titles = df["Title"].values
|
|
short_titles = [t.split('_')[0] for t in titles]
|
|
|
|
# Compute average
|
|
avg_latency = latencies.mean()
|
|
|
|
plt.figure(figsize=(14, 6))
|
|
|
|
# --- Bar chart ---
|
|
bars = plt.bar(short_titles, latencies)
|
|
|
|
# --- Average line ---
|
|
plt.axhline(y=avg_latency, linestyle="--")
|
|
plt.text(
|
|
-0.4, avg_latency,
|
|
f"Avg = {avg_latency:.3f}s",
|
|
va="bottom",
|
|
fontsize=10,
|
|
fontweight="bold"
|
|
)
|
|
|
|
# --- Label each bar with exact value ---
|
|
for i, value in enumerate(latencies):
|
|
plt.text(i, value, f"{value:.3f}", ha="center", va="bottom", fontsize=8)
|
|
|
|
plt.xlabel("Image Cases")
|
|
plt.ylabel("Latency (seconds)")
|
|
plt.title(f"Latency Performance of {args.user}")
|
|
plt.ylim(1, 300)
|
|
|
|
plt.tight_layout()
|
|
plt.savefig(args.output)
|
|
|
|
print(f"Graph saved to: {args.output}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|