From f2d78c381ed7edaec173b004d9ab0e0409479705 Mon Sep 17 00:00:00 2001 From: Saeed Ranjbar Date: Tue, 10 Oct 2023 11:38:41 -0400 Subject: [PATCH] finished the test --- hub/city_model_structure/building.py | 14 ++++++++------ tests/test_systems_factory.py | 26 +++++++++++++------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/hub/city_model_structure/building.py b/hub/city_model_structure/building.py index cbbda322..8c7fbae7 100644 --- a/hub/city_model_structure/building.py +++ b/hub/city_model_structure/building.py @@ -759,21 +759,23 @@ class Building(CityObject): if demand_type.lower() == consumption_type.lower(): if consumption_type in (cte.HEATING, cte.DOMESTIC_HOT_WATER): for generation_system in energy_system_generation_systems: - coefficient_of_performance = generation_system.generic_generation_system[0].heat_efficiency + generic_gen = generation_system.generic_generation_system + print(generation_system) + coefficient_of_performance = generation_system.generic_generation_system.heat_efficiency elif consumption_type == cte.COOLING: for generation_system in energy_system_generation_systems: - coefficient_of_performance = generation_system.generic_generation_system[0].cooling_efficiency + coefficient_of_performance = generation_system.generic_generation_system.cooling_efficiency elif consumption_type == cte.ELECTRICITY: for generation_system in energy_system_generation_systems: coefficient_of_performance = \ - generation_system.generic_generation_system[0].electricity_efficiency + generation_system.generic_generation_system.electricity_efficiency if coefficient_of_performance == 0: values = [0] * len(demand) final_energy_consumed = values else: final_energy_consumed = [] for demand_value in demand: - final_energy_consumed.append(demand_value / coefficient_of_performance) + final_energy_consumed.append(demand_value / float(coefficient_of_performance)) return final_energy_consumed @property @@ -799,8 +801,8 @@ class Building(CityObject): for energy_system in self.energy_systems: energy_system_generation_systems = energy_system.generation_systems for generation_system in energy_system_generation_systems: - if generation_system.generic_generation_system[0].type == cte.PHOTOVOLTAIC: - _efficiency = generation_system.generic_generation_system[0].electricity_efficiency + if generation_system.generic_generation_system.type == cte.PHOTOVOLTAIC: + _efficiency = generation_system.generic_generation_system.electricity_efficiency self._onsite_electrical_production = {} for _key in self.roofs[0].global_irradiance.keys(): _results = [0 for _ in range(0, len(self.roofs[0].global_irradiance[_key]))] diff --git a/tests/test_systems_factory.py b/tests/test_systems_factory.py index f2e3a7b4..69cedd55 100644 --- a/tests/test_systems_factory.py +++ b/tests/test_systems_factory.py @@ -26,10 +26,12 @@ from hub.city_model_structure.energy_systems.distribution_system import Distribu from hub.city_model_structure.energy_systems.emission_system import EmissionSystem from hub.city_model_structure.energy_systems.thermal_storage_system import ThermalStorageSystem + class TestSystemsFactory(TestCase): """ TestSystemsFactory TestCase """ + def setUp(self) -> None: """ Test setup @@ -163,22 +165,20 @@ class TestSystemsFactory(TestCase): _building_generation_systems = _generic_building_energy_system.generation_systems _generic_system_generation_systems = [] for _building_generation_system in _building_generation_systems: - _building_generation_system = GenerationSystem() - _building_generation_system.generic_generation_system = ( - copy.deepcopy(_generic_building_energy_system.generation_systems) + _generation_system = GenerationSystem() + _generation_system.generic_generation_system = ( + copy.deepcopy(_building_generation_system) ) - _building_storage_system = ThermalStorageSystem() - _building_storage_system.generic_storage_system = \ - copy.deepcopy(_generic_building_energy_system.energy_storage_systems) - if cte.HEATING in _building_energy_equipment.demand_types: - _building_generation_system.heat_power = building.heating_peak_load[cte.YEAR][0] + _generation_system.heat_power = building.heating_peak_load[cte.YEAR][0] if cte.COOLING in _building_energy_equipment.demand_types: - _building_generation_system.cooling_power = building.cooling_peak_load[cte.YEAR][0] - _generic_system_generation_systems.append(_building_generation_system) + _generation_system.cooling_power = building.cooling_peak_load[cte.YEAR][0] + _generic_system_generation_systems.append(_generation_system) print(_generic_system_generation_systems) _building_energy_equipment.generation_systems = _generic_system_generation_systems - + _building_storage_system = ThermalStorageSystem() + _building_storage_system.generic_storage_system = \ + copy.deepcopy(_generic_building_energy_system.energy_storage_systems) _building_energy_systems.append(_building_energy_equipment) building.energy_systems = _building_energy_systems @@ -188,6 +188,6 @@ class TestSystemsFactory(TestCase): print(building.domestic_hot_water_consumption[cte.YEAR][0]) print(building.onsite_electrical_production[cte.YEAR][0]) self.assertLess(0, building.heating_consumption[cte.YEAR][0]) - self.assertLess(0, building.cooling_consumption[cte.YEAR][0]) + self.assertEqual(0, building.cooling_consumption[cte.YEAR][0]) self.assertLess(0, building.domestic_hot_water_consumption[cte.YEAR][0]) - self.assertLess(0, building.onsite_electrical_production[cte.YEAR][0]) \ No newline at end of file + self.assertLess(0, building.onsite_electrical_production[cte.YEAR][0])