| 5 | WINDOW = 5 |
| 6 | |
| 7 | def read_avg_speed(path): |
| 8 | data = [] |
| 9 | with open(path) as f: |
| 10 | last_time = 0 |
| 11 | line = f.readline() |
| 12 | window_total_speed = [0, 0, 0] |
| 13 | window_num = 0 |
| 14 | |
| 15 | global_total_speed = 0 |
| 16 | global_num = 0 |
| 17 | |
| 18 | while line: |
| 19 | s = line.split(' ') |
| 20 | s = [float(x) for x in s] |
| 21 | t = s[0] |
| 22 | |
| 23 | if int(t) >= last_time + INTERVAL - WINDOW and int(t) < last_time + INTERVAL + WINDOW: |
| 24 | window_total_speed[0] += s[7] |
| 25 | window_total_speed[1] += s[8] |
| 26 | window_total_speed[2] += s[9] |
| 27 | window_num += 1 |
| 28 | elif int(t) >= last_time + INTERVAL + WINDOW: |
| 29 | data.append(( |
| 30 | last_time + INTERVAL, |
| 31 | window_total_speed[0] / window_num, |
| 32 | window_total_speed[1] / window_num, |
| 33 | window_total_speed[2] / window_num)) |
| 34 | window_total_speed = [0, 0, 0] |
| 35 | window_num = 0 |
| 36 | last_time = last_time + INTERVAL |
| 37 | line = f.readline() |
| 38 | |
| 39 | print(path) |
| 40 | |
| 41 | return data |
| 42 | |
| 43 | data_gamma = read_avg_speed('statistics.gamma.log') |
| 44 | data_simple = read_avg_speed('statistics.ttc.log') |