Added parameter for caller to specify output file path

This commit is contained in:
Peter Yefi 2021-11-12 10:14:54 +00:00
parent 216dbf6d7c
commit a06ad62ec7

View File

@ -16,7 +16,7 @@ class HeatPumpExport:
of some defined function 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._template_path = (base_path / 'heat_pumps/template.txt')
self._constants_path = (base_path / 'heat_pumps/constants.yaml') self._constants_path = (base_path / 'heat_pumps/constants.yaml')
# needed to compute max demand. # needed to compute max demand.
@ -24,6 +24,7 @@ class HeatPumpExport:
self._city = city self._city = city
self._input_data = None self._input_data = None
self._base_path = base_path self._base_path = base_path
self._output_path = output_path
def run_insel(self, user_input: Dict, hp_model: str, data_type: str) -> None: def run_insel(self, user_input: Dict, hp_model: str, data_type: str) -> None:
""" """
@ -49,8 +50,8 @@ class HeatPumpExport:
try: try:
# run insel # run insel
insel_template_handler = open(self._template_path, "r") insel_template_handler = open(self._template_path, "r")
insel_template_handler = insel_template_handler.read() insel_template_content = insel_template_handler.read()
insel_template = Template(insel_template_handler).substitute(self._input_data) insel_template = Template(insel_template_content).substitute(self._input_data)
# create the insel file and write the template with substituted values into it # 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 = (self._base_path / 'heat_pumps/dompark_heat_pump.insel')
insel_file_handler = open(insel_file, "w") insel_file_handler = open(insel_file, "w")
@ -211,4 +212,5 @@ class HeatPumpExport:
df = df.append(df.agg(['sum'])) df = df.append(df.agg(['sum']))
s = pd.Series(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec", "Total"]) s = pd.Series(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec", "Total"])
df = df.set_index([s]) df = df.set_index([s])
print(df) df.to_csv(self._output_path)