-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_results_1.py
More file actions
108 lines (88 loc) · 4.05 KB
/
plot_results_1.py
File metadata and controls
108 lines (88 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import json
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from collections import defaultdict
def _plot(by_server, unit: str, ax_plot, ax_table):
"""Shared plotting logic. unit must be 'bps' or 'Mbps'."""
scale = 1e6 if unit == 'Mbps' else 1.0
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
summary_rows = []
for idx, (server, server_runs) in enumerate(sorted(by_server.items())):
color = colors[idx % len(colors)]
all_values = []
for run_idx, run in enumerate(server_runs):
samples = run.get('goodput_samples', [])
if not samples:
continue
t_values = [s['t'] for s in samples]
y_values = [s['goodput_bps'] / scale for s in samples]
all_values.extend(y_values)
label = server if run_idx == 0 else None
ax_plot.plot(t_values, y_values, color=color, alpha=0.8, linewidth=1.2, label=label)
if all_values:
summary_rows.append((
server,
f"{np.min(all_values):.2f}",
f"{np.median(all_values):.2f}",
f"{np.mean(all_values):.2f}",
f"{np.percentile(all_values, 95):.2f}",
))
ax_plot.set_xlabel("Time (s)")
ax_plot.set_ylabel(f"Goodput ({unit})")
ax_plot.set_title("Goodput over Time")
ax_plot.yaxis.set_major_formatter(ticker.FormatStrFormatter('%.1f'))
ax_plot.legend(loc='upper left', fontsize=8, framealpha=0.7)
ax_plot.grid(True, linestyle='--', alpha=0.4)
ax_table.axis('off')
ax_table.set_title(f"Summary Statistics ({unit})", fontsize=10, fontweight='bold', pad=10)
if summary_rows:
col_labels = ["Destination", "Min", "Median", "Avg", "P95"]
table = ax_table.table(
cellText=summary_rows,
colLabels=col_labels,
loc='center',
cellLoc='center',
)
table.auto_set_font_size(False)
table.set_fontsize(9)
table.auto_set_column_width(col=list(range(len(col_labels))))
for col in range(len(col_labels)):
table[0, col].set_facecolor('#2c3e50')
table[0, col].set_text_props(color='white', fontweight='bold')
for row in range(1, len(summary_rows) + 1):
bg = '#f2f2f2' if row % 2 == 0 else 'white'
for col in range(len(col_labels)):
table[row, col].set_facecolor(bg)
def _make_fig():
fig, (ax_plot, ax_table) = plt.subplots(
nrows=2,
figsize=(14, 10),
gridspec_kw={'height_ratios': [3, 1]}
)
fig.suptitle("Goodput Analysis per Destination", fontsize=14, fontweight='bold')
return fig, ax_plot, ax_table
def plot_goodput(goodput_location: str, output_path: str = "results/goodput_plot.pdf"):
with open(goodput_location, 'r') as f:
runs = json.load(f)
if not runs:
print("No runs found in goodput file.")
return
by_server = defaultdict(list)
for run in runs:
by_server[run['server']].append(run)
# ── bps plot ───────────────────────────────────────────────────────────────
fig, ax_plot, ax_table = _make_fig()
_plot(by_server, 'bps', ax_plot, ax_table)
plt.tight_layout()
plt.savefig(output_path, dpi=150, bbox_inches='tight')
plt.close()
print(f"Plot saved to {output_path}")
# ── Mbps plot ──────────────────────────────────────────────────────────────
mbps_path = output_path.replace('.pdf', '_mbps.pdf')
fig, ax_plot, ax_table = _make_fig()
_plot(by_server, 'Mbps', ax_plot, ax_table)
plt.tight_layout()
plt.savefig(mbps_path, dpi=150, bbox_inches='tight')
plt.close()
print(f"Plot saved to {mbps_path}")