From f5b48fee4e5dac8639c82177002944dba35837e4 Mon Sep 17 00:00:00 2001 From: Guille Date: Wed, 8 May 2024 18:10:51 +0200 Subject: [PATCH] complete the meb results --- .../workflow/insel_montly_energy_balance.py | 53 ++++++++++++++----- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/hub_api/workflow/insel_montly_energy_balance.py b/hub_api/workflow/insel_montly_energy_balance.py index 07f0f7a..51bf6e8 100644 --- a/hub_api/workflow/insel_montly_energy_balance.py +++ b/hub_api/workflow/insel_montly_energy_balance.py @@ -23,7 +23,7 @@ from hub_api.helpers.session_helper import refresh_session class InselMonthlyEnergyBalance(Resource, Config): def __init__(self): super().__init__() - self._extensions = ['.geojson', '.citygml'] + self._extensions = ['.geojson', '.gml'] self._tmp_path = (Path(__file__).parent / 'tmp').resolve() self._city = None @@ -36,7 +36,7 @@ class InselMonthlyEnergyBalance(Resource, Config): height_field = request.form.get('height_field') year_of_construction_field = request.form.get('year_of_construction_field') function_field = request.form.get('function_field') - function_dictionary = self._dictionaries[request.form.get('function_dictionary_name')] + function_dictionary = self._dictionaries[request.form.get('function_to_hub')] return GeometryFactory('geojson', path=file_path, height_field=height_field, @@ -47,17 +47,21 @@ class InselMonthlyEnergyBalance(Resource, Config): return None def _citygml(self, file_path): - try: - year_of_construction_field = request.form.get('year_of_construction_field') - function_field = request.form.get('function_field') - function_dictionary = self._dictionaries[request.form.get('function_dictionary_name')] - return GeometryFactory('citygml', - path=file_path, - year_of_construction_field=year_of_construction_field, - function_field=function_field, - function_to_hub=function_dictionary).city - except KeyError: - return None + # try: + year_of_construction_field = request.form.get('year_of_construction_field') + if year_of_construction_field is '': + year_of_construction_field = None + function_field = request.form.get('function_field') + if function_field is '': + function_field = None + function_dictionary = self._dictionaries[request.form.get('function_to_hub')] + return GeometryFactory('citygml', + path=file_path, + year_of_construction_field=year_of_construction_field, + function_field=function_field, + function_to_hub=function_dictionary).city + # except KeyError: + # return None def post(self): """ @@ -67,6 +71,7 @@ class InselMonthlyEnergyBalance(Resource, Config): token = request.headers.get('token', None) application_uuid = request.headers.get('application-uuid', None) _session = refresh_session(session_id, token, application_uuid) + _session = {'token': token} if _session is None: return Response(json.dumps({'error': 'unauthorized'}), status=403) else: @@ -114,7 +119,27 @@ class InselMonthlyEnergyBalance(Resource, Config): 'monthly_lighting_peak_load': building.lighting_peak_load[cte.MONTH], 'yearly_lighting_peak_load': building.lighting_peak_load[cte.YEAR], 'monthly_appliances_peak_load': building.appliances_peak_load[cte.MONTH], - 'yearly_appliances_peak_load': building.appliances_peak_load[cte.YEAR] + 'yearly_appliances_peak_load': building.appliances_peak_load[cte.YEAR], + 'monthly_cooling_peak_load': building.cooling_peak_load[cte.MONTH], + 'yearly_cooling_peak_load': building.cooling_peak_load[cte.YEAR], + 'monthly_heating_peak_load': building.heating_peak_load[cte.MONTH], + 'yearly_heating_peak_load': building.heating_peak_load[cte.YEAR], + 'monthly_cooling_consumption': building.cooling_consumption[cte.MONTH], + 'yearly_cooling_consumption': building.cooling_consumption[cte.YEAR], + 'monthly_heating_consumption': building.heating_consumption[cte.MONTH], + 'yearly_heating_consumption': building.heating_consumption[cte.YEAR], + 'monthly_lighting_electrical_demand': building.lighting_electrical_demand[cte.MONTH], + 'yearly_lighting_electrical_demand': building.lighting_electrical_demand[cte.YEAR], + 'monthly_appliances_electrical_demand': building.appliances_electrical_demand[cte.MONTH], + 'yearly_appliances_electrical_demand': building.appliances_electrical_demand[cte.YEAR], + 'monthly_onsite_electrical_production': building.onsite_electrical_production[cte.MONTH], + 'yearly_onsite_electrical_production': building.onsite_electrical_production[cte.YEAR], + 'monthly_domestic_hot_water_consumption': building.domestic_hot_water_consumption[cte.MONTH], + 'yearly_domestic_hot_water_consumption': building.domestic_hot_water_consumption[cte.YEAR], + 'monthly_domestic_hot_water_demand': building.domestic_hot_water_heat_demand[cte.MONTH], + 'yearly_domestic_hot_water_demand': building.domestic_hot_water_heat_demand[cte.YEAR], + 'monthly_distribution_systems_electrical_consumption': building.domestic_hot_water_consumption[cte.MONTH], + 'yearly_distribution_systems_electrical_consumption': building.domestic_hot_water_consumption[cte.MONTH] } shutil.rmtree(tmp_path) return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=response_token)