Convert insel meb to object
This commit is contained in:
parent
ab4745bca9
commit
0661ab21ec
@ -20,7 +20,7 @@ class Config:
|
||||
dotenv_path = Path(dotenv_path).resolve()
|
||||
|
||||
environment = 'TEST'
|
||||
database_name = 'montreal_retrofit_test'
|
||||
database_name = 'montreal_retrofit'
|
||||
|
||||
self._database = DBControl(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
|
||||
self._repository = Repository(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
|
||||
|
@ -27,46 +27,47 @@ class Building:
|
||||
self._roof_area = building_info.roof_area
|
||||
self._total_pv_area = building_info.total_pv_area
|
||||
self._energy_systems_archetype_name = building_info.system_name
|
||||
print(results)
|
||||
self._heating_consumption = {
|
||||
cte.YEAR: results['yearly_heating_consumption'],
|
||||
cte.MONTH: results['monthly_heating_consumption']
|
||||
cte.YEAR: results['insel meb']['yearly_heating_consumption'],
|
||||
cte.MONTH: results['insel meb']['monthly_heating_consumption']
|
||||
}
|
||||
print(self._heating_consumption)
|
||||
self._cooling_consumption = {
|
||||
cte.YEAR: results['yearly_cooling_consumption'],
|
||||
cte.MONTH: results['monthly_cooling_consumption']
|
||||
cte.YEAR: results['insel meb']['yearly_cooling_consumption'],
|
||||
cte.MONTH: results['insel meb']['monthly_cooling_consumption']
|
||||
}
|
||||
self._domestic_hot_water_consumption = {
|
||||
cte.YEAR: results['yearly_domestic_hot_water_consumption'],
|
||||
cte.MONTH: results['monthly_domestic_hot_water_consumption']
|
||||
cte.YEAR: results['insel meb']['yearly_domestic_hot_water_consumption'],
|
||||
cte.MONTH: results['insel meb']['monthly_domestic_hot_water_consumption']
|
||||
}
|
||||
self._lighting_electrical_demand = {
|
||||
cte.YEAR: results['yearly_lighting_electrical_demand'],
|
||||
cte.MONTH: results['monthly_lighting_electrical_demand']
|
||||
cte.YEAR: results['insel meb']['yearly_lighting_electrical_demand'],
|
||||
cte.MONTH: results['insel meb']['monthly_lighting_electrical_demand']
|
||||
}
|
||||
self._appliances_electrical_demand = {
|
||||
cte.YEAR: results['yearly_appliances_electrical_demand'],
|
||||
cte.MONTH: results['monthly_appliances_electrical_demand']
|
||||
cte.YEAR: results['insel meb']['yearly_appliances_electrical_demand'],
|
||||
cte.MONTH: results['insel meb']['monthly_appliances_electrical_demand']
|
||||
}
|
||||
self._heating_peak_load = {
|
||||
cte.YEAR: results['yearly_heating_peak_load'],
|
||||
cte.MONTH: results['monthly_heating_peak_load']
|
||||
cte.YEAR: results['insel meb']['yearly_heating_peak_load'],
|
||||
cte.MONTH: results['insel meb']['monthly_heating_peak_load']
|
||||
}
|
||||
self._cooling_peak_load = {
|
||||
cte.YEAR: results['yearly_cooling_peak_load'],
|
||||
cte.MONTH: results['monthly_cooling_peak_load']
|
||||
cte.YEAR: results['insel meb']['yearly_cooling_peak_load'],
|
||||
cte.MONTH: results['insel meb']['monthly_cooling_peak_load']
|
||||
}
|
||||
self._lighting_peak_load = {
|
||||
cte.YEAR: results['yearly_lighting_peak_load'],
|
||||
cte.MONTH: results['monthly_lighting_peak_load']
|
||||
cte.YEAR: results['insel meb']['yearly_lighting_peak_load'],
|
||||
cte.MONTH: results['insel meb']['monthly_lighting_peak_load']
|
||||
}
|
||||
self._appliances_peak_load = {
|
||||
cte.YEAR: results['yearly_appliances_peak_load'],
|
||||
cte.MONTH: results['monthly_appliances_peak_load']
|
||||
cte.YEAR: results['insel meb']['yearly_appliances_peak_load'],
|
||||
cte.MONTH: results['insel meb']['monthly_appliances_peak_load']
|
||||
}
|
||||
self._onsite_electrical_production = {
|
||||
cte.YEAR: results['yearly_on_site_electrical_production'],
|
||||
cte.MONTH: results['monthly_on_site_electrical_production']
|
||||
cte.YEAR: results['insel meb']['yearly_on_site_electrical_production'],
|
||||
cte.MONTH: results['insel meb']['monthly_on_site_electrical_production']
|
||||
}
|
||||
self._catalog_archetype = catalog_archetype
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import json
|
||||
|
||||
from co2_emission.co2_emission import Co2Emission
|
||||
from costs.cost import Cost
|
||||
from flask import Response, request
|
||||
from flask_restful import Resource
|
||||
|
||||
from costs.cost import Cost
|
||||
from co2_emission.co2_emission import Co2Emission
|
||||
from hub_api.config import Config
|
||||
from hub_api.helpers.session_helper import session, refresh_session
|
||||
from hub_api.mockup.building import Building
|
||||
@ -24,40 +24,34 @@ class RetrofitResults(Resource, Config):
|
||||
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)
|
||||
token = {'token': _session['token']}
|
||||
application_id = session(session_id)['application_id']
|
||||
user_id = session(session_id)['user_id']
|
||||
# return Response(json.dumps({'error': 'unauthorized'}), status=403)
|
||||
application_id = 2
|
||||
user_id = 1
|
||||
token = {'token': 1}
|
||||
else:
|
||||
token = {'token': _session['token']}
|
||||
application_id = session(session_id)['application_id']
|
||||
user_id = session(session_id)['user_id']
|
||||
payload = request.get_json()
|
||||
if 'scenarios' not in payload:
|
||||
return Response(json.dumps({'error': 'Bad request'}), status=400, headers=token)
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
mockup_building = Building(building_info, building_results, 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'],
|
||||
|
Loading…
Reference in New Issue
Block a user