From cfb76a9ebdfdd14d2622572e6505aea71dbfe9e6 Mon Sep 17 00:00:00 2001 From: guille Date: Mon, 28 Aug 2023 18:34:10 +0200 Subject: [PATCH] partial correction for persistence IMPORTANT: This version neec top be checked for meb import as seems that the cooling and heating demand aren't imported properly. --- hub/persistence/models/city_object.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/hub/persistence/models/city_object.py b/hub/persistence/models/city_object.py index 5face637..48715b61 100644 --- a/hub/persistence/models/city_object.py +++ b/hub/persistence/models/city_object.py @@ -6,6 +6,7 @@ Project Coder Guille Gutierrez Guillermo.GutierrezMorote@concordia.ca """ import datetime +import logging from sqlalchemy import Column, Integer, String, Sequence, ForeignKey, Float from sqlalchemy import DateTime @@ -51,19 +52,27 @@ class CityObject(Models): self.roof_area = sum(roof.solid_polygon.area for roof in building.roofs) self.total_pv_area = sum(roof.solid_polygon.area * roof.solar_collectors_area_reduction_factor for roof in building.roofs) storeys = building.storeys_above_ground - if storeys is None: - storeys = building.max_height / building.average_storey_height - self.total_heating_area = building.floor_area * storeys wall_area = 0 + window_ratio = 0 + try: + if storeys is None: + storeys = building.max_height / building.average_storey_height + for internal_zone in building.internal_zones: + for thermal_zone in internal_zone.thermal_zones_from_internal_zones: + for thermal_boundary in thermal_zone.thermal_boundaries: + window_ratio = thermal_boundary.window_ratio + break + except TypeError: + storeys = 0 + logging.warning( + 'building %s has no storey height so heating area, storeys and window ratio cannot be calculated', + self.name + ) + self.total_heating_area = building.floor_area * storeys + for wall in building.walls: wall_area += wall.solid_polygon.area self.wall_area = wall_area - window_ratio = 0 - for internal_zone in building.internal_zones: - for thermal_zone in internal_zone.thermal_zones_from_internal_zones: - for thermal_boundary in thermal_zone.thermal_boundaries: - window_ratio = thermal_boundary.window_ratio - break self.windows_area = wall_area * window_ratio system_name = building.energy_systems_archetype_name if system_name is None: