Add retrieve result test and correct lock in sqlalchemy

This commit is contained in:
Guille Gutierrez 2023-08-09 16:12:10 -04:00
parent deb04cbe2d
commit 30908eda6d
4 changed files with 37 additions and 51 deletions

View File

@ -440,8 +440,7 @@ class Building(CityObject):
""" """
results = {} results = {}
if cte.HOUR in self.heating_demand: if cte.HOUR in self.heating_demand:
monthly_values = PeakLoads().\ monthly_values = PeakLoads().peak_loads_from_hourly(self.heating_demand[cte.HOUR])
peak_loads_from_hourly(self.heating_demand[cte.HOUR])
else: else:
monthly_values = PeakLoads(self).heating_peak_loads_from_methodology monthly_values = PeakLoads(self).heating_peak_loads_from_methodology
if monthly_values is None: if monthly_values is None:

View File

@ -33,9 +33,7 @@ class ThermalControl:
def _minimum_value(schedules): def _minimum_value(schedules):
minimum = 1000 minimum = 1000
for schedule in schedules: for schedule in schedules:
for value in schedule.values: minimum = min(minimum, min(schedule.values))
if value < minimum:
minimum = value
return minimum return minimum
@property @property

View File

@ -63,11 +63,10 @@ class LoadsCalculation:
:return: int :return: int
""" """
heating_load_transmitted = 0 heating_load_transmitted = 0
for internal_zone in self._building.internal_zones: for thermal_zone in self._building.thermal_zones_from_internal_zones:
for thermal_zone in internal_zone.thermal_zones_from_internal_zones: internal_temperature = thermal_zone.thermal_control.mean_heating_set_point
internal_temperature = thermal_zone.thermal_control.mean_heating_set_point heating_load_transmitted += self._get_load_transmitted(thermal_zone, internal_temperature, ambient_temperature,
heating_load_transmitted += self._get_load_transmitted(thermal_zone, internal_temperature, ambient_temperature, ground_temperature)
ground_temperature)
return heating_load_transmitted return heating_load_transmitted
def get_cooling_transmitted_load(self, ambient_temperature, ground_temperature): def get_cooling_transmitted_load(self, ambient_temperature, ground_temperature):
@ -76,11 +75,10 @@ class LoadsCalculation:
:return: int :return: int
""" """
cooling_load_transmitted = 0 cooling_load_transmitted = 0
for internal_zone in self._building.internal_zones: for thermal_zone in self._building.thermal_zones_from_internal_zones:
for thermal_zone in internal_zone.thermal_zones_from_internal_zones: internal_temperature = thermal_zone.thermal_control.mean_cooling_set_point
internal_temperature = thermal_zone.thermal_control.mean_cooling_set_point cooling_load_transmitted += self._get_load_transmitted(thermal_zone, internal_temperature, ambient_temperature,
cooling_load_transmitted += self._get_load_transmitted(thermal_zone, internal_temperature, ambient_temperature, ground_temperature)
ground_temperature)
return cooling_load_transmitted return cooling_load_transmitted
def get_heating_ventilation_load_sensible(self, ambient_temperature): def get_heating_ventilation_load_sensible(self, ambient_temperature):
@ -89,10 +87,9 @@ class LoadsCalculation:
:return: int :return: int
""" """
heating_ventilation_load = 0 heating_ventilation_load = 0
for internal_zone in self._building.internal_zones: for thermal_zone in self._building.thermal_zones_from_internal_zones:
for thermal_zone in internal_zone.thermal_zones_from_internal_zones: internal_temperature = thermal_zone.thermal_control.mean_heating_set_point
internal_temperature = thermal_zone.thermal_control.mean_heating_set_point heating_ventilation_load += self._get_load_ventilation(thermal_zone, internal_temperature, ambient_temperature)
heating_ventilation_load += self._get_load_ventilation(thermal_zone, internal_temperature, ambient_temperature)
return heating_ventilation_load return heating_ventilation_load
def get_cooling_ventilation_load_sensible(self, ambient_temperature): def get_cooling_ventilation_load_sensible(self, ambient_temperature):
@ -101,10 +98,9 @@ class LoadsCalculation:
:return: int :return: int
""" """
cooling_ventilation_load = 0 cooling_ventilation_load = 0
for internal_zone in self._building.internal_zones: for thermal_zone in self._building.thermal_zones_from_internal_zones:
for thermal_zone in internal_zone.thermal_zones_from_internal_zones: internal_temperature = thermal_zone.thermal_control.mean_cooling_set_point
internal_temperature = thermal_zone.thermal_control.mean_cooling_set_point cooling_ventilation_load += self._get_load_ventilation(thermal_zone, internal_temperature, ambient_temperature)
cooling_ventilation_load += self._get_load_ventilation(thermal_zone, internal_temperature, ambient_temperature)
return cooling_ventilation_load return cooling_ventilation_load
def get_internal_load_sensible(self): def get_internal_load_sensible(self):
@ -115,19 +111,18 @@ class LoadsCalculation:
cooling_load_occupancy_sensible = 0 cooling_load_occupancy_sensible = 0
cooling_load_lighting = 0 cooling_load_lighting = 0
cooling_load_equipment_sensible = 0 cooling_load_equipment_sensible = 0
for internal_zone in self._building.internal_zones: for thermal_zone in self._building.thermal_zones_from_internal_zones:
for thermal_zone in internal_zone.thermal_zones_from_internal_zones: cooling_load_occupancy_sensible += (thermal_zone.occupancy.sensible_convective_internal_gain
cooling_load_occupancy_sensible += (thermal_zone.occupancy.sensible_convective_internal_gain + thermal_zone.occupancy.sensible_radiative_internal_gain) \
+ thermal_zone.occupancy.sensible_radiative_internal_gain) \ * thermal_zone.footprint_area
* thermal_zone.footprint_area cooling_load_lighting += (
cooling_load_lighting += ( thermal_zone.lighting.density * thermal_zone.lighting.convective_fraction + thermal_zone.lighting.density *
thermal_zone.lighting.density * thermal_zone.lighting.convective_fraction + thermal_zone.lighting.density * thermal_zone.lighting.radiative_fraction
thermal_zone.lighting.radiative_fraction ) * thermal_zone.footprint_area
) * thermal_zone.footprint_area cooling_load_equipment_sensible += (
cooling_load_equipment_sensible += ( thermal_zone.appliances.density * thermal_zone.appliances.convective_fraction +
thermal_zone.appliances.density * thermal_zone.appliances.convective_fraction + thermal_zone.appliances.density * thermal_zone.appliances.radiative_fraction
thermal_zone.appliances.density * thermal_zone.appliances.radiative_fraction ) * thermal_zone.footprint_area
) * thermal_zone.footprint_area
internal_load = cooling_load_occupancy_sensible + cooling_load_lighting + cooling_load_equipment_sensible internal_load = cooling_load_occupancy_sensible + cooling_load_lighting + cooling_load_equipment_sensible
return internal_load return internal_load
@ -137,12 +132,11 @@ class LoadsCalculation:
:return: int :return: int
""" """
cooling_load_radiation = 0 cooling_load_radiation = 0
for internal_zone in self._building.internal_zones: for thermal_zone in self._building.thermal_zones_from_internal_zones:
for thermal_zone in internal_zone.thermal_zones_from_internal_zones: for thermal_boundary in thermal_zone.thermal_boundaries:
for thermal_boundary in thermal_zone.thermal_boundaries: for thermal_opening in thermal_boundary.thermal_openings:
for thermal_opening in thermal_boundary.thermal_openings: radiation = thermal_boundary.parent_surface.global_irradiance[cte.HOUR][hour] * cte.WATTS_HOUR_TO_JULES
radiation = thermal_boundary.parent_surface.global_irradiance[cte.HOUR][hour] * cte.WATTS_HOUR_TO_JULES cooling_load_radiation += (
cooling_load_radiation += ( thermal_opening.area * (1 - thermal_opening.frame_ratio) * thermal_opening.g_value * radiation
thermal_opening.area * (1 - thermal_opening.frame_ratio) * thermal_opening.g_value * radiation )
)
return cooling_load_radiation return cooling_load_radiation

