From a06ad62ec76969b1965b5767f03e8fc11b0a8c3c Mon Sep 17 00:00:00 2001 From: Peter Yefi Date: Fri, 12 Nov 2021 10:14:54 +0000 Subject: [PATCH] Added parameter for caller to specify output file path --- exports/energy_systems/heat_pump_export.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/exports/energy_systems/heat_pump_export.py b/exports/energy_systems/heat_pump_export.py index 59862cd1..754b578a 100644 --- a/exports/energy_systems/heat_pump_export.py +++ b/exports/energy_systems/heat_pump_export.py @@ -16,7 +16,7 @@ class HeatPumpExport: of some defined function """ - def __init__(self, base_path, city): + def __init__(self, base_path, city, output_path): self._template_path = (base_path / 'heat_pumps/template.txt') self._constants_path = (base_path / 'heat_pumps/constants.yaml') # needed to compute max demand. @@ -24,6 +24,7 @@ class HeatPumpExport: self._city = city self._input_data = None self._base_path = base_path + self._output_path = output_path def run_insel(self, user_input: Dict, hp_model: str, data_type: str) -> None: """ @@ -49,8 +50,8 @@ class HeatPumpExport: try: # run insel insel_template_handler = open(self._template_path, "r") - insel_template_handler = insel_template_handler.read() - insel_template = Template(insel_template_handler).substitute(self._input_data) + insel_template_content = insel_template_handler.read() + insel_template = Template(insel_template_content).substitute(self._input_data) # create the insel file and write the template with substituted values into it insel_file = (self._base_path / 'heat_pumps/dompark_heat_pump.insel') insel_file_handler = open(insel_file, "w") @@ -211,4 +212,5 @@ class HeatPumpExport: df = df.append(df.agg(['sum'])) s = pd.Series(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec", "Total"]) df = df.set_index([s]) - print(df) + df.to_csv(self._output_path) +