2021-01-06 16:42:38 -05:00
|
|
|
"""
|
|
|
|
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 usage parameters
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
|
|
|
|
"""
|
|
|
|
import xmltodict
|
2021-01-07 18:12:13 -05:00
|
|
|
from factories.usage_feeders.data_classes.hft_usage_zone_archetype import HftUsageZoneArchetype as huza
|
|
|
|
from factories.usage_feeders.data_classes.hft_internal_gains_archetype import HftInternalGainsArchetype as higa
|
2021-01-06 16:42:38 -05:00
|
|
|
|
|
|
|
|
|
|
|
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:
|
2021-01-07 18:12:13 -05:00
|
|
|
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']
|
2021-01-07 18:53:26 -05:00
|
|
|
usage_archetype_variant = self._parse_zone_usage_variant(usage, usage_archetype, usage_zone_variant)
|
2021-01-07 18:12:13 -05:00
|
|
|
self._usage_archetypes.append(usage_archetype_variant)
|
2021-01-06 16:42:38 -05:00
|
|
|
|
|
|
|
@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']:
|
|
|
|
dhw_average_volume_pers_day = zone_usage_type['endUses']['domestic_hot_water']['averageVolumePerPersAndDay']
|
|
|
|
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']:
|
|
|
|
electrical_app_average_consumption_sqm_year = \
|
|
|
|
zone_usage_type['endUses']['all_electrical_appliances']['averageConsumptionPerSqmAndYear']
|
|
|
|
|
|
|
|
# todo: for internal_gain in usage_zone_variant['occupancy']['internGains']:????????????????
|
|
|
|
# There are no more internal gains? How is it saved when more than one???
|
|
|
|
internal_gains = []
|
2021-01-07 18:53:26 -05:00
|
|
|
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
|
|
|
|
|
2021-01-07 18:12:13 -05:00
|
|
|
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)
|
2021-01-06 16:42:38 -05:00
|
|
|
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['occupancy']['internGains']:????????????????
|
|
|
|
# There are no more internal gains? How is it saved when more than one???
|
|
|
|
# for internal_gain in usage_zone.internal_gains:
|
2021-01-07 18:53:26 -05:00
|
|
|
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
|
2021-01-06 16:42:38 -05:00
|
|
|
|
|
|
|
if 'usageHoursPerDay' in usage_zone_variant['occupancy']:
|
|
|
|
hours_day = usage_zone_variant['occupancy']['usageHoursPerDay']
|
|
|
|
if 'usageDaysPerYear' in usage_zone_variant['occupancy']:
|
|
|
|
days_year = usage_zone_variant['occupancy']['usageDaysPerYear']
|
2021-01-07 18:53:26 -05:00
|
|
|
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']
|
2021-01-06 16:42:38 -05:00
|
|
|
if 'ventilation' in usage_zone_variant['endUses'] and usage_zone_variant['endUses']['ventilation'] is not None:
|
2021-01-07 18:53:26 -05:00
|
|
|
if 'mechanicalAirChangeRate' in usage_zone_variant['endUses']['ventilation']:
|
|
|
|
mechanical_air_change = usage_zone_variant['endUses']['ventilation']['mechanicalAirChangeRate']
|
2021-01-06 16:42:38 -05:00
|
|
|
# todo: for internal_gain in usage_zone_variant['occupancy']['internGains']:????????????????
|
|
|
|
# There are no more internal gains? How is it saved when more than one???
|
2021-01-07 18:53:26 -05:00
|
|
|
if 'internalGains' in usage_zone_variant['occupancy'] and usage_zone_variant['occupancy']['internGains'] is not None:
|
|
|
|
internal_gains = []
|
|
|
|
if 'latentFraction' in usage_zone_variant['occupancy']['internGains']:
|
|
|
|
latent_fraction = usage_zone_variant['occupancy']['internGains']['latentFraction']
|
|
|
|
if 'convectiveFraction' in usage_zone_variant['occupancy']['internGains']:
|
|
|
|
convective_fraction = usage_zone_variant['occupancy']['internGains']['convectiveFraction']
|
|
|
|
if 'averageInternGainPerSqm' in usage_zone_variant['occupancy']['internGains']:
|
|
|
|
average_internal_gain = usage_zone_variant['occupancy']['internGains']['averageInternGainPerSqm']
|
|
|
|
if 'radiantFraction' in usage_zone_variant['occupancy']['internGains']:
|
|
|
|
radiative_fraction = usage_zone_variant['occupancy']['internGains']['radiantFraction']
|
|
|
|
internal_gains.append(higa(average_internal_gain, convective_fraction, radiative_fraction, latent_fraction))
|
2021-01-07 18:12:13 -05:00
|
|
|
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)
|
2021-01-06 16:42:38 -05:00
|
|
|
return usage_zone_archetype
|
|
|
|
|
2021-01-07 18:12:13 -05:00
|
|
|
def enrich_buildings(self):
|
2021-01-06 16:42:38 -05:00
|
|
|
raise NotImplementedError
|