88 lines
5.3 KiB
Python
88 lines
5.3 KiB
Python
"""
|
|
UsBaseUsageParameters base class to model the usage properties for a building in NYC and US
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
|
"""
|
|
from pathlib import Path
|
|
|
|
import xmltodict
|
|
|
|
from city_model_structure.attributes.internal_gains import InternalGains
|
|
from city_model_structure.attributes.usage_zone import UsageZone
|
|
|
|
|
|
class UsBaseUsageParameters:
|
|
"""
|
|
UsBaseUsageParameters class
|
|
"""
|
|
def __init__(self, city, function_to_usage):
|
|
self._city = city
|
|
# todo: control not archetype found
|
|
# ToDo: this is using the german library as a temporary approach, need to use/define a library for US
|
|
path = str(Path(__file__).parent.parent.parent / 'data/usage/de_library.xml')
|
|
print('usage:', path)
|
|
with open(path) as xml:
|
|
self._library = xmltodict.parse(xml.read(), force_list='zoneUsageVariant')
|
|
for city_object in self._city.buildings:
|
|
# ToDo: Right now is just one usage zone but will be multiple in the future
|
|
usage_zone = UsageZone()
|
|
usage_zone.usage = function_to_usage(city_object.function)
|
|
for zone_usage_type in self._library['buildingUsageLibrary']['zoneUsageType']:
|
|
if zone_usage_type['id'] != usage_zone.usage:
|
|
if 'zoneUsageVariant' in zone_usage_type:
|
|
for usage_zone_variant in zone_usage_type['zoneUsageVariant']:
|
|
if usage_zone_variant['id'] == usage_zone.usage:
|
|
# pre-initialize the usage zone with the main type
|
|
usage_zone = UsBaseUsageParameters._parse_zone_usage_type(zone_usage_type, usage_zone)
|
|
usage_zone = UsBaseUsageParameters._parse_zone_usage_variant(usage_zone_variant, usage_zone)
|
|
city_object.usage_zone = [usage_zone]
|
|
break
|
|
continue
|
|
city_object.usage_zones = [UsBaseUsageParameters._parse_zone_usage_type(zone_usage_type, usage_zone)]
|
|
break
|
|
if city_object.usage_zones is None:
|
|
raise Exception('Usage not found for building function')
|
|
|
|
@staticmethod
|
|
def _parse_zone_usage_type(zone_usage_type, usage_zone):
|
|
usage_zone.hours_day = zone_usage_type['occupancy']['usageHoursPerDay']
|
|
usage_zone.days_year = zone_usage_type['occupancy']['usageDaysPerYear']
|
|
usage_zone.cooling_setpoint = zone_usage_type['endUses']['space_cooling']['coolingSetPointTemperature']
|
|
usage_zone.heating_setpoint = zone_usage_type['endUses']['space_heating']['heatingSetPointTemperature']
|
|
usage_zone.heating_setback = zone_usage_type['endUses']['space_heating']['heatingSetBackTemperature']
|
|
if 'ventilation' in zone_usage_type['endUses'] and zone_usage_type['endUses']['ventilation'] is not None:
|
|
usage_zone.mechanical_air_change = zone_usage_type['endUses']['ventilation']['mechanicalAirChangeRate']
|
|
int_gains = InternalGains()
|
|
int_gains.latent_fraction = zone_usage_type['occupancy']['internGains']['latentFraction']
|
|
int_gains.convective_fraction = zone_usage_type['occupancy']['internGains']['convectiveFraction']
|
|
int_gains.average_internal_gain = zone_usage_type['occupancy']['internGains']['averageInternGainPerSqm']
|
|
int_gains.radiative_fraction = zone_usage_type['occupancy']['internGains']['radiantFraction']
|
|
usage_zone.internal_gains = [int_gains]
|
|
return usage_zone
|
|
|
|
@staticmethod
|
|
def _parse_zone_usage_variant(usage_zone_variant, usage_zone):
|
|
# for the variants all is optional because it mimics the inheritance concept from OOP
|
|
if 'usageHoursPerDay' in usage_zone_variant['occupancy']:
|
|
usage_zone.hours_day = usage_zone_variant['occupancy']['usageHoursPerDay']
|
|
if 'usageDaysPerYear' in usage_zone_variant['occupancy']:
|
|
usage_zone.days_year = usage_zone_variant['occupancy']['usageDaysPerYear']
|
|
if 'coolingSetPointTemperature' in usage_zone_variant['endUses']['space_cooling']:
|
|
usage_zone.cooling_setpoint = usage_zone_variant['endUses']['space_cooling']['coolingSetPointTemperature']
|
|
if 'heatingSetPointTemperature' in usage_zone_variant['endUses']['space_heating']:
|
|
usage_zone.heating_setpoint = usage_zone_variant['endUses']['space_heating']['heatingSetPointTemperature']
|
|
if 'heatingSetBackTemperature' in usage_zone_variant['endUses']['space_heating']:
|
|
usage_zone.heating_setback = usage_zone_variant['endUses']['space_heating']['heatingSetBackTemperature']
|
|
if 'ventilation' in usage_zone_variant['endUses'] and usage_zone_variant['endUses']['ventilation'] is not None:
|
|
usage_zone.mechanical_air_change = usage_zone_variant['endUses']['ventilation']['mechanicalAirChangeRate']
|
|
if 'latentFraction' in usage_zone_variant['occupancy']['internGains']:
|
|
usage_zone.int_gains[0].latent_fraction = usage_zone_variant['occupancy']['internGains']['latentFraction']
|
|
if 'convectiveFraction' in usage_zone_variant['occupancy']['internGains']:
|
|
usage_zone.int_gains[0].convective_fraction = usage_zone_variant['occupancy']['internGains']['convectiveFraction']
|
|
if 'averageInternGainPerSqm' in usage_zone_variant['occupancy']['internGains']:
|
|
usage_zone.int_gains[0].average_internal_gain = \
|
|
usage_zone_variant['occupancy']['internGains']['averageInternGainPerSqm']
|
|
if 'radiantFraction' in usage_zone_variant['occupancy']['internGains']:
|
|
usage_zone.int_gains[0].radiative_fraction = usage_zone_variant['occupancy']['internGains']['radiantFraction']
|
|
return usage_zone
|