View File

@ -54,13 +54,11 @@ class PeakLoads:
""" """
month = 1 month = 1
peaks = [0 for _ in range(12)] peaks = [0 for _ in range(12)]
print('hv', hourly_values)
for i in range(0, len(hourly_values)): for i in range(0, len(hourly_values)):
if _MONTH_STARTING_HOUR[month] <= i: if _MONTH_STARTING_HOUR[month] <= i:
month += 1 month += 1
if hourly_values[i] > peaks[month-1]: if hourly_values[i] > peaks[month-1]:
peaks[month-1] = hourly_values[i] peaks[month-1] = hourly_values[i]
print('peak', peaks)
return peaks return peaks
@property @property
@ -75,18 +73,15 @@ class PeakLoads:
ambient_temperature = self._building.external_temperature[cte.HOUR] ambient_temperature = self._building.external_temperature[cte.HOUR]
for month in range(0, 12): for month in range(0, 12):
ground_temperature = self._building.ground_temperature[cte.MONTH]['2'][month] ground_temperature = self._building.ground_temperature[cte.MONTH]['2'][month]
heating_ambient_temperature = 100
start_hour = _MONTH_STARTING_HOUR[month] start_hour = _MONTH_STARTING_HOUR[month]
end_hour = 8760 end_hour = 8760
if month < 11: if month < 11:
end_hour = _MONTH_STARTING_HOUR[month + 1] end_hour = _MONTH_STARTING_HOUR[month + 1]
for hour in range(start_hour, end_hour): heating_ambient_temperature = min(ambient_temperature[start_hour:end_hour])
temperature = ambient_temperature[hour]
if temperature < heating_ambient_temperature:
heating_ambient_temperature = temperature
loads = LoadsCalculation(self._building) loads = LoadsCalculation(self._building)
heating_load_transmitted = loads.get_heating_transmitted_load(heating_ambient_temperature, ground_temperature) heating_load_transmitted = loads.get_heating_transmitted_load(heating_ambient_temperature, ground_temperature)
heating_load_ventilation_sensible = loads.get_heating_ventilation_load_sensible(heating_ambient_temperature) heating_load_ventilation_sensible = loads.get_heating_ventilation_load_sensible(heating_ambient_temperature)
# todo: include heating ventilation latent
heating_load_ventilation_latent = 0 heating_load_ventilation_latent = 0
heating_load = heating_load_transmitted + heating_load_ventilation_sensible + heating_load_ventilation_latent heating_load = heating_load_transmitted + heating_load_ventilation_sensible + heating_load_ventilation_latent
heating_load = max(heating_load, 0) heating_load = max(heating_load, 0)