only 2 unittest don't pass and must be reviewed, test_import_obj and test_subway

This commit is contained in:
Pilar 2021-08-11 11:14:06 -04:00
parent 11982a35bd
commit 2f86f6c8d4
7 changed files with 118 additions and 23 deletions

View File

@ -6,7 +6,6 @@ Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import uuid
from typing import List, TypeVar
from city_model_structure.building_demand.surface import Surface
from city_model_structure.building_demand.usage_zone import UsageZone
ThermalBoundary = TypeVar('ThermalBoundary')

View File

@ -0,0 +1,77 @@
"""
CaUsageParameters model the usage properties
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import sys
from imports.geometry.helpers.geometry_helper import GeometryHelper as gh
from imports.usage.hft_usage_interface import HftUsageInterface
from city_model_structure.building_demand.usage_zone import UsageZone
from city_model_structure.building_demand.internal_gains import InternalGains
class CaUsageParameters(HftUsageInterface):
"""
CaUsageParameters class
"""
def __init__(self, city, base_path):
super().__init__(base_path, 'ca_archetypes_reduced.xml')
self._city = city
# todo: this is a wrong location for self._min_air_change -> re-think where to place this info
# and where it comes from
self._min_air_change = 0
def enrich_buildings(self):
"""
Returns the city with the usage parameters assigned to the buildings
:return:
"""
city = self._city
for building in city.buildings:
archetype = self._search_archetype(building.function)
if archetype is None:
sys.stderr.write(f'Building {building.name} has unknown archetype for building function:'
f' {building.function}, that assigns building usage as '
f'{gh.usage_from_function(building.function)}\n')
continue
# todo: what to do with mix-usage usage from gml?
mix_usage = False
if not mix_usage:
# just one usage_zone
for thermal_zone in building.thermal_zones:
usage_zone = UsageZone()
self._assign_values(usage_zone, archetype)
thermal_zone.usage_zones = [usage_zone]
def _search_archetype(self, building_usage):
for building_archetype in self._usage_archetypes:
if building_archetype.usage == building_usage:
return building_archetype
return None
@staticmethod
def _assign_values(usage_zone, archetype):
usage_zone.usage = archetype.usage
# Due to the fact that python is not a typed language, the wrong object type is assigned to
# usage_zone.internal_gains when writing usage_zone.internal_gains = archetype.internal_gains.
# Therefore, this walk around has been done.
internal_gains = []
for ig in archetype.internal_gains:
internal_gain = InternalGains()
internal_gain.average_internal_gain = ig.average_internal_gain
internal_gain.convective_fraction = ig.convective_fraction
internal_gain.radiative_fraction = ig.radiative_fraction
internal_gain.latent_fraction = ig.latent_fraction
internal_gains.append(internal_gain)
usage_zone.internal_gains = internal_gains
usage_zone.heating_setpoint = archetype.heating_setpoint
usage_zone.heating_setback = archetype.heating_setback
usage_zone.cooling_setpoint = archetype.cooling_setpoint
usage_zone.occupancy_density = archetype.occupancy_density
usage_zone.hours_day = archetype.hours_day
usage_zone.days_year = archetype.days_year
usage_zone.dhw_average_volume_pers_day = archetype.dhw_average_volume_pers_day
usage_zone.dhw_preparation_temperature = archetype.dhw_preparation_temperature
usage_zone.electrical_app_average_consumption_sqm_year = archetype.electrical_app_average_consumption_sqm_year
usage_zone.mechanical_air_change = archetype.mechanical_air_change

View File

@ -100,10 +100,6 @@ class HftUsageInterface:
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']
@ -117,17 +113,22 @@ class HftUsageInterface:
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))
if 'schedules' in usage_zone_variant:
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 '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,

View File

@ -16,8 +16,7 @@ class HftUsageParameters(HftUsageInterface):
HftUsageParameters class
"""
def __init__(self, city, base_path):
#todo: 'de_library.xml'
super().__init__(base_path, 'ca_archetypes_reduced.xml')
super().__init__(base_path, 'de_library.xml')
self._city = city
# todo: this is a wrong location for self._min_air_change -> re-think where to place this info
# and where it comes from
@ -43,7 +42,7 @@ class HftUsageParameters(HftUsageInterface):
for thermal_zone in building.thermal_zones:
usage_zone = UsageZone()
self._assign_values(usage_zone, archetype)
thermal_zone.usage_zone = [usage_zone]
thermal_zone.usage_zones = [usage_zone]
def _search_archetype(self, building_usage):
for building_archetype in self._usage_archetypes:

View File

@ -5,6 +5,7 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc
"""
from pathlib import Path
from imports.usage.hft_usage_parameters import HftUsageParameters
from imports.usage.ca_usage_parameters import CaUsageParameters
class UsageFactory:
@ -19,6 +20,9 @@ class UsageFactory:
def _hft(self):
HftUsageParameters(self._city, self._base_path).enrich_buildings()
def _ca(self):
CaUsageParameters(self._city, self._base_path).enrich_buildings()
def _other_usage_library_format(self):
raise Exception('Not implemented')

View File

@ -53,9 +53,7 @@ class TestGeometryFactory(TestCase):
Test city objects in the city
:return: None
"""
# todo @Guille: when reading gml, pluto_building.gml has no surfaces
#file = 'one_building_in_kelowna.gml'
file = 'pluto_building.gml'
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
self.assertTrue(len(city.buildings) == 1)
for building in city.buildings:

View File

@ -34,12 +34,12 @@ class TestUsageFactory(TestCase):
Enrich the city with the usage information and verify it
:return: None
"""
# case 1: HFT
file = 'pluto_building.gml'
city = self._get_citygml(file)
for building in city.buildings:
building.function = GeometryHelper.pluto_to_function[building.function]
# case 1: HFT
UsageFactory('hft', city).enrich()
for building in city.buildings:
self.assertIsNot(len(building.usage_zones), 0, 'no building usage_zones defined')
@ -55,3 +55,20 @@ class TestUsageFactory(TestCase):
self.assertIsNotNone(usage_zone.dhw_average_volume_pers_day, 'usage is none')
self.assertIsNotNone(usage_zone.dhw_preparation_temperature, 'usage is none')
self.assertIsNotNone(usage_zone.electrical_app_average_consumption_sqm_year, 'usage is none')
# case 2: CA
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
UsageFactory('ca', city).enrich()
for building in city.buildings:
self.assertIsNot(len(building.usage_zones), 0, 'no building usage_zones defined')
for usage_zone in building.usage_zones:
self.assertIsNotNone(usage_zone.usage, 'usage is none')
self.assertIsNotNone(usage_zone.internal_gains, 'usage is none')
self.assertIsNotNone(usage_zone.cooling_setpoint, 'usage is none')
self.assertIsNotNone(usage_zone.heating_setback, 'usage is none')
self.assertIsNotNone(usage_zone.heating_setpoint, 'usage is none')
self.assertIsNotNone(usage_zone.occupancy_density, 'usage is none')
self.assertIsNotNone(usage_zone.hours_day, 'usage is none')
self.assertIsNotNone(usage_zone.days_year, 'usage is none')