From a06eced6f4dc3fe0bde4db38c129be8089a24152 Mon Sep 17 00:00:00 2001 From: Peter Yefi Date: Wed, 22 Feb 2023 20:17:04 -0500 Subject: [PATCH] Modified city merge function in city --- hub/city_model_structure/city.py | 20 +++++++++++++++++++- hub/imports/db_factory.py | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/hub/city_model_structure/city.py b/hub/city_model_structure/city.py index 03764570..7934c924 100644 --- a/hub/city_model_structure/city.py +++ b/hub/city_model_structure/city.py @@ -29,6 +29,7 @@ from hub.helpers.geometry_helper import GeometryHelper from hub.helpers.location import Location from hub.city_model_structure.energy_system import EnergySystem from hub.city_model_structure.lca_material import LcaMaterial +import pandas as pd class City: @@ -447,8 +448,25 @@ class City: def merge(self, city) -> City: _merge_city = self.copy + selected_city_object = None + # set initial minimum radiation to a higher number + min_radiation = 1000000 for city_object in city.city_objects: - _merge_city.add_city_object(city_object) + if city_object.type == 'building': + building_radiation = 0 + for surface in city_object.surfaces: + radiation = surface.global_irradiance + if "yearly" in radiation: + building_radiation += radiation["yearly"].iloc[0] + elif "monthly" in radiation and "yearly" not in radiation: + radiation["yearly"] = pd.DataFrame({radiation["monthly"].sum()}) + building_radiation += radiation["yearly"].iloc[0] + if building_radiation < min_radiation: + min_radiation = building_radiation + selected_city_object = city_object + # merge the city object with the minimum radiation + if selected_city_object is not None: + _merge_city.add_city_object(selected_city_object) return _merge_city @property diff --git a/hub/imports/db_factory.py b/hub/imports/db_factory.py index 596aa225..67891f30 100644 --- a/hub/imports/db_factory.py +++ b/hub/imports/db_factory.py @@ -51,4 +51,4 @@ class DBFactory: :param city_id: city id or None :param city_object_id: city object id or None """ - self._simulation_results.insert(name, values,city_id, city_object_id) + self._simulation_results.insert(name, values, city_id, city_object_id)