Skip to content

Commit e5e9bb2

Browse files
Search all lines for AGS/CLGS-style output, since these are currently recategorized into non-AGS/CLGS-style categories by the client (TODO to eventually address this backwards-compatibly)
1 parent 555ebb8 commit e5e9bb2

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/geophires_x_client/geophires_x_result.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ def __init__(self, output_file_path, logger_name=None):
383383

384384
with open(self.output_file_path, encoding='utf-8') as f:
385385
self._lines = list(f.readlines())
386+
387+
self.is_ags_clgs_style_output = '***AGS/CLGS STYLE OUTPUT***' in [_l.strip() for _l in self._lines]
388+
386389
self._lines_by_category = self._get_lines_by_category()
387390

388391
# TODO generic-er result value map
@@ -394,15 +397,16 @@ def __init__(self, output_file_path, logger_name=None):
394397

395398
self.result[category] = {}
396399
category_lines = self._lines_by_category.get(category, [])
400+
search_lines = category_lines if not self.is_ags_clgs_style_output else self._lines
397401

398402
for field in fields:
399403
if isinstance(field, _EqualSignDelimitedField):
400404
self.result[category][field.field_name] = self._get_equal_sign_delimited_field(
401-
field.field_name, search_lines=category_lines
405+
field.field_name, search_lines=search_lines
402406
)
403407
elif isinstance(field, _UnlabeledStringField):
404408
self.result[category][field.field_name] = self._get_unlabeled_string_field(
405-
field.field_name, field.marker_prefixes, search_lines=category_lines
409+
field.field_name, field.marker_prefixes, search_lines=search_lines
406410
)
407411
else:
408412
is_string_field = isinstance(field, _StringValueField)
@@ -412,7 +416,7 @@ def __init__(self, output_file_path, logger_name=None):
412416
field_name,
413417
is_string_value_field=is_string_field,
414418
min_indentation_spaces=indent,
415-
search_lines=category_lines,
419+
search_lines=search_lines,
416420
)
417421

418422
try:
@@ -465,6 +469,12 @@ def _get_lines_by_category(self) -> dict[str, list[str]]:
465469
for line in self._lines:
466470

467471
def get_header_content(h_: str) -> str:
472+
"""
473+
TODO adjust this to also work with AGS/CLGS-style headers like '### Cost Results ###'
474+
For now, AGS-style results are parsed from all lines according to the categories defined in
475+
_RESULT_FIELDS_BY_CATEGORY.
476+
"""
477+
468478
if h_ == 'Simulation Metadata':
469479
return h_
470480
return f'***{h_}***'

tests/geophires_x_client_tests/test_geophires_x_result.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ def test_multicategory_fields_only_in_case_report_category(self) -> None:
5757
self.assertIsNone(r.result['RESERVOIR SIMULATION RESULTS']['Average Net Electricity Production'])
5858
self.assertIsNotNone(r.result['SUMMARY OF RESULTS']['Average Net Electricity Production'])
5959
self.assertIsNotNone(r.result['SURFACE EQUIPMENT SIMULATION RESULTS']['Average Net Electricity Generation'])
60+
61+
def test_ags_clgs_style_output(self) -> None:
62+
r: GeophiresXResult = GeophiresXResult(
63+
self._get_test_file_path('../examples/Beckers_et_al_2023_Tabulated_Database_Uloop_sCO2_elec.out')
64+
)
65+
self.assertIsNotNone(r.result['SUMMARY OF RESULTS']['LCOE'])

0 commit comments

Comments
 (0)