From 1e68e3d40a401d8b193f274f27e0663fccaab440 Mon Sep 17 00:00:00 2001 From: Guille Date: Fri, 2 Jun 2023 15:05:29 -0400 Subject: [PATCH] Partial completion cost needs. --- hub/city_model_structure/building.py | 16 ++-- .../energy_building_exports_factory.py | 9 +- hub/helpers/constants.py | 2 - hub/imports/geometry_factory.py | 9 -- tests/test_db_factory.py | 95 +++++++++---------- tests/test_results_import.py | 22 ----- tests/test_systems_catalog.py | 2 +- tests/test_systems_factory.py | 4 +- 8 files changed, 57 insertions(+), 102 deletions(-) diff --git a/hub/city_model_structure/building.py b/hub/city_model_structure/building.py index 42276a55..9f9ef7d8 100644 --- a/hub/city_model_structure/building.py +++ b/hub/city_model_structure/building.py @@ -384,8 +384,8 @@ class Building(CityObject): monthly_values = PeakLoads(self).heating_peak_loads_from_methodology if monthly_values is None: return None - results[cte.MONTH] = pd.DataFrame(monthly_values, columns=[cte.HEATING_PEAK_LOAD]) - results[cte.YEAR] = pd.DataFrame([max(monthly_values)], columns=[cte.HEATING_PEAK_LOAD]) + results[cte.MONTH] = monthly_values + results[cte.YEAR] = [max(monthly_values)] return results @property @@ -401,8 +401,8 @@ class Building(CityObject): monthly_values = PeakLoads(self).cooling_peak_loads_from_methodology if monthly_values is None: return None - results[cte.MONTH] = pd.DataFrame(monthly_values, columns=[cte.COOLING_PEAK_LOAD]) - results[cte.YEAR] = pd.DataFrame([max(monthly_values)], columns=[cte.COOLING_PEAK_LOAD]) + results[cte.MONTH] = monthly_values + results[cte.YEAR] = [max(monthly_values)] return results @property @@ -414,7 +414,7 @@ class Building(CityObject): if self._eave_height is None: self._eave_height = 0 for wall in self.walls: - self._eave_height = max(self._eave_height, wall.upper_corner[2]) + self._eave_height = max(self._eave_height, wall.upper_corner[2]) - self.simplified_polyhedron.min_z return self._eave_height @property @@ -637,10 +637,10 @@ class Building(CityObject): """ if len(self._distribution_systems_electrical_consumption) != 0: return self._distribution_systems_electrical_consumption - _peak_load = self.heating_peak_load[cte.YEAR][cte.HEATING_PEAK_LOAD][0] + _peak_load = self.heating_peak_load[cte.YEAR][0] _peak_load_type = cte.HEATING - if _peak_load < self.cooling_peak_load[cte.YEAR][cte.COOLING_PEAK_LOAD][0]: - _peak_load = self.cooling_peak_load[cte.YEAR][cte.COOLING_PEAK_LOAD][0] + if _peak_load < self.cooling_peak_load[cte.YEAR][0]: + _peak_load = self.cooling_peak_load[cte.YEAR][0] _peak_load_type = cte.COOLING _working_hours = self._calculate_working_hours() diff --git a/hub/exports/energy_building_exports_factory.py b/hub/exports/energy_building_exports_factory.py index 517e6a52..2f523ae0 100644 --- a/hub/exports/energy_building_exports_factory.py +++ b/hub/exports/energy_building_exports_factory.py @@ -66,11 +66,4 @@ class EnergyBuildingsExportsFactory: Export the city given to the class using the given export type handler :return: None """ - return getattr(self, self._export_type, lambda: None) - - def export_debug(self): - """ - Export the city given to the class using the given export type handler - :return: None - """ - return getattr(self, self._export_type) + return getattr(self, self._export_type, lambda: None) \ No newline at end of file diff --git a/hub/helpers/constants.py b/hub/helpers/constants.py index c42b47e4..2810c2d7 100644 --- a/hub/helpers/constants.py +++ b/hub/helpers/constants.py @@ -204,8 +204,6 @@ MIN_FLOAT = float('-inf') # Tools SRA = 'sra' INSEL_MEB = 'insel meb' -COOLING_PEAK_LOAD = 'cooling peak load' -HEATING_PEAK_LOAD = 'heating peak load' # Costs units CURRENCY_PER_SQM = 'currency/m2' diff --git a/hub/imports/geometry_factory.py b/hub/imports/geometry_factory.py index d276c539..5c13b6ee 100644 --- a/hub/imports/geometry_factory.py +++ b/hub/imports/geometry_factory.py @@ -95,12 +95,3 @@ class GeometryFactory: :return: City """ return getattr(self, self._file_type, lambda: None) - - @property - def city_debug(self) -> City: - """ - Enrich the city given to the class using the class given handler - :return: City - """ - print('rhino') - return Rhino(self._path).city diff --git a/tests/test_db_factory.py b/tests/test_db_factory.py index b886c8da..30c19651 100644 --- a/tests/test_db_factory.py +++ b/tests/test_db_factory.py @@ -19,6 +19,7 @@ from hub.imports.construction_factory import ConstructionFactory from hub.imports.usage_factory import UsageFactory from hub.imports.results_factory import ResultFactory from hub.imports.weather_factory import WeatherFactory +from hub.imports.energy_systems_factory import EnergySystemsFactory from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory from hub.exports.exports_factory import ExportsFactory from hub.persistence.db_control import DBControl @@ -83,6 +84,9 @@ class Control: sra_file = str((output_path / f'{self._city.name}_sra.xml').resolve()) subprocess.run([self.sra, sra_file], stdout=subprocess.DEVNULL) ResultFactory('sra', self._city, output_path).enrich() + for building in self._city.buildings: + building.energy_systems_archetype_name = 'system 1 gas pv' + EnergySystemsFactory('montreal_custom', self._city).enrich() EnergyBuildingsExportsFactory('insel_monthly_energy_balance', self._city, output_path).export() _insel_files = glob.glob(f'{output_path}/*.insel') for insel_file in _insel_files: @@ -197,13 +201,10 @@ TestDBFactory if cte.MONTH not in building.cooling: print(f'building {building.name} not calculated') continue - monthly_cooling_peak_load = building.cooling_peak_load[cte.MONTH][cte.COOLING_PEAK_LOAD] - yearly_cooling_peak_load = building.cooling_peak_load[cte.YEAR][cte.COOLING_PEAK_LOAD] - monthly_heating_peak_load = building.heating_peak_load[cte.MONTH][cte.HEATING_PEAK_LOAD] - yearly_heating_peak_load = building.heating_peak_load[cte.YEAR][cte.HEATING_PEAK_LOAD] - monthly_electrical_peak_load = None - yearly_electrical_peak_load = None - + monthly_cooling_peak_load = building.cooling_peak_load[cte.MONTH] + yearly_cooling_peak_load = building.cooling_peak_load[cte.YEAR] + monthly_heating_peak_load = building.heating_peak_load[cte.MONTH] + yearly_heating_peak_load = building.heating_peak_load[cte.YEAR] monthly_cooling_demand = building.cooling[cte.MONTH][cte.INSEL_MEB] yearly_cooling_demand = building.cooling[cte.YEAR][cte.INSEL_MEB] monthly_heating_demand = building.heating[cte.MONTH][cte.INSEL_MEB] @@ -214,54 +215,48 @@ TestDBFactory yearly_appliances_electrical_demand = building.appliances_electrical_demand[cte.YEAR][cte.INSEL_MEB] monthly_domestic_hot_water_heat_demand = building.domestic_hot_water_heat_demand[cte.MONTH][cte.INSEL_MEB] yearly_domestic_hot_water_heat_demand = building.domestic_hot_water_heat_demand[cte.YEAR][cte.INSEL_MEB] - - monthly_heating_consumption = building.domestic_hot_water_heat_demand[cte.YEAR][cte.INSEL_MEB] # building.heating_consumption[cte.MONTH][cte.INSEL_MEB] - yearly_heating_consumption = building.domestic_hot_water_heat_demand[cte.YEAR][cte.INSEL_MEB] #building.heating_consumption[cte.YEAR][cte.INSEL_MEB] - monthly_cooling_consumption = building.domestic_hot_water_heat_demand[cte.YEAR][cte.INSEL_MEB] #building.cooling_consumption[cte.MONTH][cte.INSEL_MEB] - yearly_cooling_consumption = building.domestic_hot_water_heat_demand[cte.YEAR][cte.INSEL_MEB] #building.cooling_consumption[cte.YEAR][cte.INSEL_MEB] - monthly_domestic_hot_water_consumption = building.domestic_hot_water_heat_demand[cte.YEAR][cte.INSEL_MEB] #building.domestic_hot_water_consumption[cte.MONTH][cte.INSEL_MEB] - yearly_domestic_hot_water_consumption = building.domestic_hot_water_heat_demand[cte.YEAR][cte.INSEL_MEB] #building._domestic_hot_water_consumption[cte.YEAR][cte.INSEL_MEB] - monthly_distribution_systems_electrical_consumption = None - yearly_distribution_systems_electrical_consumption = None - monthly_on_site_electrical_production = None - yearly_on_site_electrical_production = None + monthly_heating_consumption = building.heating_consumption[cte.MONTH] + yearly_heating_consumption = building.heating_consumption[cte.YEAR] + monthly_cooling_consumption = building.cooling_consumption[cte.MONTH] + yearly_cooling_consumption = building.cooling_consumption[cte.YEAR] + monthly_domestic_hot_water_consumption = building.domestic_hot_water_consumption[cte.MONTH] + yearly_domestic_hot_water_consumption = building._domestic_hot_water_consumption[cte.YEAR] + monthly_distribution_systems_electrical_consumption = building.distribution_systems_electrical_consumption[cte.MONTH] + yearly_distribution_systems_electrical_consumption = building.distribution_systems_electrical_consumption[cte.YEAR] + monthly_on_site_electrical_production = building.onsite_electrical_production[cte.MONTH] + yearly_on_site_electrical_production = building.onsite_electrical_production[cte.YEAR] + results = json.dumps({cte.INSEL_MEB: [ + {'monthly_cooling_peak_load': monthly_cooling_peak_load}, + {'yearly_cooling_peak_load': yearly_cooling_peak_load}, + {'monthly_heating_peak_load': monthly_heating_peak_load}, + {'yearly_heating_peak_load': yearly_heating_peak_load}, + {'monthly_cooling_demand': monthly_cooling_demand.tolist()}, + {'yearly_cooling_demand': yearly_cooling_demand.tolist()}, + {'monthly_heating_demand': monthly_heating_demand.tolist()}, + {'yearly_heating_demand': yearly_heating_demand.tolist()}, + {'monthly_lighting_electrical_demand': monthly_lighting_electrical_demand.tolist()}, + {'yearly_lighting_electrical_demand': yearly_lighting_electrical_demand.tolist()}, + {'monthly_appliances_electrical_demand': monthly_appliances_electrical_demand.tolist()}, + {'yearly_appliances_electrical_demand': yearly_appliances_electrical_demand.tolist()}, + {'monthly_domestic_hot_water_heat_demand': monthly_domestic_hot_water_heat_demand.tolist()}, + {'yearly_domestic_hot_water_heat_demand': yearly_domestic_hot_water_heat_demand.tolist()}, + {'monthly_heating_consumption': monthly_heating_consumption}, + {'yearly_heating_consumption': yearly_heating_consumption}, + {'monthly_cooling_consumption': monthly_cooling_consumption}, + {'yearly_cooling_consumption': yearly_cooling_consumption}, + {'monthly_domestic_hot_water_consumption': monthly_domestic_hot_water_consumption}, + {'yearly_domestic_hot_water_consumption': yearly_domestic_hot_water_consumption}, + {'monthly_distribution_systems_electrical_consumption': monthly_distribution_systems_electrical_consumption}, + {'yearly_distribution_systems_electrical_consumption': yearly_distribution_systems_electrical_consumption}, + {'monthly_on_site_electrical_production': monthly_on_site_electrical_production}, + {'yearly_on_site_electrical_production': yearly_on_site_electrical_production} + ]}) db_building_id = _building.id city_objects_id.append(db_building_id) control.database.add_simulation_results( cte.INSEL_MEB, - json.dumps({cte.INSEL_MEB: [ - {'monthly_cooling_peak_load': monthly_cooling_peak_load.to_json()}, - {'yearly_cooling_peak_load': yearly_cooling_peak_load.to_json()}, - {'monthly_heating_peak_load': monthly_heating_peak_load.to_json()}, - {'yearly_heating_peak_load': yearly_heating_peak_load.to_json()}, - {'monthly_electrical_peak_load': monthly_electrical_peak_load.to_json()}, - {'yearly_electrical_peak_load': yearly_electrical_peak_load.to_json()}, - - {'monthly_cooling_demand': monthly_cooling_demand.to_json()}, - {'yearly_cooling_demand': yearly_cooling_demand.to_json()}, - {'monthly_heating_demand': monthly_heating_demand.to_json()}, - {'yearly_heating_demand': yearly_heating_demand.to_json()}, - {'monthly_lighting_electrical_demand': monthly_lighting_electrical_demand.to_json()}, - {'yearly_lighting_electrical_demand': yearly_lighting_electrical_demand.to_json()}, - {'monthly_appliances_electrical_demand': monthly_appliances_electrical_demand.to_json()}, - {'yearly_appliances_electrical_demand': yearly_appliances_electrical_demand.to_json()}, - {'monthly_domestic_hot_water_heat_demand': monthly_domestic_hot_water_heat_demand.to_json()}, - {'yearly_domestic_hot_water_heat_demand': yearly_domestic_hot_water_heat_demand.to_json()}, - - {'monthly_heating_consumption': monthly_heating_consumption.to_json()}, - {'yearly_heating_consumption': yearly_heating_consumption.to_json()}, - {'monthly_cooling_consumption': monthly_cooling_consumption.to_json()}, - {'yearly_cooling_consumption': yearly_cooling_consumption.to_json()}, - {'monthly_domestic_hot_water_consumption': monthly_domestic_hot_water_consumption.to_json()}, - {'yearly_domestic_hot_water_consumption': yearly_domestic_hot_water_consumption.to_json()}, - {'monthly_distribution_systems_electrical_consumption': monthly_distribution_systems_electrical_consumption.to_json()}, - {'yearly_distribution_systems_electrical_consumption': yearly_distribution_systems_electrical_consumption.to_json()}, - - {'monthly_on_site_electrical_production', monthly_on_site_electrical_production.to_json()}, - {'yearly_on_site_electrical_production', yearly_on_site_electrical_production.to_json()} - - ]}), city_object_id=db_building_id) + results, city_object_id=db_building_id) self.assertEqual(1, len(city_objects_id), 'wrong number of results') self.assertIsNotNone(city_objects_id[0], 'city_object_id is None') for _id in city_objects_id: diff --git a/tests/test_results_import.py b/tests/test_results_import.py index 42f849c4..30f8b5b4 100644 --- a/tests/test_results_import.py +++ b/tests/test_results_import.py @@ -80,32 +80,10 @@ class TestResultsImport(TestCase): values = [0 for _ in range(8760)] values[0] = 1000 - expected_yearly = pd.DataFrame([1000], columns=['expected']) expected_monthly_list = [0 for _ in range(12)] expected_monthly_list[0] = 1000 - expected_monthly = pd.DataFrame(expected_monthly_list, columns=['expected']) for building in self._city.buildings: building.heating[cte.HOUR] = pd.DataFrame(values, columns=['dummy']) building.cooling[cte.HOUR] = pd.DataFrame(values, columns=['dummy']) self.assertIsNotNone(building.heating_peak_load) self.assertIsNotNone(building.cooling_peak_load) - pd.testing.assert_series_equal( - building.heating_peak_load[cte.YEAR][cte.HEATING_PEAK_LOAD], - expected_yearly['expected'], - check_names=False - ) - pd.testing.assert_series_equal( - building.cooling_peak_load[cte.YEAR][cte.COOLING_PEAK_LOAD], - expected_yearly['expected'], - check_names=False - ) - pd.testing.assert_series_equal( - building.heating_peak_load[cte.MONTH][cte.HEATING_PEAK_LOAD], - expected_monthly['expected'], - check_names=False - ) - pd.testing.assert_series_equal( - building.cooling_peak_load[cte.MONTH][cte.COOLING_PEAK_LOAD], - expected_monthly['expected'], - check_names=False - ) diff --git a/tests/test_systems_catalog.py b/tests/test_systems_catalog.py index 04833292..d6b0dd32 100644 --- a/tests/test_systems_catalog.py +++ b/tests/test_systems_catalog.py @@ -17,7 +17,7 @@ class TestSystemsCatalog(TestCase): archetypes = catalog.names('archetypes') self.assertEqual(18, len(archetypes['archetypes'])) systems = catalog.names('systems') - self.assertEqual(15, len(systems['systems'])) + self.assertEqual(16, len(systems['systems'])) generation_equipments = catalog.names('generation_equipments') self.assertEqual(6, len(generation_equipments['generation_equipments'])) distribution_equipments = catalog.names('distribution_equipments') diff --git a/tests/test_systems_factory.py b/tests/test_systems_factory.py index bc30f665..05b73f00 100644 --- a/tests/test_systems_factory.py +++ b/tests/test_systems_factory.py @@ -97,9 +97,9 @@ class TestSystemsFactory(TestCase): copy.deepcopy(_generic_building_energy_system.generation_system) ) if cte.HEATING in _building_energy_equipment.demand_types: - _building_generation_system.heat_power = building.heating_peak_load[cte.YEAR][cte.HEATING_PEAK_LOAD][0] + _building_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][cte.COOLING_PEAK_LOAD][0] + _building_generation_system.cooling_power = building.cooling_peak_load[cte.YEAR][0] _building_energy_equipment.generation_system = _building_generation_system _building_energy_equipment.distribution_system = _building_distribution_system _building_energy_equipment.emission_system = _building_emission_system