Read energy demand as an array of floats

This commit is contained in:
Peter Yefi 2023-01-17 18:59:59 -05:00
parent ab4492aebb
commit 025fe02f71
5 changed files with 28 additions and 7 deletions

View File

@ -21,6 +21,7 @@ class CityInfo(Resource):
pass
@staticmethod
@role_required([UserRoles.Admin.value])
def get():
session = refresh_session(request)
if session is None:

0
hub_api/config.py Normal file
View File

View File

@ -1,2 +1,3 @@
from .misc import validate_hp_model
from .hp_simulator import HeatPumpSimulator
from .misc import expand_energy_demand

View File

@ -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)

View File

@ -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)