energy_system_modelling_wor.../helpers/enrich_city.py
2023-01-10 12:03:27 -05:00

109 lines
4.0 KiB
Python

"""
Enrich city
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder 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
from hub_logger import logger
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,
pickle_construction=False, pickle_usage=False, pickle_schedules=False):
"""
Enrich the city with the given formats
:return: City
"""
if self._enriched_city is None:
self._errors = []
print('original:', len(self._city.buildings))
logger.info(f'Building length prior to enrichment: {len(self._city.buildings)}')
if not pickle_construction:
if construction_format is not None:
self._enriched_city = self._construction(construction_format)
if len(self._errors) != 0:
return self._enriched_city
if not pickle_usage:
if usage_format is not None:
self._enriched_city = self._usage(usage_format)
if len(self._errors) != 0:
return self._enriched_city
if not pickle_schedules:
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):
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 len(building.thermal_zones) == 0:
self._city.remove_city_object(building)
elif 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))
logger.info(f'City 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))
logger.info(f'City enriched with occupancy: {len(self._city.buildings)}')
return self._city