-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_to_csv.py
More file actions
31 lines (25 loc) · 1.12 KB
/
convert_to_csv.py
File metadata and controls
31 lines (25 loc) · 1.12 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
import json
import csv
import os
def convert_to_csv(goodput_path="results/goodput.json", output_dir="results/csv", marker=None):
with open(goodput_path, 'r') as f:
data = json.load(f)
output_dir = output_dir
if not os.path.exists(output_dir):
os.makedirs(output_dir)
for idx, server in enumerate(data):
samples = server['tcpstats_samples']
prefix = f"{marker}_" if marker else ""
filename = os.path.join(output_dir, f'{prefix}trace_{idx}.csv')
with open(filename, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['time', 'goodput_bps', 'rtt_ms', 'loss', 'snd_cwnd'])
for i, sample in enumerate(samples):
writer.writerow([
sample.get('t', ''),
sample.get('goodput_bps', ''),
sample.get('rtt_ms', ''),
sample.get('loss', ''),
sample.get('cwnd', '')
])
print(f'Created trace_{idx}.csv for server: {server["server"]}')