hub/unittests/test_usage_factory.py

182 lines
11 KiB
Python
Raw Normal View History

2020-11-06 05:40:17 -05:00
"""
TestUsageFactory test and validate the city model structure usage parameters
2020-11-06 05:40:17 -05:00
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
2020-11-06 05:40:17 -05:00
"""
from pathlib import Path
from unittest import TestCase
from imports.geometry_factory import GeometryFactory
from imports.usage_factory import UsageFactory
from imports.geometry.helpers.geometry_helper import GeometryHelper
2021-11-16 07:57:47 -05:00
from imports.construction_factory import ConstructionFactory
2020-11-06 05:40:17 -05:00
class TestUsageFactory(TestCase):
"""
TestUsageFactory TestCase
"""
def setUp(self) -> None:
"""
Configure test environment
:return:
"""
2022-03-08 19:19:52 -05:00
self._city = None
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
2020-11-06 05:40:17 -05:00
def _get_citygml(self, file):
file_path = (self._example_path / file).resolve()
2022-03-08 19:19:52 -05:00
self._city = GeometryFactory('citygml', file_path).city
self.assertIsNotNone(self._city, 'city is none')
return self._city
def _check_buildings(self, city):
for building in city.buildings:
self.assertIsNotNone(building.name, 'building name is none')
self.assertIsNotNone(building.lod, 'building lod is none')
self.assertIsNotNone(building.type, 'building type is none')
self.assertIsNotNone(building.volume, 'building volume is none')
self.assertIsNotNone(building.detailed_polyhedron, 'building detailed polyhedron is none')
self.assertIsNotNone(building.simplified_polyhedron, 'building simplified polyhedron is none')
self.assertIsNotNone(building.surfaces, 'building surfaces is none')
self.assertIsNotNone(building.centroid, 'building centroid is none')
self.assertIsNotNone(building.max_height, 'building max_height is none')
self.assertEqual(len(building.external_temperature), 0, 'building external temperature is calculated')
self.assertEqual(len(building.global_horizontal), 0, 'building global horizontal is calculated')
self.assertEqual(len(building.diffuse), 0, 'building diffuse is calculated')
self.assertEqual(len(building.beam), 0, 'building beam is calculated')
self.assertIsNotNone(building.lower_corner, 'building lower corner is none')
self.assertEqual(len(building.sensors), 0, 'building sensors are assigned')
self.assertIsNotNone(building.internal_zones, 'no internal zones created')
2022-03-08 19:19:52 -05:00
self.assertIsNotNone(building.grounds, 'building grounds is none')
self.assertIsNotNone(building.walls, 'building walls is none')
self.assertIsNotNone(building.roofs, 'building roofs is none')
for internal_zone in building.internal_zones:
self.assertTrue(len(internal_zone.usage_zones) > 0, 'usage zones are not defined')
self.assertIsNone(internal_zone.thermal_zones, 'thermal zones are defined')
self.assertIsNone(building.basement_heated, 'building basement_heated is not none')
self.assertIsNone(building.attic_heated, 'building attic_heated is not none')
2022-03-08 19:19:52 -05:00
self.assertIsNone(building.terrains, 'building terrains is not none')
self.assertIsNotNone(building.year_of_construction, 'building year_of_construction is none')
self.assertIsNotNone(building.function, 'building function is none')
self.assertIsNone(building.average_storey_height, 'building average_storey_height is not none')
self.assertIsNone(building.storeys_above_ground, 'building storeys_above_ground is not none')
2022-03-08 19:19:52 -05:00
self.assertEqual(len(building.heating), 0, 'building heating is not none')
self.assertEqual(len(building.cooling), 0, 'building cooling is not none')
self.assertIsNotNone(building.eave_height, 'building eave height is none')
self.assertIsNotNone(building.roof_type, 'building roof type is none')
self.assertIsNotNone(building.floor_area, 'building floor_area is none')
self.assertIsNone(building.households, 'building households is not none')
self.assertTrue(building.is_conditioned, 'building is not conditioned')
def _check_usage_zone(self, usage_zone):
self.assertIsNotNone(usage_zone.usage, 'usage is none')
self.assertIsNotNone(usage_zone.percentage, 'usage percentage is none')
self.assertIsNotNone(usage_zone.get_internal_gains, 'internal gains is none')
self.assertIsNotNone(usage_zone.hours_day, 'hours per day is none')
self.assertIsNotNone(usage_zone.days_year, 'days per year is none')
self.assertIsNotNone(usage_zone.thermal_control, 'thermal control is none')
self.assertIsNotNone(usage_zone.thermal_control.mean_heating_set_point, 'control heating set point is none')
self.assertIsNotNone(usage_zone.thermal_control.heating_set_back, 'control heating set back is none')
self.assertIsNotNone(usage_zone.thermal_control.mean_cooling_set_point, 'control cooling set point is none')
2022-03-08 19:19:52 -05:00
def test_import_comnet(self):
"""
Enrich the city with the usage information from comnet and verify it
"""
file = 'pluto_building.gml'
city = self._get_citygml(file)
for building in city.buildings:
building.function = GeometryHelper.libs_function_from_pluto(building.function)
2022-03-08 19:19:52 -05:00
UsageFactory('comnet', city).enrich()
2022-03-08 19:19:52 -05:00
self._check_buildings(city)
for building in city.buildings:
2022-03-08 20:08:03 -05:00
for internal_zone in building.internal_zones:
self.assertIsNot(len(internal_zone.usage_zones), 0, 'no building usage_zones defined')
for usage_zone in internal_zone.usage_zones:
self._check_usage_zone(usage_zone)
self.assertIsNotNone(usage_zone.mechanical_air_change, 'mechanical air change is none')
self.assertIsNotNone(usage_zone.thermal_control.heating_set_point_schedules,
'control heating set point schedule is none')
self.assertIsNotNone(usage_zone.thermal_control.cooling_set_point_schedules,
'control cooling set point schedule is none')
self.assertIsNotNone(usage_zone.occupancy, 'occupancy is none')
occupancy = usage_zone.occupancy
self.assertIsNotNone(occupancy.occupancy_density, 'occupancy density is none')
self.assertIsNotNone(occupancy.latent_internal_gain, 'occupancy latent internal gain is none')
self.assertIsNotNone(occupancy.sensible_convective_internal_gain,
'occupancy sensible convective internal gain is none')
self.assertIsNotNone(occupancy.sensible_radiative_internal_gain,
'occupancy sensible radiant internal gain is none')
self.assertIsNotNone(occupancy.occupancy_schedules, 'occupancy schedule is none')
self.assertIsNone(occupancy.occupants, 'occupancy density is not none')
self.assertIsNotNone(usage_zone.lighting, 'lighting is none')
lighting = usage_zone.lighting
self.assertIsNotNone(lighting.lighting_density, 'lighting density is none')
self.assertIsNotNone(lighting.latent_fraction, 'lighting latent fraction is none')
self.assertIsNotNone(lighting.convective_fraction, 'lighting convective fraction is none')
self.assertIsNotNone(lighting.radiative_fraction, 'lighting radiant fraction is none')
self.assertIsNotNone(lighting.schedules, 'lighting schedule is none')
self.assertIsNotNone(usage_zone.appliances, 'appliances is none')
appliances = usage_zone.appliances
self.assertIsNotNone(appliances.appliances_density, 'appliances density is none')
self.assertIsNotNone(appliances.latent_fraction, 'appliances latent fraction is none')
self.assertIsNotNone(appliances.convective_fraction, 'appliances convective fraction is none')
self.assertIsNotNone(appliances.radiative_fraction, 'appliances radiant fraction is none')
self.assertIsNotNone(appliances.schedules, 'appliances schedule is none')
self.assertIsNotNone(usage_zone.thermal_control.hvac_availability_schedules,
'control hvac availability is none')
def test_import_ca(self):
2020-11-06 05:40:17 -05:00
"""
Enrich the city with the usage information from canada and verify it
2020-11-06 05:40:17 -05:00
"""
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
UsageFactory('ca', city).enrich()
self._check_buildings(city)
2020-11-06 05:40:17 -05:00
for building in city.buildings:
2022-03-08 20:08:03 -05:00
for internal_zone in building.internal_zones:
self.assertIsNot(len(internal_zone.usage_zones), 0, 'no building usage_zones defined')
for usage_zone in internal_zone.usage_zones:
self._check_usage_zone(usage_zone)
self.assertIsNotNone(usage_zone.mechanical_air_change, 'mechanical air change is none')
self.assertIsNotNone(usage_zone.not_detailed_source_mean_annual_internal_gains,
'not detailed internal gains is none')
def test_import_hft(self):
2022-03-08 19:19:52 -05:00
"""
Enrich the city with the usage information from hft and verify it
2022-03-08 19:19:52 -05:00
"""
file = 'pluto_building.gml'
city = self._get_citygml(file)
for building in city.buildings:
building.function = GeometryHelper.libs_function_from_pluto(building.function)
UsageFactory('hft', city).enrich()
self._check_buildings(city)
for building in city.buildings:
2022-03-08 20:08:03 -05:00
for internal_zone in building.internal_zones:
self.assertIsNot(len(internal_zone.usage_zones), 0, 'no building usage_zones defined')
for usage_zone in internal_zone.usage_zones:
self._check_usage_zone(usage_zone)
self.assertIsNone(usage_zone.mechanical_air_change, 'mechanical air change is not none')
self.assertIsNotNone(usage_zone.thermal_control.heating_set_point_schedules,
'control heating set point schedule is none')
self.assertIsNotNone(usage_zone.thermal_control.cooling_set_point_schedules,
'control cooling set point schedule is none')
self.assertIsNotNone(usage_zone.occupancy, 'occupancy is none')
occupancy = usage_zone.occupancy
self.assertIsNotNone(occupancy.occupancy_density, 'occupancy density is none')
self.assertIsNone(occupancy.latent_internal_gain, 'occupancy latent internal gain is none')
self.assertIsNone(occupancy.sensible_convective_internal_gain,
'occupancy sensible convective internal gain is not none')
self.assertIsNone(occupancy.sensible_radiative_internal_gain,
'occupancy sensible radiant internal gain is not none')
self.assertIsNone(occupancy.occupancy_schedules, 'occupancy schedule is not none')
self.assertIsNone(occupancy.occupants, 'occupancy density is not none')
self.assertIsNone(usage_zone.lighting, 'lighting is not none')
self.assertIsNone(usage_zone.appliances, 'appliances is not none')