first commit
This commit is contained in:
commit
27e101260c
6 changed files with 547 additions and 0 deletions
60
latency/generate_graph.py
Normal file
60
latency/generate_graph.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import argparse
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def shorten_title(title, max_len=12):
|
||||
"""Return a shortened title for plotting."""
|
||||
return title if len(title) <= max_len else title[:max_len] + "..."
|
||||
|
||||
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 = [shorten_title(t) 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.xticks(rotation=45, ha="right")
|
||||
plt.xlabel("Name")
|
||||
plt.ylabel("Latency (seconds)")
|
||||
plt.title(f"Latency Performance of {args.user}")
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig(args.output)
|
||||
|
||||
print(f"Graph saved to: {args.output}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue