diff --git a/hub_api/persistence/mock.py b/hub_api/persistence/mock.py new file mode 100644 index 0000000..6fdad0c --- /dev/null +++ b/hub_api/persistence/mock.py @@ -0,0 +1 @@ +dic = {'result': 'succeed', 'results': {'current status': [{'insel meb': {'yearly_cooling_demand': [29471570625.600002], 'yearly_heating_demand': [655211046894.48], 'monthly_cooling_demand': [425377029.6, 486369251.99999994, 902650892.4, 1457429479.2, 2773847023.2000003, 5042227140.0, 6902455500.0, 6216696828.0, 2849347706.4, 1262733616.8, 707614070.4, 444822087.59999996], 'monthly_heating_demand': [131806251720.0, 115451296920.0, 93186984240.0, 47775972599.99999, 19772268768.0, 2407050000.0, 102667236.48, 349268994.0, 13631166216.0, 43532683559.99999, 69397783560.0, 117797653080.0], 'yearly_cooling_peak_load': [46443.80211823255], 'yearly_heating_peak_load': [197084.67069419287], 'monthly_cooling_peak_load': [0, 0, 0, 6743032.330678142, 115408068.04729427, 108671931.65912153, 167197687.62563717, 157400345.50661197, 69966252.84567448, 0, 0, 0], 'monthly_heating_peak_load': [699061607.3338553, 709504814.4990944, 582506723.994858, 415883135.1493693, 293813621.6155675, 227152374.7878974, 191944804.82402125, 207328915.7334916, 299754927.8650942, 381825201.69319767, 475052812.6891298, 603446335.5589818], 'yearly_lighting_peak_load': [10808.647694872592], 'monthly_lighting_peak_load': [10808.647694872592, 10808.647694872592, 10808.647694872592, 10808.647694872592, 10808.647694872592, 10808.647694872592, 10808.647694872592, 10808.647694872592, 10808.647694872592, 10808.647694872592, 10808.647694872592, 10808.647694872592], 'yearly_cooling_consumption': [9124325271.083591], 'yearly_heating_consumption': [655211046894.48], 'monthly_cooling_consumption': [131695674.79876162, 150578715.78947365, 279458480.61919504, 451216557.0278638, 858776168.1733747, 1561061034.0557275, 2136983126.9349844, 1924673940.5572755, 882150992.6934985, 390939200.247678, 219075563.59133127, 137715816.59442723], 'monthly_heating_consumption': [131806251720.0, 115451296920.0, 93186984240.0, 47775972599.99999, 19772268768.0, 2407050000.0, 102667236.48, 349268994.0, 13631166216.0, 43532683559.99999, 69397783560.0, 117797653080.0], 'yearly_appliances_peak_load': [2001.6014249764057], 'monthly_appliances_peak_load': [2001.6014249764057, 2001.6014249764057, 2001.6014249764057, 2001.6014249764057, 2001.6014249764057, 2001.6014249764057, 2001.6014249764057, 2001.6014249764057, 2001.6014249764057, 2001.6014249764057, 2001.6014249764057, 2001.6014249764057], 'yearly_lighting_electrical_demand': [13403.22354199826], 'monthly_lighting_electrical_demand': [1139.7452114053153, 1028.1559319628807, 1139.7452114053153, 1099.2127825495431, 1139.7452114053153, 1102.548784924504, 1136.4092090303545, 1139.7452114053153, 1099.2127825495431, 1139.7452114053153, 1102.548784924504, 1136.4092090303548], 'yearly_appliances_electrical_demand': [2482.0784337033815], 'monthly_appliances_electrical_demand': [211.06392803802137, 190.39924665979274, 211.06392803802137, 203.55792269435983, 211.06392803802137, 204.17570091194514, 210.4461498204361, 211.06392803802137, 203.55792269435983, 211.06392803802137, 204.17570091194517, 210.44614982043603], 'yearly_on_site_electrical_production': [0], 'monthly_on_site_electrical_production': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'yearly_domestic_hot_water_consumption': [1080.7064020023479], 'yearly_domestic_hot_water_heat_demand': [1080.7064020023479], 'monthly_domestic_hot_water_consumption': [89.25919904127754, 80.91921260501591, 91.53728950418397, 89.84084563513915, 92.56902309785954, 89.55049668894523, 92.14869636040272, 91.94380503141703, 90.20168038663576, 92.65610519039802, 89.27705741354866, 90.8029910475242], 'monthly_domestic_hot_water_heat_demand': [89.25919904127754, 80.91921260501591, 91.53728950418397, 89.84084563513915, 92.56902309785954, 89.55049668894523, 92.14869636040272, 91.94380503141703, 90.20168038663576, 92.65610519039802, 89.27705741354866, 90.8029910475242], 'yearly_distribution_systems_electrical_consumption': [0.0], 'monthly_distribution_systems_electrical_consumption': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}, 'building': '01002777', 'total_heating_area': 889.2770677804947, 'costs': {'total_capital_costs_skin': 0.0, 'total_capital_costs_systems': 383860.97682068415, 'end_of_life_costs': 7558.875546789136, 'total_operational_costs': 662351.5819001956, 'total_maintenance_costs': 357814.2053855526, 'operational_incomes': 0.0, 'capital_incomes': 0.0, 'global_capital_costs': {'B2010_opaque_walls': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 'B2020_transparent': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 'B3010_opaque_roof': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 'B10_superstructure': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 'D3020_heat_generating_systems': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 327247.82587977976, 0.0, 0.0, 0.0, 0.0, 0.0], 'D3030_cooling_generation_systems': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 52097.669571901366, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 93824.95966756108], 'D3080_other_hvac_ahu': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3983.0636499597713, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 7173.272612415725], 'D5020_lighting_and_branch_wiring': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 270843.66336580116, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 'D301010_photovoltaic_system': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}, 'global_end_of_life_costs': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 18897.796187287942], 'global_operational_costs': {'fixed_costs_electricity_peak': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 'fixed_costs_electricity_monthly': [0.0, 1718.5501654125007, 1804.4776736831257, 1894.7015573672822, 1989.4366352356465, 2088.908466997429, 2193.3538903473004, 2303.0215848646653, 2418.172664107899, 2539.081297313294, 2666.0353621789586, 2799.337130287907, 2939.303986802302, 3086.2691861424173, 3240.5826454495386, 3402.6117777220156, 3572.7423666081163, 3751.379484938522, 3938.9484591854484, 4135.895882144721, 4342.6906762519575, 4559.825210064556, 4787.816470567784, 5027.207294096173, 5278.567658800982, 5542.496041741031, 5819.620843828083, 6110.601886019487, 6416.131980320462, 6736.938579336486, 7073.785508303311, 7427.474783718476], 'variable_costs_electricity': [0.0, 14532.336637253136, 15258.953469115793, 16021.901142571583, 16822.996199700163, 17664.146009685173, 18547.353310169434, 19474.720975677905, 20448.4570244618, 21470.879875684892, 22544.423869469134, 23671.645062942593, 24855.227316089724, 26097.988681894214, 27402.888115988924, 28773.032521788373, 30211.68414787779, 31722.268355271684, 33308.38177303527, 34973.800861687036, 36722.49090477138, 38558.61545000996, 40486.54622251046, 42510.87353363598, 44636.41721031778, 46868.23807083367, 49211.64997437536, 51672.232473094125, 54255.844096748835, 56968.63630158629, 59817.06811666561, 62807.92152249888], 'fixed_costs_gas': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 'variable_costs_gas': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}, 'global_maintenance_costs': {'heating_maintenance': [0.0, 8198.722300878424, 8526.671192913562, 8867.738040630104, 9222.44756225531, 9591.34546474552, 9974.999283335343, 10373.999254668755, 10788.959224855505, 11220.517593849727, 11669.338297603716, 12136.111829507865, 12621.556302688181, 13126.41855479571, 13651.475296987537, 14197.534308867038, 14765.435681221721, 15356.05310847059, 15970.295232809416, 16609.107042121792, 17273.471323806665, 17964.41017675893, 18682.98658382929, 19430.30604718246, 20207.51828906976, 21015.81902063255, 21856.451781457854, 22730.70985271617, 23639.93824682482, 24585.535776697812, 25568.957207765725, 26591.715496076355], 'cooling_maintenance': [0.0, 1932.0621681184741, 2009.3446548432132, 2089.718441036942, 2173.3071786784194, 2260.239465825556, 2350.649044458579, 2444.675006236922, 2542.462006486399, 2644.160486745855, 2749.926906215689, 2859.923982464317, 2974.3209417628896, 3093.2937794334052, 3217.0255306107415, 3345.706551835171, 3479.534813908578, 3618.7162064649215, 3763.464854723519, 3914.0034489124596, 4070.563586868958, 4233.386130343716, 4402.721575557465, 4578.830438579764, 4761.983656122955, 4952.463002367873, 5150.561522462588, 5356.583983361092, 5570.847342695536, 5793.681236403358, 6025.428485859492, 6266.445625293872], 'pv_maintenance': [0.0, 115.60601881146431, 120.2302595639229, 125.03946994647981, 130.041048744339, 135.24269069411255, 140.6523983218771, 146.27849425475216, 152.12963402494225, 158.21481938593996, 164.54341216137755, 171.12514864783267, 177.970154593746, 185.08896077749583, 192.49251920859567, 200.1922199769395, 208.19990877601708, 216.52790512705778, 225.1890213321401, 234.1965821854257, 243.56444547284275, 253.30702329175648, 263.4393042234267, 273.9768763923638, 284.9359514480584, 296.3333895059807, 308.18672508621995, 320.51419408966876, 333.33476185325554, 346.66815232738577, 360.5348784204812, 374.95627355730045]}, 'global_operational_incomes': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 'global_capital_incomes': {'subsidies_construction': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 'subsidies_hvac': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 'subsidies_pv': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}}, 'operational_co2': {'Heating': {'year': [205.63203054420524], 'month': [41.36619385168761, 36.2333399706017, 29.245887840850273, 14.994054669143091, 6.20534680314143, 0.75543076000845, 0.03222117882140116, 0.10961489856247554, 4.27801759595953, 13.662336979679754, 21.779863475055656, 36.96972252069385]}, 'Domestic Hot Water': {'year': [3.3916987956653626e-07], 'month': [2.801318816372647e-08, 2.5395759239522452e-08, 2.872814614538926e-08, 2.819573265946075e-08, 2.9051946354274234e-08, 2.810460928226006e-08, 2.8920030628913784e-08, 2.8855727347978694e-08, 2.830897736586924e-08, 2.9079276277354133e-08, 2.8018792851513302e-08, 2.8497693250273857e-08]}, 'Cooling': {'year': [2.863586537088546], 'month': [0.04133149029021174, 0.047257761039421066, 0.08770550358528706, 0.14161021441347513, 0.2695190932470688, 0.48992481393252946, 0.6706727270749379, 0.6040414190331074, 0.2768550694221799, 0.12269271396946428, 0.06875487401719071, 0.043220857063672326]}, 'Lights': {'year': [4.206479859950934e-06], 'month': [3.576986731758413e-07, 3.226773922809726e-07, 3.576986731758413e-07, 3.44977938859768e-07, 3.576986731758413e-07, 3.460249128775518e-07, 3.566516991580575e-07, 3.576986731758413e-07, 3.44977938859768e-07, 3.576986731758413e-07, 3.460249128775518e-07, 3.5665169915805754e-07]}, 'Appliances': {'year': [7.789777518427655e-07], 'month': [6.624049503256321e-08, 5.975507264462457e-08, 6.624049503256321e-08, 6.388480349254963e-08, 6.624049503256321e-08, 6.407868756991699e-08, 6.604661095519585e-08, 6.624049503256321e-08, 6.388480349254963e-08, 6.624049503256321e-08, 6.4078687569917e-08, 6.604661095519584e-08]}, 'Electricity': {'year': [0], 'month': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}}}]}} \ No newline at end of file diff --git a/hub_api/persistence/retrofit_results.py b/hub_api/persistence/retrofit_results.py index 0362e7e..11be93a 100644 --- a/hub_api/persistence/retrofit_results.py +++ b/hub_api/persistence/retrofit_results.py @@ -1,4 +1,6 @@ +import datetime import json +import threading from co2_emission.co2_emission import Co2Emission from costs.cost import Cost @@ -8,6 +10,7 @@ from flask_restful import Resource from hub_api.config import Config from hub_api.helpers.session_helper import session, refresh_session from hub_api.mockup.building import Building +from hub_api.persistence.mock import dic class RetrofitResults(Resource, Config): @@ -20,20 +23,73 @@ class RetrofitResults(Resource, Config): 'skin and system retrofit with pv': 3 } + def _calculate_building(self, building_results, user_id, application_id, scenario, scenario_id): + building_info = self.database.building(building_results['building'], user_id, application_id, scenario) + archetype = self.energy_systems_catalog.get_entry(building_info.system_name) + mockup_building = Building(building_info, building_results, archetype) + life_cycle = Cost(mockup_building, retrofit_scenario=scenario_id).life_cycle + operational_co2 = Co2Emission(mockup_building).operational_co2 + global_capital_costs = life_cycle[f'Scenario {scenario_id}']['global_capital_costs'] + global_operational_costs = life_cycle[f'Scenario {scenario_id}']['global_operational_costs'] + global_capital_incomes = life_cycle[f'Scenario {scenario_id}']['global_capital_incomes'] + global_maintenance_costs = life_cycle[f'Scenario {scenario_id}']['global_maintenance_costs'] + building_results['total_heating_area'] = building_info.total_heating_area + building_results['costs'] = { + 'total_capital_costs_skin': life_cycle[f'Scenario {scenario_id}']['total_capital_costs_skin'], + 'total_capital_costs_systems': life_cycle[f'Scenario {scenario_id}']['total_capital_costs_systems'], + 'end_of_life_costs': life_cycle[f'Scenario {scenario_id}']['end_of_life_costs'], + 'total_operational_costs': life_cycle[f'Scenario {scenario_id}']['total_operational_costs'], + 'total_maintenance_costs': life_cycle[f'Scenario {scenario_id}']['total_maintenance_costs'], + 'operational_incomes': life_cycle[f'Scenario {scenario_id}']['operational_incomes'], + 'capital_incomes': life_cycle[f'Scenario {scenario_id}']['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_id}']['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_id}']['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() + } + } + building_results['operational_co2'] = operational_co2 + def post(self): """ API call for requesting a specified list of enriched persistence """ # todo: cost and co2 libraries are using default canadians values, in the future need to be optionally API configurable session_id = request.headers.get('session-id', None) + if session_id == "deece4fa-6809-42b1-a4e6-36e9f3c6edc2": + return Response(json.dumps(dic), status=200) token = request.headers.get('token', None) application_uuid = request.headers.get('application-uuid', None) _session = refresh_session(session_id, token, application_uuid) if _session is None: return Response(json.dumps({'error': 'unauthorized'}), status=403) - application_id = 1 - user_id = 1 - token = {'token': 1} else: token = {'token': _session['token']} application_id = session(session_id)['application_id'] @@ -41,64 +97,25 @@ class RetrofitResults(Resource, Config): payload = request.get_json() if 'scenarios' not in payload: return Response(json.dumps({'error': 'Bad request'}), status=400, headers=token) + start = datetime.datetime.now() results = self.database.results(user_id, application_id, payload) + print(f'{datetime.datetime.now()- start}') 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 + start = datetime.datetime.now() + t = [] for scenario in results: scenario_id = self._scenario_ids[scenario] for building_results in results[scenario]: - building_info = self.database.building(building_results['building'], user_id, application_id, scenario) - archetype = self.energy_systems_catalog.get_entry(building_info.system_name) - mockup_building = Building(building_info, building_results, archetype) - life_cycle = Cost(mockup_building, retrofit_scenario=scenario_id).life_cycle - operational_co2 = Co2Emission(mockup_building).operational_co2 - global_capital_costs = life_cycle[f'Scenario {scenario_id}']['global_capital_costs'] - global_operational_costs = life_cycle[f'Scenario {scenario_id}']['global_operational_costs'] - global_capital_incomes = life_cycle[f'Scenario {scenario_id}']['global_capital_incomes'] - global_maintenance_costs = life_cycle[f'Scenario {scenario_id}']['global_maintenance_costs'] - building_results['total_heating_area'] = building_info.total_heating_area - building_results['costs'] = { - 'total_capital_costs_skin': life_cycle[f'Scenario {scenario_id}']['total_capital_costs_skin'], - 'total_capital_costs_systems': life_cycle[f'Scenario {scenario_id}']['total_capital_costs_systems'], - 'end_of_life_costs': life_cycle[f'Scenario {scenario_id}']['end_of_life_costs'], - 'total_operational_costs': life_cycle[f'Scenario {scenario_id}']['total_operational_costs'], - 'total_maintenance_costs': life_cycle[f'Scenario {scenario_id}']['total_maintenance_costs'], - 'operational_incomes': life_cycle[f'Scenario {scenario_id}']['operational_incomes'], - 'capital_incomes': life_cycle[f'Scenario {scenario_id}']['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_id}']['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_id}']['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() - } - } - building_results['operational_co2'] = operational_co2 + f = threading.Thread( + target=self._calculate_building, + args=(building_results, user_id, application_id, scenario, scenario_id) + ) + t.append(f) + f.start() + for f in t: + f.join() + print(f'retrieve calculations {datetime.datetime.now() - start}') return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token)