hub/imports/usages/hft_usage_interface.py
2021-06-01 18:31:50 -04:00

142 lines
9.1 KiB
Python

"""
Hft-based interface, it reads format defined within the CERC team based on that one used in SimStadt and developed by
the IAF team at hft-Stuttgart and enriches the city with usages parameters
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import xmltodict
from imports.usages.data_classes.hft_usage_zone_archetype import HftUsageZoneArchetype as huza
from imports.usages.data_classes.hft_internal_gains_archetype import HftInternalGainsArchetype as higa
class HftUsageInterface:
"""
HftUsageInterface abstract class
"""
def __init__(self, base_path, usage_file='ca_library_reduced.xml'):
path = str(base_path / usage_file)
self._usage_archetypes = []
with open(path) as xml:
self._archetypes = xmltodict.parse(xml.read(), force_list=('zoneUsageVariant', 'zoneUsageType'))
for zone_usage_type in self._archetypes['buildingUsageLibrary']['zoneUsageType']:
usage = zone_usage_type['id']
usage_archetype = self._parse_zone_usage_type(usage, zone_usage_type)
self._usage_archetypes.append(usage_archetype)
if 'zoneUsageVariant' in zone_usage_type:
for usage_zone_variant in zone_usage_type['zoneUsageVariant']:
usage = usage_zone_variant['id']
usage_archetype_variant = self._parse_zone_usage_variant(usage, usage_archetype, usage_zone_variant)
self._usage_archetypes.append(usage_archetype_variant)
@staticmethod
def _parse_zone_usage_type(usage, zone_usage_type):
occupancy_density = zone_usage_type['occupancy']['occupancyDensity']
hours_day = zone_usage_type['occupancy']['usageHoursPerDay']
days_year = zone_usage_type['occupancy']['usageDaysPerYear']
cooling_setpoint = zone_usage_type['endUses']['space_cooling']['coolingSetPointTemperature']
heating_setpoint = zone_usage_type['endUses']['space_heating']['heatingSetPointTemperature']
heating_setback = zone_usage_type['endUses']['space_heating']['heatingSetBackTemperature']
mechanical_air_change = None
if 'ventilation' in zone_usage_type['endUses'] and zone_usage_type['endUses']['ventilation'] is not None:
mechanical_air_change = zone_usage_type['endUses']['ventilation']['mechanicalAirChangeRate']
dhw_average_volume_pers_day = None
dhw_preparation_temperature = None
if 'domestic_hot_water' in zone_usage_type['endUses']:
# liters to cubic meters
dhw_average_volume_pers_day = float(
zone_usage_type['endUses']['domestic_hot_water']['averageVolumePerPersAndDay'])/1000
dhw_preparation_temperature = zone_usage_type['endUses']['domestic_hot_water']['preparationTemperature']
electrical_app_average_consumption_sqm_year = None
if 'all_electrical_appliances' in zone_usage_type['endUses']:
if 'averageConsumptionPerSqmAndYear' in zone_usage_type['endUses']['all_electrical_appliances']:
# kWh to J
electrical_app_average_consumption_sqm_year = \
float(zone_usage_type['endUses']['all_electrical_appliances']['averageConsumptionPerSqmAndYear'])/3.6
# todo: for internal_gain in usage_zone_variant['schedules']['internGains']:????????????????
# There are no more internal gains? How is it saved when more than one???
internal_gains = []
if 'internGains' in zone_usage_type['occupancy']:
latent_fraction = zone_usage_type['occupancy']['internGains']['latentFraction']
convective_fraction = zone_usage_type['occupancy']['internGains']['convectiveFraction']
average_internal_gain = zone_usage_type['occupancy']['internGains']['averageInternGainPerSqm']
radiative_fraction = zone_usage_type['occupancy']['internGains']['radiantFraction']
else:
latent_fraction = 0
convective_fraction = 0
average_internal_gain = 0
radiative_fraction = 0
internal_gains.append(higa(average_internal_gain, convective_fraction, radiative_fraction, latent_fraction))
usage_zone_archetype = huza(usage=usage, internal_gains=internal_gains, heating_set_point=heating_setpoint,
heating_set_back=heating_setback, cooling_set_point=cooling_setpoint,
occupancy_density=occupancy_density, hours_day=hours_day, days_year=days_year,
dhw_average_volume_pers_day=dhw_average_volume_pers_day,
dhw_preparation_temperature=dhw_preparation_temperature,
electrical_app_average_consumption_sqm_year=electrical_app_average_consumption_sqm_year,
mechanical_air_change=mechanical_air_change)
return usage_zone_archetype
@staticmethod
def _parse_zone_usage_variant(usage, usage_zone, usage_zone_variant):
# for the variants all is optional because it mimics the inheritance concept from OOP
occupancy_density = usage_zone.occupancy_density
hours_day = usage_zone.hours_day
days_year = usage_zone.days_year
cooling_setpoint = usage_zone.cooling_setpoint
heating_setpoint = usage_zone.heating_setpoint
heating_setback = usage_zone.heating_setback
mechanical_air_change = usage_zone.mechanical_air_change
dhw_average_volume_pers_day = usage_zone.dhw_average_volume_pers_day
dhw_preparation_temperature = usage_zone.dhw_preparation_temperature
electrical_app_average_consumption_sqm_year = usage_zone.electrical_app_average_consumption_sqm_year
# todo: for internal_gain in usage_zone_variant['schedules']['internGains']:????????????????
# There are no more internal gains? How is it saved when more than one???
# for internal_gain in usage_zone.internal_gains:
internal_gains = usage_zone.internal_gains[0]
latent_fraction = internal_gains.latent_fraction
convective_fraction = internal_gains.convective_fraction
average_internal_gain = internal_gains.average_internal_gain
radiative_fraction = internal_gains.radiative_fraction
if 'usageHoursPerDay' in usage_zone_variant['schedules']:
hours_day = usage_zone_variant['schedules']['usageHoursPerDay']
if 'usageDaysPerYear' in usage_zone_variant['schedules']:
days_year = usage_zone_variant['schedules']['usageDaysPerYear']
if 'space_cooling' in usage_zone_variant['endUses'] and usage_zone_variant['endUses']['space_cooling'] is not None:
if 'coolingSetPointTemperature' in usage_zone_variant['endUses']['space_cooling']:
cooling_setpoint = usage_zone_variant['endUses']['space_cooling']['coolingSetPointTemperature']
if 'space_heating' in usage_zone_variant['endUses'] and usage_zone_variant['endUses']['space_heating'] is not None:
if 'heatingSetPointTemperature' in usage_zone_variant['endUses']['space_heating']:
heating_setpoint = usage_zone_variant['endUses']['space_heating']['heatingSetPointTemperature']
if 'heatingSetBackTemperature' in usage_zone_variant['endUses']['space_heating']:
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:
if 'mechanicalAirChangeRate' in usage_zone_variant['endUses']['ventilation']:
mechanical_air_change = usage_zone_variant['endUses']['ventilation']['mechanicalAirChangeRate']
# todo: for internal_gain in usage_zone_variant['schedules']['internGains']:????????????????
# There are no more internal gains? How is it saved when more than one???
if 'internalGains' in usage_zone_variant['schedules'] and usage_zone_variant['schedules']['internGains'] is not None:
internal_gains = []
if 'latentFraction' in usage_zone_variant['schedules']['internGains']:
latent_fraction = usage_zone_variant['schedules']['internGains']['latentFraction']
if 'convectiveFraction' in usage_zone_variant['schedules']['internGains']:
convective_fraction = usage_zone_variant['schedules']['internGains']['convectiveFraction']
if 'averageInternGainPerSqm' in usage_zone_variant['schedules']['internGains']:
average_internal_gain = usage_zone_variant['schedules']['internGains']['averageInternGainPerSqm']
if 'radiantFraction' in usage_zone_variant['schedules']['internGains']:
radiative_fraction = usage_zone_variant['schedules']['internGains']['radiantFraction']
internal_gains.append(higa(average_internal_gain, convective_fraction, radiative_fraction, latent_fraction))
usage_zone_archetype = huza(usage=usage, internal_gains=internal_gains, heating_set_point=heating_setpoint,
heating_set_back=heating_setback, cooling_set_point=cooling_setpoint,
occupancy_density=occupancy_density, hours_day=hours_day, days_year=days_year,
dhw_average_volume_pers_day=dhw_average_volume_pers_day,
dhw_preparation_temperature=dhw_preparation_temperature,
electrical_app_average_consumption_sqm_year=electrical_app_average_consumption_sqm_year,
mechanical_air_change=mechanical_air_change)
return usage_zone_archetype
def enrich_buildings(self):
raise NotImplementedError