143 lines
9.2 KiB
Python
143 lines
9.2 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 usage parameters
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
|
|
"""
|
|
import xmltodict
|
|
from factories.usage_feeders.data_classes.hft_usage_zone_archetype import HftUsageZoneArchetype
|
|
from factories.usage_feeders.data_classes.hft_internal_gains_archetype import HftInternalGainsArchetype
|
|
|
|
|
|
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')
|
|
# todo: how to read all zone_usage_types in file?
|
|
zone_usage_type = 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, zone_usage_type, 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']:
|
|
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 = []
|
|
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']
|
|
internal_gains.append(HftInternalGainsArchetype(average_internal_gain, convective_fraction,
|
|
radiative_fraction, latent_fraction))
|
|
usage_zone_archetype = HftUsageZoneArchetype(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['occupancy']['internGains']:????????????????
|
|
# There are no more internal gains? How is it saved when more than one???
|
|
# for internal_gain in usage_zone.internal_gains:
|
|
internal_gain = usage_zone.internal_gains[0]
|
|
latent_fraction = internal_gain.latent_fraction
|
|
convective_fraction = internal_gain.convective_fraction
|
|
average_internal_gain = internal_gain.average_internal_gain
|
|
radiative_fraction = internal_gain.radiative_fraction
|
|
|
|
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']
|
|
if 'coolingSetPointTemperature' in usage_zone_variant['endUses']['space_cooling']:
|
|
cooling_setpoint = usage_zone_variant['endUses']['space_cooling']['coolingSetPointTemperature']
|
|
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:
|
|
mechanical_air_change = usage_zone_variant['endUses']['ventilation']['mechanicalAirChangeRate']
|
|
# 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 = []
|
|
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(HftInternalGainsArchetype(average_internal_gain, convective_fraction,
|
|
radiative_fraction, latent_fraction))
|
|
usage_zone_archetype = HftUsageZoneArchetype(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 fill_buildings(self):
|
|
raise NotImplementedError
|
|
|
|
def _search_archetype(self, building_usage):
|
|
raise NotImplementedError
|
|
|
|
def _assign_values(self, building, archetype):
|
|
raise NotImplementedError
|