error in test_weather_factory.py

This commit is contained in:
pilar 2020-10-30 06:23:29 -04:00
parent 5c4f323e76
commit b17bab8df7
7 changed files with 8830 additions and 8774 deletions

View File

@ -5,7 +5,7 @@
<excludeFolder url="file://$MODULE_DIR$/venv" /> <excludeFolder url="file://$MODULE_DIR$/venv" />
<excludeFolder url="file://$MODULE_DIR$/venv38" /> <excludeFolder url="file://$MODULE_DIR$/venv38" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="Python 3.7 (libs)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@ class UsBaseUsageParameters:
self._city = city self._city = city
# todo: control not archetype found # todo: control not archetype found
# ToDo: this is using the german library as a temporary approach, need to use/define a library for US # ToDo: this is using the german library as a temporary approach, need to use/define a library for US
path = str(Path(__file__).parent.parent.parent.parent / 'data/usage/de_library.xml') path = str(Path(__file__).parent.parent.parent / 'data/usage/de_library.xml')
print('usage:', path) print('usage:', path)
with open(path) as xml: with open(path) as xml:
self._library = xmltodict.parse(xml.read(), force_list='zoneUsageVariant') self._library = xmltodict.parse(xml.read(), force_list='zoneUsageVariant')

View File

@ -18,10 +18,11 @@ class WeatherFactory:
self._handler = '_' + handler.lower().replace(' ', '_') self._handler = '_' + handler.lower().replace(' ', '_')
self._city = city self._city = city
self._base_path = base_path self._base_path = base_path
self._city_name = 'new_york_city'
self.factory() self.factory()
def _dat(self): def _dat(self):
DatWeatherParameters(self._city, Path(self._base_path / 'inseldb' + self._handler + '.dat')) DatWeatherParameters(self._city, self._base_path, self._city_name)
def _tmy(self): def _tmy(self):
raise Exception('Not implemented') raise Exception('Not implemented')

View File

@ -5,25 +5,27 @@ Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
""" """
import pandas as pd import pandas as pd
from pathlib import Path
class DatWeatherParameters: class DatWeatherParameters:
""" """
DatWeatherParameters class DatWeatherParameters class
""" """
def __init__(self, city, path): def __init__(self, city, path, name):
self._path = path
self._weather_values = None self._weather_values = None
self._city = city self._city = city
self._city_name = name
file_name = 'inseldb_' + self._city_name + '.dat'
self._path = Path(path / file_name)
def weather_values(self):
# TODO: catch error if file does not exist # TODO: catch error if file does not exist
if self._weather_values is None: if self._weather_values is None:
self._weather_values = pd.read_csv(self._path, sep='\s+', header=None, self._weather_values = pd.read_csv(self._path, sep='\s+', header=None,
names=['hour', 'global_horiz', 'temperature', 'diffuse', 'beam', 'empty']) names=['hour', 'global_horiz', 'temperature', 'diffuse', 'beam', 'empty'])
for building in self._city.buildings: for building in self._city.buildings:
building._hourly_external_temperature = pd.DataFrame(self._weather_values[['temperature']], columns=['inseldb']) building._hourly_external_temperature = pd.DataFrame(self._weather_values[['temperature']].to_numpy(), columns=['inseldb'])
building._hourly_global_horizontal = pd.DataFrame(self._weather_values[['global_horiz']], columns=['inseldb']) building._hourly_global_horizontal = pd.DataFrame(self._weather_values[['global_horiz']].to_numpy(), columns=['inseldb'])
building._hourly_diffuse = pd.DataFrame(self._weather_values[['diffuse']], columns=['inseldb']) building._hourly_diffuse = pd.DataFrame(self._weather_values[['diffuse']].to_numpy(), columns=['inseldb'])
building._hourly_beam = pd.DataFrame(self._weather_values[['beam']], columns=['inseldb']) building._hourly_beam = pd.DataFrame(self._weather_values[['beam']].to_numpy(), columns=['inseldb'])

View File

@ -0,0 +1,57 @@
"""
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
self._nyc_with_weather = None
self._example_path = (Path(__file__).parent.parent / 'tests_data').resolve()
def _get_citygml(self):
if self._city_gml is None:
file_path = (self._example_path / 'buildings.gml').resolve()
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):
if self._nyc_with_weather is None:
self._nyc_with_weather = self._get_citygml()
WeatherFactory('dat', self._nyc_with_weather, base_path=self._example_path)
return self._nyc_with_weather
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:
values = building.external_temperature('hour')[['inseldb']].to_numpy()
print(values[8])
self.assertEqual(values[8], [-1.4109149], 'wrong value external_temperature')
values = building.diffuse('hour')[['inseldb']].to_numpy()
print(values[8])
self.assertEqual(values[8], [40.0263214], 'wrong value diffuse')
values = building.beam('hour')[['inseldb']].to_numpy()
print(values[8])
self.assertEqual(values[8], [402.954041], 'wrong value beam')
values = building.global_horizontal('hour')[['inseldb']].to_numpy()
print(values[8])
self.assertEqual(values[8], [79.9888763], 'wrong value global horizontal')

File diff suppressed because it is too large Load Diff