-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_graphs.py
More file actions
65 lines (47 loc) · 1.95 KB
/
Copy pathplot_graphs.py
File metadata and controls
65 lines (47 loc) · 1.95 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
#!/usr/bin/env python3
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import os
CSV_FILE = 'network_data.csv'
OUTPUT_DIR = 'graphs'
def plot_graphs():
"""
Reads network data from a CSV file and generates two graphs:
"""
if not os.path.exists(CSV_FILE):
print(f"'{CSV_FILE}' não encontrado.")
return
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
df = pd.read_csv(CSV_FILE)
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='s')
sns.set_theme(style="whitegrid")
plt.figure(figsize=(15, 8))
# bps to mpbs
df['throughput_mbps'] = df['throughput_bps'] / 1_000_000
plot1 = sns.lineplot(data=df, x='timestamp', y='throughput_mbps', hue='dpid', palette='viridis', legend='full')
plt.title('Throughput per Switch Over Time', fontsize=16)
plt.xlabel('Time', fontsize=12)
plt.ylabel('Throughput (Mbps)', fontsize=12)
plt.xticks(rotation=45)
plt.legend(title='Switch DPID', bbox_to_anchor=(1.05, 1), loc='upper left')
plt.tight_layout()
output_path1 = os.path.join(OUTPUT_DIR, 'throughput_over_time.png')
plt.savefig(output_path1)
print(f"Graph 1 saved to: {output_path1}")
plt.clf()
plt.figure(figsize=(15, 8))
total_bytes_per_switch = df.groupby('dpid')['bytes_passed'].sum().reset_index()
total_bytes_per_switch['total_megabytes'] = total_bytes_per_switch['bytes_passed'] / (1024 * 1024)
plot2 = sns.barplot(data=total_bytes_per_switch, x='dpid', y='total_megabytes', palette='plasma')
plt.title('Total Data Volume per Switch', fontsize=16)
plt.xlabel('Switch DPID', fontsize=12)
plt.ylabel('Total Volume (MB)', fontsize=12)
plt.xticks(rotation=90, fontsize=8)
plt.tight_layout()
output_path2 = os.path.join(OUTPUT_DIR, 'total_volume_per_switch.png')
plt.savefig(output_path2)
print(f"Graph 2 saved to: {output_path2}")
if __name__ == "__main__":
plot_graphs()