-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagg_results.py
41 lines (28 loc) · 1.25 KB
/
agg_results.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
import os
import json
agg_results = {}
agg_filename = "agg_results.json"
def define_key_subkey(filename):
key = ""
subkey = ""
aux = filename.split("_")
if filename.startswith("Sc1") or filename.startswith("Sc_3") or filename.startswith("Sc_4"):
def define_key(x): return "_".join(x[:3] + x[4:])
elif filename.startswith("Sc_2"):
def define_key(x): return "_".join(x[:4] + x[5:])
key = define_key(aux)
subkey = "CNN1D" if filename.find(
"CNN1D") > -1 else "MLP" if filename.find("MLP") > -1 else ""
return key, subkey
# Para cada resultado '.json' registrado no diretório results, carregue o arquivo e agrupe-o em um novo json file
for i, filename in enumerate(sorted(os.listdir("results"))):
if filename.endswith(".json"):
with open(f"results/{filename}", "r") as file:
key, subkey = define_key_subkey(filename[:-5])
# Temos que aplicar essa lógica para não sobrescrever agg_results[key][subkey]
if agg_results.get(key) is None:
agg_results[key] = {}
agg_results[key].update({subkey: json.load(file)})
with open(agg_filename, "w") as f:
json.dump(agg_results, f, indent=4)
print(f"{i+1} elementos agrupados em {agg_filename}")