-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv-to-result.py
63 lines (51 loc) · 1.9 KB
/
csv-to-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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import csv
import sys
from optimization import result
def parse_csv(filepath, ignore_not_converge = True):
results = result.Results()
with open(filepath, 'r') as file:
reader = csv.reader(file, delimiter=',')
# Read the header row to get column names
next(reader)
# Print each column name
for row in reader:
specie = row[0]
variable = row[1]
variation = row[2]
converge = True if row[3] == "True" else False
iterations = row[4]
gradient = row[5]
init_value = row[6]
final_value = row[7]
if not converge and ignore_not_converge:
continue
results.add_single_result(
result.Result(
specie = specie,
variable = variable,
variation = int(variation),
converge = converge,
iterations = int(iterations),
gradient = gradient,
init_value = float(init_value),
final_value = float(final_value),
))
return results
if len(sys.argv) != 2:
print("Usage: python csv-to-result.py <csv_filepath>")
sys.exit()
filepath = sys.argv[1]
results = parse_csv(filepath, False)
parsed = results.get_results_metrics()
print("\n\n--------------\n")
print("\tLatex Data - stacionaty, percent")
print("\n--------------\n")
order_conv = ["HO+HF", "R-vdW (F--H2O)", "TS", "P-vdW (HO--HF)", "F + H2O"]
for i, conv in enumerate(order_conv):
data = parsed["convergence"][conv]
print("\t({}, {:.2f})".format(i+1, data["conv_percent"]))
print("\n--------------\n")
print("\tLatex Data - iterations, percent")
print("\n--------------\n")
for it, data in parsed["iterations"].items():
print("\t({}, {:.2f})".format(it, data["percent"]))