-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregate.py
38 lines (29 loc) · 1.18 KB
/
aggregate.py
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
import json
import os
import argparse
def save_results(in_path: str, out_path: str, id: str):
# Get new data
with open(in_path, 'r') as in_file:
new_data = json.load(in_file)
del new_data["benchmarks"][0]["stats"]["data"]
new_data["benchmarks"][0]["commit_info"] = new_data["commit_info"]
new_data["benchmarks"][0]["heat_commit_id"] = id
if os.path.isfile(out_path) and os.access(out_path, os.R_OK):
# checks if file exists
print("Path exists")
with open(out_path, 'r+') as out_file:
file_data =json.load(out_file)
file_data.append(new_data["benchmarks"][0])
out_file.seek(0)
json.dump(file_data, out_file, indent=4)
else:
print ("aggregate file is missing or is not readable, creating file...")
with open(out_path, 'w') as out_file:
out_file.write(json.dumps([new_data["benchmarks"][0]], indent=4))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("in_path")
parser.add_argument("out_path")
parser.add_argument("id")
args = parser.parse_args()
save_results(args.in_path, args.out_path, args.id)