Skip to content

Commit 2650b1b

Browse files
Reformat final concs into a dictionary
1 parent b02e317 commit 2650b1b

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

backend/src/acidwatch_api/models/phpitz.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,48 @@ async def run(self) -> RunResult:
6767
res.raise_for_status()
6868

6969
result = res.text.replace("\\n", "\n").strip("'")
70-
return ({}, TextResult(data=result))
70+
concentrations_dict = self.parse_phpitz_simple(
71+
result[result.find("FINISH") : result.find("\n \n \n")]
72+
)
73+
74+
return (concentrations_dict, TextResult(data=result))
75+
76+
@staticmethod
77+
def parse_phpitz_simple(text: str) -> dict:
78+
"""
79+
Parse PHPitz table into a simple dictionary format.
80+
81+
Returns:
82+
Dict with component names as keys and their data as nested dicts
83+
"""
84+
result = {}
85+
86+
lines = text.split("\n")
87+
88+
for line in lines:
89+
line = line.strip()
90+
# Skip empty lines, separators, and headers
91+
if (
92+
line
93+
and not line.startswith("-")
94+
and not line.startswith("Component")
95+
and line != "FINISH"
96+
):
97+
98+
parts = line.split()
99+
if len(parts) >= 5:
100+
component = parts[0]
101+
result[component] = {
102+
"start_moles": float(
103+
parts[1].replace("E+", "e+").replace("E-", "e-")
104+
),
105+
"end_moles": float(
106+
parts[2].replace("E+", "e+").replace("E-", "e-")
107+
),
108+
"end_ppm": float(
109+
parts[3].replace("E+", "e+").replace("E-", "e-")
110+
),
111+
"fugacity_coef": float(parts[4]),
112+
}
113+
114+
return result

0 commit comments

Comments
 (0)