File tree Expand file tree Collapse file tree
backend/src/acidwatch_api/models Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments