""" monthly_to_hourly_demand module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es """ import pandas as pd from city_model_structure.attributes.occupants import Occupants import calendar as cal class MonthlyToHourlyDemand: """ MonthlyToHourlyDemand class """ def __init__(self, building, conditioning_seasons): self._hourly_heating = pd.DataFrame() self._hourly_cooling = pd.DataFrame() self._building = building self._conditioning_seasons = conditioning_seasons @property def hourly_heating(self): """ hourly distribution of the monthly heating of a building :return: [hourly_heating] """ # todo: this method and the insel model have to be reviewed for more than one thermal zone external_temp = self._building.external_temperature['hour'] # todo: review index depending on how the schedules are defined, either 8760 or 24 hours for usage_zone in self._building.usage_zones: temp_set = float(usage_zone.heating_setpoint) temp_back = float(usage_zone.heating_setback) occupancy = Occupants().get_complete_year_schedule(usage_zone.schedules['Occupancy']) heating_schedule = self._conditioning_seasons['heating'] hourly_heating = [] i = 0 temp_grad_day = [] for month in range(1, 13): temp_grad_month = 0 month_range = cal.monthrange(2015, month) for day in range(1, month_range[1]+1): external_temp_med = 0 for hour in range(0, 24): external_temp_med += external_temp['inseldb'][i]/24 for hour in range(0, 24): if external_temp_med < temp_set and heating_schedule[month-1] == 1: if occupancy[hour] > 0: temp_grad_day.append(temp_set - external_temp['inseldb'][i]) else: temp_grad_day.append(temp_back - external_temp['inseldb'][i]) else: temp_grad_day.append(0) temp_grad_month += temp_grad_day[i] i += 1 for day in range(1, month_range[1] + 1): for hour in range(0, 24): j = (day - 1) * 24 + hour monthly_demand = self._building.heating['month']['INSEL'][month-1] hourly_demand = float(monthly_demand)*float(temp_grad_day[j])/float(temp_grad_month) hourly_heating.append(hourly_demand) self._hourly_heating = pd.DataFrame(data=hourly_heating, columns=['monthly to hourly']) return self._hourly_heating @property def hourly_cooling(self) -> NotImplementedError: raise NotImplementedError