summer_course_2024/tests/test_usage_factory.py

75 lines
3.1 KiB
Python
Raw Normal View History

2020-11-06 05:40:17 -05:00
"""
TestUsageFactory test and validate the city model structure usage parameters
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
"""
from pathlib import Path
from unittest import TestCase
from imports.geometry_factory import GeometryFactory
from imports.usage_factory import UsageFactory
2020-11-06 05:40:17 -05:00
class TestUsageFactory(TestCase):
"""
TestUsageFactory TestCase
"""
def setUp(self) -> None:
"""
Configure test environment
:return:
"""
self._city_gml = None
self._nyc_with_usage = None
self._example_path = (Path(__file__).parent.parent / 'tests_data').resolve()
2021-01-07 18:53:26 -05:00
def _get_citygml(self, file_path):
2020-11-06 05:40:17 -05:00
if self._city_gml is None:
self._city_gml = GeometryFactory('citygml', file_path).city
self.assertIsNotNone(self._city_gml, 'city is none')
return self._city_gml
def _get_city_with_usage(self):
if self._nyc_with_usage is None:
2021-01-07 18:53:26 -05:00
file_path = (self._example_path / '20buildings.gml').resolve()
self._nyc_with_usage = self._get_citygml(file_path)
2020-11-06 05:40:17 -05:00
UsageFactory('us_new_york', self._nyc_with_usage)
return self._nyc_with_usage
def test_city_with_usage(self):
"""
Enrich the city with the usage information and verify it
:return: None
"""
city = self._get_city_with_usage()
for building in city.buildings:
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')
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')
# todo: missing occupancy, schedules and heating schedule
2021-01-06 16:42:38 -05:00
def test_hft_interface(self):
2021-01-07 18:53:26 -05:00
file_path = (self._example_path / 'lod2_buildings.gml').resolve()
city = self._get_citygml(file_path)
2021-01-06 16:42:38 -05:00
# reduced library
UsageFactory('ca', city)
2021-01-07 18:53:26 -05:00
for building in city.buildings:
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')