Skip to content

Commit d75c816

Browse files
Return finaldicts as part of phpitz run
1 parent be9c85e commit d75c816

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

backend/src/acidwatch_api/models/phpitz.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,37 @@ 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+
parsed_data = self.parse_phpitz_simple(
71+
result[result.find("FINISH") : result.find("\n \n \n")]
72+
)
73+
74+
final_concentrations: dict[str, float] = {
75+
component: data["end_ppm"] for component, data in parsed_data.items()
76+
}
77+
78+
return (final_concentrations, TextResult(data=result))
79+
80+
@staticmethod
81+
def parse_phpitz_simple(text: str) -> dict[str, dict[str, float]]:
82+
result = {}
83+
84+
lines = text.split("\n")
85+
86+
for line in lines:
87+
line = line.strip()
88+
if (
89+
line
90+
and not line.startswith("-")
91+
and not line.startswith("Component")
92+
and line != "FINISH"
93+
):
94+
parts = line.split()
95+
if len(parts) >= 5:
96+
component = parts[0]
97+
result[component] = {
98+
"start_moles": float(parts[1]),
99+
"end_moles": float(parts[2]),
100+
"end_ppm": float(parts[3]),
101+
"fugacity_coef": float(parts[4]),
102+
}
103+
return result

0 commit comments

Comments
 (0)