Skip to content

Commit f79a2da

Browse files
Extract calls to AddOns & S-DAC PrintOutputs from OutputsRich to Outputs
1 parent f112096 commit f79a2da

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

src/geophires_x/Outputs.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# noinspection PyPackageRequirements
88
import numpy as np
9+
import pandas as pd
910

1011
import geophires_x
1112
import geophires_x.Model as Model
@@ -759,6 +760,15 @@ def PrintOutputs(self, model: Model):
759760
f.write(NL)
760761
f.write(NL)
761762

763+
addon_df = pd.DataFrame()
764+
sdac_df = pd.DataFrame()
765+
addon_results = []
766+
sdac_results = []
767+
768+
if model.economics.DoAddOnCalculations.value:
769+
addon_df, addon_results = model.addoutputs.PrintOutputs(model)
770+
if model.economics.DoSDACGTCalculations.value:
771+
sdac_df, sdac_results = model.sdacgtoutputs.PrintOutputs(model)
762772

763773
except BaseException as ex:
764774
tb = sys.exc_info()[2]
@@ -769,7 +779,15 @@ def PrintOutputs(self, model: Model):
769779
model.logger.critical(msg)
770780
raise RuntimeError(msg) from ex
771781

772-
print_outputs_rich(self.output_file, self.text_output_file, self.html_output_file, model)
782+
print_outputs_rich(
783+
self.text_output_file,
784+
self.html_output_file,
785+
model,
786+
sdac_results,
787+
addon_results,
788+
sdac_df,
789+
addon_df
790+
)
773791

774792
model.logger.info(f'Complete {__class__!s}: {sys._getframe().f_code.co_name}')
775793

src/geophires_x/OutputsRich.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@
3030
VERTICAL_WELL_DEPTH_OUTPUT_NAME = 'Well depth'
3131

3232

33-
def print_outputs_rich(output_file: str, text_output_file: strParameter, html_output_file: strParameter, model: Model):
33+
def print_outputs_rich(
34+
text_output_file: strParameter,
35+
html_output_file: strParameter,
36+
model: Model,
37+
sdac_results: list,
38+
addon_results: list,
39+
sdac_df: pd.DataFrame,
40+
addon_df: pd.DataFrame):
3441
"""
3542
TODO Implementation of rich output in this method/file is duplicative of Outputs.PrintOutputs. This adds undue
3643
code complexity, maintenance overhead, inconsistency, and potential for bugs. Rich output should instead be
@@ -49,9 +56,7 @@ def print_outputs_rich(output_file: str, text_output_file: strParameter, html_ou
4956
CAPEX = []
5057
OPEX = []
5158
surface_equipment_results = []
52-
addon_results = []
53-
sdac_resa_results = []
54-
pumping_power_results = []
59+
# addon_results = []
5560

5661
simulation_metadata.append(OutputTableItem('GEOPHIRES Version', geophires_x.__version__))
5762
simulation_metadata.append(OutputTableItem('Simulation Date', datetime.datetime.now().strftime('%Y-%m-%d')))
@@ -878,26 +883,16 @@ def print_outputs_rich(output_file: str, text_output_file: strParameter, html_ou
878883

879884
pumping_power_profiles = pumping_power_profiles.reset_index()
880885

881-
addon_df = pd.DataFrame()
882-
sdac_df = pd.DataFrame()
883-
addon_results: list[OutputTableItem] = []
884-
sdac_results: list[OutputTableItem] = []
885-
886-
if model.economics.DoAddOnCalculations.value:
887-
addon_df, addon_results = model.addoutputs.PrintOutputs(model)
888-
if model.economics.DoSDACGTCalculations.value:
889-
sdac_df, sdac_results = model.sdacgtoutputs.PrintOutputs(model)
890-
891886
if text_output_file.Provided:
892-
Write_Text_Output(output_file, simulation_metadata, summary, economic_parameters,
887+
Write_Text_Output(text_output_file.value, simulation_metadata, summary, economic_parameters,
893888
engineering_parameters,
894889
resource_characteristics, reservoir_parameters, reservoir_stimulation_results, CAPEX,
895890
OPEX,
896891
surface_equipment_results, sdac_results, addon_results, hce, ahce, cashflow,
897892
pumping_power_profiles, sdac_df, addon_df)
898893

899894
# Get rid of any trailing spaces in that output file - they are confusing the testing code
900-
with open(output_file, 'r+') as fp:
895+
with open(text_output_file.value, 'r+') as fp:
901896
lines = fp.readlines()
902897
fp.seek(0)
903898
fp.truncate()

0 commit comments

Comments
 (0)