hub/unittests/test_usage_factory.py
2022-03-24 18:43:55 -04:00

181 lines
10 KiB
Python

"""
TestUsageFactory test and validate the city model structure usage parameters
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
from pathlib import Path
from unittest import TestCase
from imports.geometry_factory import GeometryFactory
from imports.usage_factory import UsageFactory
from imports.schedules_factory import SchedulesFactory
from imports.construction_factory import ConstructionFactory
from imports.geometry.helpers.geometry_helper import GeometryHelper
from imports.construction_factory import ConstructionFactory
class TestUsageFactory(TestCase):
"""
TestUsageFactory TestCase
"""
def setUp(self) -> None:
"""
Configure test environment
:return:
"""
self._city = None
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
def _get_citygml(self, file):
file_path = (self._example_path / file).resolve()
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.geometrical_zones, 'no geometrical zones created')
self.assertIsNotNone(building.grounds, 'building grounds is none')
self.assertIsNotNone(building.walls, 'building walls is none')
self.assertIsNotNone(building.roofs, 'building roofs is none')
self.assertTrue(len(building.usage_zones) > 0, 'usage zones are not defined')
self.assertTrue(len(building.thermal_zones) > 0, 'thermal zones are not defined')
self.assertIsNotNone(building.basement_heated, 'building basement_heated is none')
self.assertIsNotNone(building.attic_heated, 'building attic_heated is none')
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.assertIsNotNone(building.average_storey_height, 'building average_storey_height is none')
self.assertIsNotNone(building.storeys_above_ground, 'building storeys_above_ground is none')
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.storeys, 'building storeys are not defined')
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_thermal_zones(self, building):
for thermal_zone in building.thermal_zones:
self.assertIsNotNone(thermal_zone.id, 'thermal_zone id is none')
self.assertIsNotNone(thermal_zone.floor_area, 'thermal_zone floor area is none')
self.assertTrue(len(thermal_zone.thermal_boundaries) > 0, 'thermal_zone thermal_boundaries not defined')
self.assertIsNotNone(thermal_zone.additional_thermal_bridge_u_value, 'additional_thermal_bridge_u_value is none')
self.assertIsNotNone(thermal_zone.effective_thermal_capacity, 'thermal_zone effective_thermal_capacity is none')
self.assertIsNotNone(thermal_zone.indirectly_heated_area_ratio,
'thermal_zone indirectly_heated_area_ratio is none')
self.assertIsNotNone(thermal_zone.infiltration_rate_system_off,
'thermal_zone infiltration_rate_system_off is none')
self.assertIsNotNone(thermal_zone.infiltration_rate_system_on, 'thermal_zone infiltration_rate_system_on is none')
self.assertIsNotNone(thermal_zone.usage_zones, 'thermal_zone usage_zones is none')
self.assertIsNotNone(thermal_zone.volume, 'thermal_zone volume is none')
self.assertIsNone(thermal_zone.ordinate_number, 'thermal_zone ordinate number is not none')
self.assertIsNotNone(thermal_zone.thermal_control, 'thermal_zone thermal_control is not none')
self.assertIsNotNone(thermal_zone.hvac_system, 'thermal_zone hvac_system is not none')
def _check_usage_zones(self, building):
for usage_zone in building.usage_zones:
self.assertIsNotNone(usage_zone.usage, 'usage is none')
self.assertIsNotNone(usage_zone.not_detailed_source_mean_annual_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')
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')
self.assertIsNotNone(usage_zone.is_heated, 'thermal_zone heated is none')
self.assertIsNotNone(usage_zone.is_cooled, 'thermal_zone cooled is none')
def _check_hvac(self, thermal_zone):
self.assertIsNotNone(None, 'hvac')
def _check_control(self, thermal_zone):
self.assertIsNotNone(None, 'control')
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.pluto_to_function[building.function]
ConstructionFactory('nrel', city).enrich()
UsageFactory('comnet', city).enrich()
SchedulesFactory('comnet', city).enrich()
self._check_buildings(city)
for building in city.buildings:
self._check_thermal_zones(building)
for thermal_zone in building.thermal_zones:
self._check_hvac(thermal_zone)
self._check_control(thermal_zone)
self.assertIsNotNone(building.usage_zones, 'building usage zones is none')
self._check_usage_zones(building)
def test_import_hft(self):
"""
Enrich the city with the usage information from hft and verify it
"""
file = 'pluto_building.gml'
city = self._get_citygml(file)
for building in city.buildings:
building.function = GeometryHelper.pluto_to_function[building.function]
ConstructionFactory('nrel', city).enrich()
UsageFactory('hft', 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.not_detailed_source_mean_annual_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')
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')
self.assertIsNotNone(usage_zone.is_heated, 'thermal_zone heated is none')
self.assertIsNotNone(usage_zone.is_cooled, 'thermal_zone cooled is none')
def test_import_ca(self):
"""
Enrich the city with the usage information from hft and verify it
"""
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
ConstructionFactory('nrel', city).enrich()
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.not_detailed_source_mean_annual_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')