api_v1.4/utils/hp_simulator.py

42 lines
1.4 KiB
Python

"""
HeatPumpSimulator: Module for running simulations
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Project Author Peter Yefi peteryefi@gmail.com
"""
from pathlib import Path
from typing import Dict
from exports.energy_systems_factory import EnergySystemsExportFactory
from imports.energy_systems_factory import EnergySystemsFactory
class HeatPumpSimulator:
def __init__(self, city, user_input: Dict):
"""
:param user_input: the user parameters for running simulation
"""
self._user_input = user_input
self._hp_type = user_input['HeatPumpType'].replace(" ", "_").lower()
# file to have results after simulation is run
self._output_path = Path(Path(__file__).parent.parent / "data/dompark_{}.csv".format(self._hp_type))
self._city = city
EnergySystemsFactory(user_input['HeatPumpType'].lower(), self._city).enrich()
def run_hp_simulation(self) -> str:
"""
Runs heat pump simulation and dumps output
in self._output_path
:return: None
"""
hp_type = 'water' if 'water' in self._hp_type else 'air'
del self._user_input['HeatPumpType']
model = self._user_input.pop('HeatPumpModel')
EnergySystemsExportFactory(self._city,
self._user_input,
model,
self._output_path,
self._user_input['SimType']).export(hp_type)
return str(self._output_path)