2023-05-04 10:39:23 -04:00
|
|
|
"""
|
|
|
|
TestSystemsFactory
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2023 Concordia CERC group
|
|
|
|
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
|
|
"""
|
|
|
|
|
2023-05-12 09:27:29 -04:00
|
|
|
import subprocess
|
2023-05-04 10:39:23 -04:00
|
|
|
from pathlib import Path
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2023-05-12 09:27:29 -04:00
|
|
|
import hub.helpers.constants as cte
|
|
|
|
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
|
|
|
from hub.exports.exports_factory import ExportsFactory
|
|
|
|
from hub.helpers.dictionaries import Dictionaries
|
2023-05-04 10:39:23 -04:00
|
|
|
from hub.imports.construction_factory import ConstructionFactory
|
2023-05-12 09:27:29 -04:00
|
|
|
from hub.imports.geometry_factory import GeometryFactory
|
|
|
|
from hub.imports.results_factory import ResultFactory
|
2023-05-04 10:39:23 -04:00
|
|
|
from hub.imports.usage_factory import UsageFactory
|
|
|
|
from hub.imports.energy_systems_factory import EnergySystemsFactory
|
|
|
|
|
|
|
|
|
|
|
|
class TestSystemsFactory(TestCase):
|
|
|
|
"""
|
|
|
|
TestSystemsFactory TestCase
|
|
|
|
"""
|
|
|
|
def setUp(self) -> None:
|
|
|
|
"""
|
2023-05-12 09:27:29 -04:00
|
|
|
Test setup
|
|
|
|
:return: None
|
2023-05-04 10:39:23 -04:00
|
|
|
"""
|
|
|
|
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
|
2023-05-12 09:27:29 -04:00
|
|
|
self._gml_path = (self._example_path / 'FZK_Haus_LoD_2.gml').resolve()
|
|
|
|
self._output_path = (Path(__file__).parent / 'tests_outputs').resolve()
|
|
|
|
self._city = GeometryFactory('citygml',
|
|
|
|
self._gml_path,
|
|
|
|
function_to_hub=Dictionaries().alkis_function_to_hub_function).city
|
2023-05-04 10:39:23 -04:00
|
|
|
|
|
|
|
def test_montreal_custom_system_factory(self):
|
|
|
|
"""
|
|
|
|
Enrich the city with the construction information and verify it
|
|
|
|
"""
|
2023-05-12 09:27:29 -04:00
|
|
|
for building in self._city.buildings:
|
2023-05-04 10:39:23 -04:00
|
|
|
building.energy_systems_archetype_name = 'system 1 gas'
|
|
|
|
|
2023-05-12 09:27:29 -04:00
|
|
|
EnergySystemsFactory('montreal_custom', self._city).enrich()
|
|
|
|
for building in self._city.buildings:
|
|
|
|
self.assertEqual(2, len(building.energy_systems[0].demand_types))
|
|
|
|
self.assertEqual(1, len(building.energy_systems[1].demand_types))
|
2023-05-04 10:39:23 -04:00
|
|
|
|
|
|
|
def test_montreal_custom_system_results(self):
|
|
|
|
"""
|
|
|
|
Enrich the city with the construction information and verify it
|
|
|
|
"""
|
2023-05-12 09:27:29 -04:00
|
|
|
ConstructionFactory('nrcan', self._city).enrich()
|
|
|
|
UsageFactory('nrcan', self._city).enrich()
|
|
|
|
weather_file = (self._example_path / 'CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw').resolve()
|
|
|
|
ExportsFactory('sra', self._city, self._output_path, weather_file=weather_file, weather_format='epw').export()
|
|
|
|
sra_path = (self._output_path / f'{self._city.name}_sra.xml').resolve()
|
|
|
|
subprocess.run(['sra', str(sra_path)])
|
|
|
|
ResultFactory('sra', self._city, self._output_path).enrich()
|
|
|
|
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', self._city, self._output_path).export()
|
|
|
|
for building in self._city.buildings:
|
|
|
|
insel_path = (self._output_path / f'{building.name}.insel')
|
|
|
|
subprocess.run(['insel', str(insel_path)])
|
|
|
|
ResultFactory('insel_monthly_energy_balance', self._city, self._output_path).enrich()
|
|
|
|
|
|
|
|
for building in self._city.buildings:
|
|
|
|
building.energy_systems_archetype_name = 'system 1 gas'
|
|
|
|
EnergySystemsFactory('montreal_custom', self._city).enrich()
|
|
|
|
|
|
|
|
for building in self._city.buildings:
|
|
|
|
self.assertLess(0, building.heating_consumption[cte.YEAR][0])
|
|
|
|
self.assertLess(0, building.cooling_consumption[cte.YEAR][0])
|
|
|
|
self.assertLess(0, building.domestic_hot_water_consumption[cte.YEAR][0])
|