From b96617bb216434138a9cc71870e0025db5a57844 Mon Sep 17 00:00:00 2001 From: Guille Date: Thu, 3 Aug 2023 12:38:19 -0400 Subject: [PATCH] correct retrofit results to apply costs and co2 to all scenariosa --- hub_api/persistence/retrofit_results.py | 115 ++++++++++++------------ 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/hub_api/persistence/retrofit_results.py b/hub_api/persistence/retrofit_results.py index f357e8e..44d7439 100644 --- a/hub_api/persistence/retrofit_results.py +++ b/hub_api/persistence/retrofit_results.py @@ -38,65 +38,64 @@ class RetrofitResults(Resource, Config): 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 - mockup_building = Building(building_info, results_dictionary, archetype) - life_cycle = Cost(mockup_building, retrofit_scenario=scenario).life_cycle + for scenario in 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 + mockup_building = Building(building_info, results_dictionary, archetype) + life_cycle = Cost(mockup_building, retrofit_scenario=scenario).life_cycle - operational_co2 = Co2Emission(mockup_building).operational_co2 - 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() + operational_co2 = Co2Emission(mockup_building).operational_co2 + 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(operational_co2) - building_results['operational_co2'] = operational_co2 + building_results['operational_co2'] = operational_co2 return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token)