-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsummary.py
More file actions
executable file
·29 lines (27 loc) · 867 Bytes
/
summary.py
File metadata and controls
executable file
·29 lines (27 loc) · 867 Bytes
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
import os
import csv
import pandas as pd
def summarize_profiling(csv_path: str) -> dict:
totals = {}
total_nums = {}
avgs = {}
with open(csv_path, 'r', newline='') as f:
reader = csv.dictReader(f)
for row in reader:
for k, v in row.items():
try:
val = float(v)
except ValueError:
continue
if val != 0.0:
total_nums[k] = total_nums.get(k, 0) + 1
totals[k] = totals.get(k, 0.0) + val
print(pd.DataFrame([totals]).T)
for k, v in totals.items():
if k in total_nums and total_nums[k] > 0:
avgs[k] = v / total_nums[k]
else:
avgs[k] = 0.0
print(pd.DataFrame([avgs]).T)
if __name__ == "__main__":
summarize_profiling("log/attention_profile.csv")