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 logging
|
||||
import subprocess
|
||||
from typing import List, Union, Dict
|
||||
import yaml
|
||||
from string import Template
|
||||
|
@ -58,7 +59,7 @@ class HeatPumpExport:
|
|||
# Now run insel
|
||||
self._delete_existing_output_files()
|
||||
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
|
||||
self._write_insel_output_headers()
|
||||
# User output
|
||||
|
|
|
@ -37,19 +37,19 @@ class TestCityMerge(TestCase):
|
|||
full_city = GeometryFactory('geojson', file_path, height_field='citygml_me').city
|
||||
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)
|
||||
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:
|
||||
if int(building.name) % 2 == 0:
|
||||
par_city.add_city_object(copy.deepcopy(building))
|
||||
even_city.add_city_object(copy.deepcopy(building))
|
||||
else:
|
||||
odd_city.add_city_object(copy.deepcopy(building))
|
||||
self.assertEqual(8, len(odd_city.buildings), 'Wrong number of odd buildings')
|
||||
self.assertEqual(9, len(par_city.buildings), 'Wrong number of par buildings')
|
||||
merged_city = odd_city.merge(par_city)
|
||||
self.assertEqual(9, len(even_city.buildings), 'Wrong number of par buildings')
|
||||
merged_city = odd_city.merge(even_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')
|
||||
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')
|
||||
|
||||
def test_merge_with_radiation(self):
|
||||
|
@ -57,42 +57,50 @@ class TestCityMerge(TestCase):
|
|||
file_path = Path('./tests_data/test.geojson').resolve()
|
||||
output_path = Path('./tests_outputs/')
|
||||
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:
|
||||
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()
|
||||
sra_file = str((output_path / f'{full_city.name}_sra.xml').resolve())
|
||||
subprocess.run([sra, sra_file], stdout=subprocess.DEVNULL)
|
||||
ResultFactory('sra', full_city, output_path).enrich()
|
||||
self.assertEqual(17, len(full_city.buildings), 'Wrong number of buildings')
|
||||
merged_city = full_city.merge(par_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)
|
||||
merged_city = full_city.merge(even_city)
|
||||
|
||||
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:
|
||||
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
|
||||
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(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
|
||||
for building in merged_city.buildings:
|
||||
for surface in building.surfaces:
|
||||
|
|
Loading…
Reference in New Issue
Block a user