forked from MahmudulHasn/python-energy-microscope
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_avg.py
More file actions
51 lines (40 loc) · 1.55 KB
/
Copy pathtime_avg.py
File metadata and controls
51 lines (40 loc) · 1.55 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
import csv
import os
import sys
def compute_package_avg(file_path):
with open(file_path, 'r') as f:
reader = csv.DictReader(f)
package_values = []
for row in reader:
try:
val = float(row['execution_time (s)'])
package_values.append(val)
except (ValueError, KeyError):
continue # Skip invalid or missing values
if not package_values:
return None
#print(f"{file_path} - {len(package_values)}")
return sum(package_values) / len(package_values)
def main(folder_path, output_file):
csv_files = [f for f in os.listdir(folder_path) if f.endswith('.csv')]
if not csv_files:
print("No CSV files found in the given folder.")
return
with open(output_file, 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['filename', 'execution_time (s)'])
for file_name in csv_files:
full_path = os.path.join(folder_path, file_name)
avg = compute_package_avg(full_path)
if avg is not None:
writer.writerow([file_name.split('.')[0], avg])
else:
print(f"Skipped {file_name} — no valid 'execution_time (s)' data.")
print(f"Averages saved to '{output_file}'.")
if __name__ == '__main__':
if len(sys.argv) != 3:
print("Usage: python average_package_time.py <folder_path> <output_csv>")
else:
folder_path = sys.argv[1]
output_file = sys.argv[2]
main(folder_path, output_file)