forked from s_ranjbar/city_retrofit
100 lines
3.7 KiB
Python
100 lines
3.7 KiB
Python
"""
|
|
Enrich city
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
"""
|
|
|
|
from imports.construction_factory import ConstructionFactory
|
|
from imports.usage_factory import UsageFactory
|
|
from imports.schedules_factory import SchedulesFactory
|
|
|
|
|
|
class EnrichCity:
|
|
"""
|
|
Enrich city
|
|
"""
|
|
|
|
def __init__(self, city):
|
|
self._city = city
|
|
self._enriched_city = None
|
|
self._errors = []
|
|
|
|
@property
|
|
def errors(self) -> [str]:
|
|
"""
|
|
Error list
|
|
"""
|
|
return self._errors
|
|
|
|
def enriched_city(self, construction_format=None, usage_format=None, schedules_format=None):
|
|
"""
|
|
Enrich the city with the given formats
|
|
:return: City
|
|
"""
|
|
if self._enriched_city is None:
|
|
self._errors = []
|
|
print('original:', len(self._city.buildings))
|
|
if construction_format is not None:
|
|
self._enriched_city = self._construction(construction_format)
|
|
if len(self._errors) != 0:
|
|
return self._enriched_city
|
|
if usage_format is not None:
|
|
self._enriched_city = self._usage(usage_format)
|
|
if len(self._errors) != 0:
|
|
return self._enriched_city
|
|
if schedules_format is not None:
|
|
self._enriched_city = self._schedules(schedules_format)
|
|
if len(self._errors) != 0:
|
|
return self._enriched_city
|
|
self._enriched_city = self._city
|
|
return self._enriched_city
|
|
|
|
def _construction(self, construction_format):
|
|
|
|
# todo: in construction factory, when adding the values to the thermal zones,
|
|
# these are created using the just read storeys_above_ground -> review where to assign this value!!
|
|
ConstructionFactory(construction_format, self._city).enrich()
|
|
for building in self._city.buildings:
|
|
# infiltration_rate_system_off is a mandatory parameter.
|
|
# If it is not returned, extract the building from the calculation list
|
|
if building.thermal_zones[0].infiltration_rate_system_off is None:
|
|
self._city.remove_city_object(building)
|
|
if self._city.buildings is None:
|
|
self._errors.append('no archetype found per construction')
|
|
self._enriched_city = self._city
|
|
return self._enriched_city
|
|
print('enriched with construction:', len(self._city.buildings))
|
|
return self._city
|
|
|
|
def _usage(self, usage_format):
|
|
UsageFactory(usage_format, self._city).enrich()
|
|
for building in self._city.buildings:
|
|
# At least one thermal zone must be created.
|
|
# If it is not created, extract the building from the calculation list
|
|
if len(building.usage_zones) <= 0:
|
|
self._city.remove_city_object(building)
|
|
if self._city.buildings is None:
|
|
self._errors.append('no archetype found per usage')
|
|
self._enriched_city = self._city
|
|
return self._enriched_city
|
|
print('enriched with usage:', len(self._city.buildings))
|
|
return self._city
|
|
|
|
def _schedules(self, schedules_format):
|
|
SchedulesFactory(schedules_format, self._city).enrich()
|
|
for building in self._city.buildings:
|
|
counter_schedules = 0
|
|
for usage_zone in building.usage_zones:
|
|
# At least one schedule must be created at each thermal zone.
|
|
# If it is not created, extract the building from the calculation list
|
|
if len(usage_zone.schedules) > 0:
|
|
counter_schedules += 1
|
|
if counter_schedules < len(building.usage_zones):
|
|
self._city.remove_city_object(building)
|
|
if self._city.buildings is None:
|
|
self._errors.append('no archetype found per usage')
|
|
self._enriched_city = self._city
|
|
return self._enriched_city
|
|
print('enriched with occupancy:', len(self._city.buildings))
|
|
return self._city
|