-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmerge_result.py
45 lines (37 loc) · 1.35 KB
/
merge_result.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
38
39
40
41
42
43
44
45
import os
import json
import sys
def merge_json_files(date_str):
base_dir = f'results-{date_str}'
speed_file_path = os.path.join(base_dir, 'speed', 'reports', 'speed.json')
memory_file_path = os.path.join(base_dir, 'memory', 'reports', 'memory.json')
result_file_path = os.path.join(base_dir, 'result.json')
# Ensure the files exist
if not os.path.exists(speed_file_path):
print(f"Speed file not found: {speed_file_path}")
return
if not os.path.exists(memory_file_path):
print(f"Memory file not found: {memory_file_path}")
return
# Read the speed data
with open(speed_file_path, 'r') as speed_file:
speed_data = json.load(speed_file)
# Read the memory data
with open(memory_file_path, 'r') as memory_file:
memory_data = json.load(memory_file)
# Merge the data
result_data = {
'speed': speed_data,
'memory': memory_data
}
# Save the merged data
with open(result_file_path, 'w') as result_file:
json.dump(result_data, result_file, indent=4)
print(f"Merged data saved to {result_file_path}")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python merge_json.py <date>")
print("Example: python merge_json.py 20230102")
else:
date_str = sys.argv[1]
merge_json_files(date_str)