-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize.py
More file actions
38 lines (27 loc) · 1.05 KB
/
Copy pathvisualize.py
File metadata and controls
38 lines (27 loc) · 1.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
#Python graphs
import pandas as pd
import matplotlib.pyplot as plt
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
csv_path = os.path.join(BASE_DIR, "packet_log.csv")
df = pd.read_csv(csv_path)
df['timestamp'] = df['timestamp'] - df['timestamp'].min()
# --- Plot 1: Throughput ---
throughput = df.groupby('timestamp')['packet_size'].sum()
fig, axes = plt.subplots(2, 1, figsize=(10, 8))
axes[0].plot(throughput.index, throughput.values, color='steelblue')
axes[0].set_xlabel("Time (s)")
axes[0].set_ylabel("Bytes per second")
axes[0].set_title("Network Throughput Over Time")
axes[0].grid(True)
# --- Plot 2: Inter-Packet Delay (Latency) ---
avg_delay = df.groupby('timestamp')['delay_ms'].mean()
axes[1].plot(avg_delay.index, avg_delay.values, color='coral')
axes[1].set_xlabel("Time (s)")
axes[1].set_ylabel("Avg Delay (ms)")
axes[1].set_title("Inter-Packet Arrival Delay Over Time")
axes[1].grid(True)
plt.tight_layout()
output_path = os.path.join(BASE_DIR, "throughput.png")
plt.savefig(output_path)
print(f"[+] Plot saved to {output_path}")