improve unit tests and bug fix
This commit is contained in:
parent
46ed69ef6e
commit
af93dbb3a1
|
@ -6,6 +6,7 @@ Project Coder Peter Yefi peteryefi@gmail.com
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import subprocess
|
||||||
from typing import List, Union, Dict
|
from typing import List, Union, Dict
|
||||||
import yaml
|
import yaml
|
||||||
from string import Template
|
from string import Template
|
||||||
|
@ -58,7 +59,7 @@ class HeatPumpExport:
|
||||||
# Now run insel
|
# Now run insel
|
||||||
self._delete_existing_output_files()
|
self._delete_existing_output_files()
|
||||||
logging.info(f'Running Insel with user input: {user_input} and coefficients {capacity_coefficient}')
|
logging.info(f'Running Insel with user input: {user_input} and coefficients {capacity_coefficient}')
|
||||||
os.system('insel {}'.format(insel_file))
|
subprocess.run(['insel', str(insel_file)])
|
||||||
# Writer headers to csv output files generated by insel
|
# Writer headers to csv output files generated by insel
|
||||||
self._write_insel_output_headers()
|
self._write_insel_output_headers()
|
||||||
# User output
|
# User output
|
||||||
|
|
|
@ -37,19 +37,19 @@ class TestCityMerge(TestCase):
|
||||||
full_city = GeometryFactory('geojson', file_path, height_field='citygml_me').city
|
full_city = GeometryFactory('geojson', file_path, height_field='citygml_me').city
|
||||||
self.assertEqual(17, len(full_city.buildings), 'Wrong number of buildings')
|
self.assertEqual(17, len(full_city.buildings), 'Wrong number of buildings')
|
||||||
odd_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
odd_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
||||||
par_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
even_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
||||||
for building in full_city.buildings:
|
for building in full_city.buildings:
|
||||||
if int(building.name) % 2 == 0:
|
if int(building.name) % 2 == 0:
|
||||||
par_city.add_city_object(copy.deepcopy(building))
|
even_city.add_city_object(copy.deepcopy(building))
|
||||||
else:
|
else:
|
||||||
odd_city.add_city_object(copy.deepcopy(building))
|
odd_city.add_city_object(copy.deepcopy(building))
|
||||||
self.assertEqual(8, len(odd_city.buildings), 'Wrong number of odd buildings')
|
self.assertEqual(8, len(odd_city.buildings), 'Wrong number of odd buildings')
|
||||||
self.assertEqual(9, len(par_city.buildings), 'Wrong number of par buildings')
|
self.assertEqual(9, len(even_city.buildings), 'Wrong number of par buildings')
|
||||||
merged_city = odd_city.merge(par_city)
|
merged_city = odd_city.merge(even_city)
|
||||||
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
||||||
merged_city = par_city.merge(odd_city)
|
merged_city = even_city.merge(odd_city)
|
||||||
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
||||||
merged_city = full_city.merge(odd_city).merge(par_city)
|
merged_city = full_city.merge(odd_city).merge(even_city)
|
||||||
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
||||||
|
|
||||||
def test_merge_with_radiation(self):
|
def test_merge_with_radiation(self):
|
||||||
|
@ -57,42 +57,50 @@ class TestCityMerge(TestCase):
|
||||||
file_path = Path('./tests_data/test.geojson').resolve()
|
file_path = Path('./tests_data/test.geojson').resolve()
|
||||||
output_path = Path('./tests_outputs/')
|
output_path = Path('./tests_outputs/')
|
||||||
full_city = GeometryFactory('geojson', file_path, height_field='citygml_me').city
|
full_city = GeometryFactory('geojson', file_path, height_field='citygml_me').city
|
||||||
par_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
even_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
||||||
for building in full_city.buildings:
|
for building in full_city.buildings:
|
||||||
if int(building.name) % 2 == 0:
|
if int(building.name) % 2 == 0:
|
||||||
par_city.add_city_object(copy.deepcopy(building))
|
even_city.add_city_object(copy.deepcopy(building))
|
||||||
ExportsFactory('sra', full_city, output_path).export()
|
ExportsFactory('sra', full_city, output_path).export()
|
||||||
sra_file = str((output_path / f'{full_city.name}_sra.xml').resolve())
|
sra_file = str((output_path / f'{full_city.name}_sra.xml').resolve())
|
||||||
subprocess.run([sra, sra_file], stdout=subprocess.DEVNULL)
|
subprocess.run([sra, sra_file], stdout=subprocess.DEVNULL)
|
||||||
ResultFactory('sra', full_city, output_path).enrich()
|
ResultFactory('sra', full_city, output_path).enrich()
|
||||||
self.assertEqual(17, len(full_city.buildings), 'Wrong number of buildings')
|
self.assertEqual(17, len(full_city.buildings), 'Wrong number of buildings')
|
||||||
merged_city = full_city.merge(par_city)
|
merged_city = full_city.merge(even_city)
|
||||||
merged_city_building_total_radiation = 0
|
|
||||||
for building in merged_city.buildings:
|
|
||||||
for surface in building.surfaces:
|
|
||||||
if surface.global_irradiance:
|
|
||||||
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
|
||||||
self.assertEqual(438405954, merged_city_building_total_radiation)
|
|
||||||
merged_city = par_city.merge(full_city)
|
|
||||||
merged_city_building_total_radiation = 0
|
|
||||||
for building in merged_city.buildings:
|
|
||||||
for surface in building.surfaces:
|
|
||||||
if surface.global_irradiance:
|
|
||||||
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
|
||||||
self.assertEqual(438405954, merged_city_building_total_radiation)
|
|
||||||
|
|
||||||
for building in par_city.buildings:
|
full_city_building_total_radiation = 0
|
||||||
|
for building in merged_city.buildings:
|
||||||
|
for surface in building.surfaces:
|
||||||
|
if surface.global_irradiance:
|
||||||
|
full_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
||||||
|
|
||||||
|
merged_city_building_total_radiation = 0
|
||||||
|
for building in merged_city.buildings:
|
||||||
|
for surface in building.surfaces:
|
||||||
|
if surface.global_irradiance:
|
||||||
|
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
||||||
|
self.assertEqual(full_city_building_total_radiation, merged_city_building_total_radiation)
|
||||||
|
|
||||||
|
merged_city = even_city.merge(full_city)
|
||||||
|
merged_city_building_total_radiation = 0
|
||||||
|
for building in merged_city.buildings:
|
||||||
|
for surface in building.surfaces:
|
||||||
|
if surface.global_irradiance:
|
||||||
|
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
||||||
|
self.assertEqual(full_city_building_total_radiation, merged_city_building_total_radiation)
|
||||||
|
|
||||||
|
for building in even_city.buildings:
|
||||||
for surface in building.surfaces:
|
for surface in building.surfaces:
|
||||||
surface.global_irradiance[cte.YEAR] = pd.DataFrame([3], columns=['sra_mockup_value'])
|
surface.global_irradiance[cte.YEAR] = pd.DataFrame([3], columns=['sra_mockup_value'])
|
||||||
|
|
||||||
merged_city = full_city.merge(par_city)
|
merged_city = full_city.merge(even_city)
|
||||||
merged_city_building_total_radiation = 0
|
merged_city_building_total_radiation = 0
|
||||||
for building in merged_city.buildings:
|
for building in merged_city.buildings:
|
||||||
for surface in building.surfaces:
|
for surface in building.surfaces:
|
||||||
if surface.global_irradiance:
|
if surface.global_irradiance:
|
||||||
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR].iloc[0, 0]
|
||||||
self.assertEqual(189336013, merged_city_building_total_radiation)
|
self.assertEqual(189336013, merged_city_building_total_radiation)
|
||||||
merged_city = par_city.merge(full_city)
|
merged_city = even_city.merge(full_city)
|
||||||
merged_city_building_total_radiation = 0
|
merged_city_building_total_radiation = 0
|
||||||
for building in merged_city.buildings:
|
for building in merged_city.buildings:
|
||||||
for surface in building.surfaces:
|
for surface in building.surfaces:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user