From d9a464e6d90a052d3456f20a642b8fc335d2e411 Mon Sep 17 00:00:00 2001 From: Guille Date: Tue, 1 Aug 2023 16:40:49 -0400 Subject: [PATCH] cost completed --- hub_api/mockup/building.py | 60 ++++++++++++++++++--- hub_api/persistence/retrofit_results.py | 72 ++++++++++++++++++------- 2 files changed, 104 insertions(+), 28 deletions(-) diff --git a/hub_api/mockup/building.py b/hub_api/mockup/building.py index 8925a69..014b460 100644 --- a/hub_api/mockup/building.py +++ b/hub_api/mockup/building.py @@ -5,6 +5,7 @@ Copyright © 2023 Concordia CERC group Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ +import hub.helpers.constants as cte from hub_api.mockup.properties import * @@ -21,14 +22,45 @@ class Building: self._windows_area = building_info.windows_area self._roof_area = building_info.roof_area self._total_pv_area = building_info.total_pv_area - self._heating_consumption = heating_consumption - self._cooling_consumption = cooling_consumption - self._domestic_hot_water_consumption = domestic_hot_water_consumption - self._lighting_electrical_demand = lighting_electrical_demand - self._appliances_electrical_demand = appliances_electrical_demand - self._heating_peak_load = heating_peak_load - self._cooling_peak_load =cooling_peak_load - self._onsite_electrical_production = onsite_electrical_production + self._energy_systems_archetype_name = building_info.system_name + self._heating_consumption = { + cte.YEAR: results['yearly_heating_consumption'], + cte.MONTH: results['monthly_heating_consumption'] + } + self._cooling_consumption = { + cte.YEAR: results['yearly_cooling_consumption'], + cte.MONTH: results['monthly_cooling_consumption'] + } + self._domestic_hot_water_consumption = { + cte.YEAR: results['yearly_domestic_hot_water_consumption'], + cte.MONTH: results['monthly_domestic_hot_water_consumption'] + } + self._lighting_electrical_demand = { + cte.YEAR: {'insel meb': results['yearly_lighting_electrical_demand'][0]} + } + self._appliances_electrical_demand = { + cte.YEAR: {'insel meb': results['yearly_appliances_electrical_demand'][0]} + } + self._heating_peak_load = { + cte.YEAR: results['yearly_heating_peak_load'], + cte.MONTH: results['monthly_heating_peak_load'] + } + self._cooling_peak_load = { + cte.YEAR: results['yearly_cooling_peak_load'], + cte.MONTH: results['monthly_cooling_peak_load'] + } + self._lighting_peak_load = { + cte.YEAR: results['yearly_lighting_peak_load'], + cte.MONTH: results['monthly_lighting_peak_load'] + } + self._appliances_peak_load = { + cte.YEAR: results['yearly_appliances_peak_load'], + cte.MONTH: results['monthly_appliances_peak_load'] + } + self._onsite_electrical_production = { + cte.YEAR: results['yearly_on_site_electrical_production'], + cte.MONTH: results['monthly_on_site_electrical_production'] + } self._catalog_archetype = catalog_archetype @property @@ -93,10 +125,22 @@ class Building: def cooling_peak_load(self): return self._cooling_peak_load + @property + def lighting_peak_load(self): + return self._lighting_peak_load + + @property + def appliances_peak_load(self): + return self._appliances_peak_load + @property def onsite_electrical_production(self): return self._onsite_electrical_production + @property + def energy_systems_archetype_name(self): + return self._energy_systems_archetype_name + @property def energy_systems(self): _energy_systems = [] diff --git a/hub_api/persistence/retrofit_results.py b/hub_api/persistence/retrofit_results.py index 89b9852..2aeb6ca 100644 --- a/hub_api/persistence/retrofit_results.py +++ b/hub_api/persistence/retrofit_results.py @@ -30,36 +30,68 @@ class RetrofitResults(Resource, Config): if 'scenarios' not in payload: return Response(json.dumps({'error': 'Bad request'}), status=400, headers=token) - # retrieve the buildings info - buildings = [] - buildings_info = [] - mockups = {} - scenario_name = None - - for scenario in payload['scenarios']: - scenario_name = next(iter(scenario)) - for name in scenario[scenario_name]: - if name not in buildings: - buildings.append(name) - for building in buildings: - building_info = self.database.building(building, user_id, application_id, scenario_name) - archetype = self.energy_systems_catalog.get_entry(building_info.system_name) - buildings_info.append(building_info) - mockups[building_info.name] = Building(building_info, archetype) - results = self.database.results(user_id, application_id, payload) if results == {}: # no data found for the given parameters return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token) + # deserialize the response to return pure json scenario = next(iter(results)) + for building_results in results[scenario]: values = [] + building_info = self.database.building(building_results['building'], user_id, application_id, scenario) + results_dictionary = {} + archetype = self.energy_systems_catalog.get_entry(building_info.system_name) for value in building_results['insel meb']: key = next(iter(value)) values.append({key: json.loads(str(value[key]))}) + results_dictionary[key] = json.loads(str(value[key])) building_results['insel meb'] = values - building_results['costs'] = Cost(mockups[building_results['name']], scenario_name=scenario) - - + mockup_building = Building(building_info, results_dictionary, archetype) + life_cycle = Cost(mockup_building, retrofit_scenario=scenario).life_cycle + global_capital_costs = life_cycle[f'Scenario {scenario}']['global_capital_costs'] + global_operational_costs = life_cycle[f'Scenario {scenario}']['global_operational_costs'] + global_capital_incomes = life_cycle[f'Scenario {scenario}']['global_capital_incomes'] + global_maintenance_costs = life_cycle[f'Scenario {scenario}']['global_maintenance_costs'] + building_results['costs'] = { + 'total_capital_costs_skin': life_cycle[f'Scenario {scenario}']['total_capital_costs_skin'], + 'total_capital_costs_systems': life_cycle[f'Scenario {scenario}']['total_capital_costs_systems'], + 'end_of_life_costs': life_cycle[f'Scenario {scenario}']['end_of_life_costs'], + 'total_operational_costs': life_cycle[f'Scenario {scenario}']['total_operational_costs'], + 'total_maintenance_costs': life_cycle[f'Scenario {scenario}']['total_maintenance_costs'], + 'operational_incomes': life_cycle[f'Scenario {scenario}']['operational_incomes'], + 'capital_incomes': life_cycle[f'Scenario {scenario}']['capital_incomes'], + 'global_capital_costs': { + 'B2010_opaque_walls': global_capital_costs['B2010_opaque_walls'].tolist(), + 'B2020_transparent': global_capital_costs['B2020_transparent'].tolist(), + 'B3010_opaque_roof': global_capital_costs['B3010_opaque_roof'].tolist(), + 'B10_superstructure': global_capital_costs['B10_superstructure'].tolist(), + 'D3020_heat_generating_systems': global_capital_costs['D3020_heat_generating_systems'].tolist(), + 'D3030_cooling_generation_systems': global_capital_costs['D3030_cooling_generation_systems'].tolist(), + 'D3080_other_hvac_ahu': global_capital_costs['D3080_other_hvac_ahu'].tolist(), + 'D5020_lighting_and_branch_wiring': global_capital_costs['D5020_lighting_and_branch_wiring'].tolist(), + 'D301010_photovoltaic_system': global_capital_costs['D301010_photovoltaic_system'].tolist(), + }, + 'global_end_of_life_costs': life_cycle[f'Scenario {scenario}']['global_end_of_life_costs']['End_of_life_costs'].tolist(), + 'global_operational_costs': { + 'fixed_costs_electricity_peak': global_operational_costs['Fixed_costs_electricity_peak'].tolist(), + 'fixed_costs_electricity_monthly': global_operational_costs['Fixed_costs_electricity_monthly'].tolist(), + 'variable_costs_electricity': global_operational_costs['Variable_costs_electricity'].tolist(), + 'fixed_costs_gas': global_operational_costs['Fixed_costs_gas'].tolist(), + 'variable_costs_gas': global_operational_costs['Variable_costs_gas'].tolist() + }, + 'global_maintenance_costs': { + 'heating_maintenance': global_maintenance_costs['Heating_maintenance'].tolist(), + 'cooling_maintenance': global_maintenance_costs['Cooling_maintenance'].tolist(), + 'pv_maintenance': global_maintenance_costs['PV_maintenance'].tolist(), + }, + 'global_operational_incomes': life_cycle[f'Scenario {scenario}']['global_operational_incomes']['Incomes electricity'].tolist(), + 'global_capital_incomes': { + 'subsidies_construction': global_capital_incomes['Subsidies construction'].tolist(), + 'subsidies_hvac': global_capital_incomes['Subsidies HVAC'].tolist(), + 'subsidies_pv': global_capital_incomes['Subsidies PV'].tolist() + } + } + print(results) return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token)