From 025fe02f71c92d2447ade828eca26e5131c7f1ac Mon Sep 17 00:00:00 2001 From: Peter Yefi Date: Tue, 17 Jan 2023 18:59:59 -0500 Subject: [PATCH] Read energy demand as an array of floats --- hub_api/city_info.py | 1 + hub_api/config.py | 0 utils/__init__.py | 1 + utils/hp_simulator.py | 16 +++++++++------- utils/misc.py | 17 +++++++++++++++++ 5 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 hub_api/config.py diff --git a/hub_api/city_info.py b/hub_api/city_info.py index 8971cd3..5cd9454 100644 --- a/hub_api/city_info.py +++ b/hub_api/city_info.py @@ -21,6 +21,7 @@ class CityInfo(Resource): pass @staticmethod + @role_required([UserRoles.Admin.value]) def get(): session = refresh_session(request) if session is None: diff --git a/hub_api/config.py b/hub_api/config.py new file mode 100644 index 0000000..e69de29 diff --git a/utils/__init__.py b/utils/__init__.py index 1de5e8f..311bf12 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -1,2 +1,3 @@ from .misc import validate_hp_model from .hp_simulator import HeatPumpSimulator +from .misc import expand_energy_demand diff --git a/utils/hp_simulator.py b/utils/hp_simulator.py index 42a0b6a..342c563 100644 --- a/utils/hp_simulator.py +++ b/utils/hp_simulator.py @@ -17,10 +17,10 @@ class HeatPumpSimulator: :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() @@ -32,10 +32,12 @@ class HeatPumpSimulator: """ hp_type = 'water' if 'water' in self._hp_type else 'air' del self._user_input['HeatPumpType'] + del self._user_input['EnergyDemand'] 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) + energy_demand_path = Path(Path(__file__).parent.parent / "data/energy_demand.txt") + return EnergySystemsExportFactory(city=self._city, + user_input=self._user_input, + hp_model=model, + output_path=None, + sim_type=self._user_input['SimType'], + demand_path=energy_demand_path).export(hp_type) diff --git a/utils/misc.py b/utils/misc.py index dc0b169..0f23955 100644 --- a/utils/misc.py +++ b/utils/misc.py @@ -3,6 +3,11 @@ Miscellaneous SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2022 Project Author Peter Yefi peteryefi@gmail.com """ +from typing import List +from pathlib import Path +import numpy as np + + hp_models = { 'air_source': ['012', '015', '018', '023', '030', '033', '037', '044', '047', '057', '070', '087', '097', '102', '120', '130', '140'], @@ -26,3 +31,15 @@ def validate_hp_model(hp_type: str, model: str) -> bool: if model in hp_models['water_to_water']: return True return False + + +def expand_energy_demand(hourly_energy_demand: List[float]): + """ + Replicates each value in the list 11 times and persist the values to a file + :param hourly_energy_demand: a list of hourly energy demand data + """ + energy_demand = Path(Path(__file__).parent.parent / "data/energy_demand.txt") + with open(energy_demand, 'w') as demand_file: + repeated_demand_values = np.repeat(hourly_energy_demand, 12).tolist() + for demand in repeated_demand_values: + demand_file.write("%.6f\n" % demand) \ No newline at end of file