github.com/network-quality/goresponsiveness@v0.0.0-20240129151524-343954285090/datalogger/munge.py (about) 1 #!/bin/env python3 2 3 from dataclasses import dataclass 4 import csv 5 6 @dataclass 7 class ProbeDataPoint: 8 time: str 9 rtt_count: int 10 duration: float 11 12 @dataclass 13 class ThroughputDataPoint: 14 time: str 15 throughput: str 16 17 def convertDuration(duration: str) -> str: 18 if duration.endswith("ms"): 19 return duration[0:-2] 20 elif duration.endswith("s"): 21 return str(float(duration[0:-1]) * 1000) 22 23 if __name__ == '__main__': 24 # Let's open all the files! 25 foreign_dps = {} 26 self_dps = {} 27 dl_throughput_dps = {} 28 ul_throughput_dps = {} 29 max_happens_after = 0 30 with open("log-foreign-07-29-2022-14-36-39.csv") as foreign_dp_fh: 31 seen_header = False 32 for record in csv.reader(foreign_dp_fh): 33 if not seen_header: 34 seen_header = True 35 continue 36 foreign_dps[record[0]] = ProbeDataPoint(record[1], record[2], convertDuration(record[3])) 37 if int(record[0]) > max_happens_after: 38 max_happens_after = int(record[0]) 39 with open("log-self-07-29-2022-14-36-39.csv") as self_dp_fh: 40 seen_header = False 41 for record in csv.reader(self_dp_fh): 42 if not seen_header: 43 seen_header = True 44 continue 45 self_dps[record[0]] = ProbeDataPoint(record[1], record[2], convertDuration(record[3])) 46 if int(record[0]) > max_happens_after: 47 max_happens_after = int(record[0]) 48 with open("log-throughput-download07-29-2022-14-36-39.csv") as download_dp_fh: 49 seen_header = False 50 for record in csv.reader(download_dp_fh): 51 if not seen_header: 52 seen_header = True 53 continue 54 dl_throughput_dps[record[0]] = ThroughputDataPoint(record[1], record[2]) 55 if int(record[0]) > max_happens_after: 56 max_happens_after = int(record[0]) 57 with open("log-throughput-upload07-29-2022-14-36-39.csv") as upload_dp_fh: 58 seen_header = False 59 for record in csv.reader(upload_dp_fh): 60 if not seen_header: 61 seen_header = True 62 continue 63 ul_throughput_dps[record[0]] = ThroughputDataPoint(record[1], record[2]) 64 if int(record[0]) > max_happens_after: 65 max_happens_after = int(record[0]) 66 67 # Happens After, RT Count (self), RTT (self), RT Count (foreign), RTT (foreign), DL Throughput, UL Throughput 68 current = ["" for _ in range(0, 8)] 69 for ha in range(0, max_happens_after): 70 ha = str(ha) 71 found = True 72 if ha in self_dps: 73 print(f"{ha} is in self_dps") 74 current[0] = str(ha) 75 current[1] = self_dps[str(ha)].rtt_count 76 current[2] = self_dps[str(ha)].duration 77 elif ha in foreign_dps: 78 print(f"{ha} is in foreign_dps") 79 current[0] = str(ha) 80 current[3] = foreign_dps[str(ha)].rtt_count 81 current[4] = foreign_dps[str(ha)].duration 82 elif ha in dl_throughput_dps: 83 print(f"{ha} is in throughput download") 84 current[0] = str(ha) 85 current[5] = dl_throughput_dps[str(ha)].throughput 86 elif ha in ul_throughput_dps: 87 print(f"{ha} is in throughput upload") 88 current[0] = str(ha) 89 current[6] = ul_throughput_dps[str(ha)].throughput 90 else: 91 print(f"Cannot find {ha}.") 92 found = False 93 if found: 94 print(",".join(current))