2020-10-30 06:23:29 -04:00
|
|
|
"""
|
|
|
|
TestWeatherFactory test and validate the city model structure weather 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 factories.geometry_factory import GeometryFactory
|
|
|
|
from factories.weather_factory import WeatherFactory
|
|
|
|
|
|
|
|
|
|
|
|
class TestWeatherFactory(TestCase):
|
|
|
|
"""
|
|
|
|
TestWeatherFactory TestCase
|
|
|
|
"""
|
|
|
|
def setUp(self) -> None:
|
|
|
|
"""
|
|
|
|
Configure test environment
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
self._city_gml = None
|
2021-01-11 17:11:50 -05:00
|
|
|
self._city_with_weather = None
|
|
|
|
self._city_name = 'new_york_city'
|
2020-10-30 06:23:29 -04:00
|
|
|
self._example_path = (Path(__file__).parent.parent / 'tests_data').resolve()
|
|
|
|
|
2021-01-11 17:11:50 -05:00
|
|
|
def _get_citygml(self, file_path):
|
2020-10-30 06:23:29 -04: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_weather(self):
|
2021-01-11 17:11:50 -05:00
|
|
|
if self._city_with_weather is None:
|
|
|
|
file_path = (Path(__file__).parent.parent / 'tests_data' / '20buildings.gml').resolve()
|
|
|
|
self._city_with_weather = self._get_citygml(file_path)
|
|
|
|
WeatherFactory('dat', self._city_with_weather, city_name=self._city_name, base_path=self._example_path)
|
|
|
|
return self._city_with_weather
|
2020-10-30 06:23:29 -04:00
|
|
|
|
|
|
|
def test_city_with_weather(self):
|
|
|
|
"""
|
|
|
|
Enrich the city with the weather information and verify it
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
city = self._get_city_with_weather()
|
|
|
|
for building in city.buildings:
|
2020-10-30 16:01:12 -04:00
|
|
|
values = building.external_temperature['hour'][['inseldb']]
|
|
|
|
self.assertFalse(values.empty, 'wrong value external_temperature')
|
|
|
|
values = building.global_horizontal['hour'][['inseldb']]
|
|
|
|
self.assertFalse(values.empty, 'wrong value global horizontal')
|
|
|
|
values = building.diffuse['hour'][['inseldb']]
|
|
|
|
self.assertFalse(values.empty, 'wrong value diffuse')
|
|
|
|
values = building.beam['hour'][['inseldb']]
|
|
|
|
self.assertFalse(values.empty, 'wrong value beam')
|
2021-01-11 17:11:50 -05:00
|
|
|
|
|
|
|
def test_weather_xls(self):
|
|
|
|
file_path = (Path(__file__).parent.parent / 'tests_data' / 'iso_52016_1_2017_lod2.gml').resolve()
|
|
|
|
city_with_weather = self._get_citygml(file_path)
|
|
|
|
WeatherFactory('xls', city_with_weather, city_name=self._city_name, base_path=self._example_path)
|
|
|
|
for building in city_with_weather.buildings:
|
|
|
|
values = building.external_temperature['hour'][['iso52016']]
|
|
|
|
self.assertFalse(values.empty, 'wrong value external_temperature')
|
|
|
|
values = building.global_horizontal['hour'][['iso52016']]
|
|
|
|
self.assertFalse(values.empty, 'wrong value global horizontal')
|