-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreport_metadata.py
49 lines (41 loc) · 1.38 KB
/
report_metadata.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
46
47
48
49
import os
import sys
import json
import yaml
def read_computer_specs(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()
specs = {}
for line in lines[1:]:
if ": " in line:
key, value = line.split(": ", 1)
specs[key.strip()] = value.strip()
return specs
def read_images(file_path):
with open(file_path, 'r') as file:
images = yaml.safe_load(file)
return images
def save_metadata(computer_specs, images, output_path):
metadata = {
'computer_specs': computer_specs,
'images': images
}
with open(output_path, 'w') as file:
json.dump(metadata, file, indent=4)
def main(date, data_type):
base_path = f"results-{date}/{data_type}"
computer_specs_path = os.path.join(base_path, "computer_specs.txt")
images_path = "./images.yaml"
output_path = os.path.join(base_path, "reports", "metadata.json")
if not os.path.exists(os.path.dirname(output_path)):
os.makedirs(os.path.dirname(output_path))
computer_specs = read_computer_specs(computer_specs_path)
images = read_images(images_path)
save_metadata(computer_specs, images, output_path)
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python script.py <date> <data_type>")
sys.exit(1)
date = sys.argv[1]
data_type = sys.argv[2]
main(date, data_type)