diff --git a/hub/city_model_structure/building.py b/hub/city_model_structure/building.py index 0f4dbc8b..bdb8a7e3 100644 --- a/hub/city_model_structure/building.py +++ b/hub/city_model_structure/building.py @@ -684,11 +684,17 @@ class Building(CityObject): for i, value in enumerate(item): _working_hours[key][i] = max(_working_hours[key][i], saved_values[i]) - _total_hours = 0 - for key in _working_hours: - hours = sum(_working_hours[key]) - _total_hours += hours * cte.WEEK_DAYS_A_YEAR[key] - return _total_hours + working_hours = {} + values_months = [] + for month in cte.WEEK_DAYS_A_MONTH.keys(): + _total_hours_month = 0 + for key in _working_hours: + hours = sum(_working_hours[key]) + _total_hours_month += hours * cte.WEEK_DAYS_A_MONTH[month][key] + values_months.append(_total_hours_month) + working_hours[cte.MONTH] = values_months + working_hours[cte.YEAR] = sum(working_hours[cte.MONTH]) + return working_hours @property def distribution_systems_electrical_consumption(self): @@ -738,7 +744,7 @@ class Building(CityObject): for key, item in self._distribution_systems_electrical_consumption.items(): for i in range(0, len(item)): self._distribution_systems_electrical_consumption[key][i] += _peak_load * _consumption_fix_flow \ - * _working_hours + * _working_hours[key] * cte.WATTS_HOUR_TO_JULES return self._distribution_systems_electrical_consumption def _calculate_consumption(self, consumption_type, demand): diff --git a/hub/helpers/constants.py b/hub/helpers/constants.py index 7cd6151e..c2d9d642 100644 --- a/hub/helpers/constants.py +++ b/hub/helpers/constants.py @@ -49,36 +49,140 @@ WEEK_DAYS = 'Weekdays' WEEK_ENDS = 'Weekends' ALL_DAYS = 'Alldays' -WEEK_DAYS_A_MONTH = {'monday': [5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 5], - 'tuesday': [5, 4, 4, 4, 5, 4, 5, 4, 4, 5, 4, 4], - 'wednesday': [5, 4, 4, 4, 5, 4, 4, 5, 4, 5, 4, 4], - 'thursday': [4, 4, 5, 4, 5, 4, 4, 5, 4, 4, 5, 4], - 'friday': [4, 4, 5, 4, 4, 5, 4, 5, 4, 4, 5, 4], - 'saturday': [4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5], - 'sunday': [4, 4, 4, 5, 4, 4, 5, 4, 5, 4, 4, 5], - 'holiday': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]} +JANUARY = 'January' +FEBRUARY = 'February' +MARCH = 'March' +APRIL = 'April' +MAY = 'May' +JUNE = 'June' +JULY = 'July' +AUGUST = 'August' +SEPTEMBER = 'September' +OCTOBER = 'October' +NOVEMBER = 'November' +DECEMBER = 'December' -WEEK_DAYS_A_YEAR = {'monday': 51, - 'tuesday': 50, - 'wednesday': 50, - 'thursday': 50, - 'friday': 50, - 'saturday': 52, - 'sunday': 52, - 'holiday': 10} +MONTHS = [JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER] -DAYS_A_MONTH = {'January': 31, - 'February': 28, - 'March': 31, - 'April': 30, - 'May': 31, - 'June': 30, - 'July': 31, - 'August': 31, - 'September': 30, - 'October': 31, - 'November': 30, - 'December': 31} +WEEK_DAYS_A_MONTH = {JANUARY: {MONDAY: 5, + TUESDAY: 5, + WEDNESDAY: 5, + THURSDAY: 4, + FRIDAY: 4, + SATURDAY: 4, + SUNDAY: 4, + HOLIDAY: 0}, + FEBRUARY: {MONDAY: 4, + TUESDAY: 4, + WEDNESDAY: 4, + THURSDAY: 4, + FRIDAY: 4, + SATURDAY: 4, + SUNDAY: 4, + HOLIDAY: 0}, + MARCH: {MONDAY: 4, + TUESDAY: 4, + WEDNESDAY: 4, + THURSDAY: 5, + FRIDAY: 5, + SATURDAY: 5, + SUNDAY: 4, + HOLIDAY: 0}, + APRIL: {MONDAY: 5, + TUESDAY: 4, + WEDNESDAY: 4, + THURSDAY: 4, + FRIDAY: 4, + SATURDAY: 4, + SUNDAY: 5, + HOLIDAY: 0}, + MAY: {MONDAY: 4, + TUESDAY: 5, + WEDNESDAY: 5, + THURSDAY: 5, + FRIDAY: 4, + SATURDAY: 4, + SUNDAY: 4, + HOLIDAY: 0}, + JUNE: {MONDAY: 4, + TUESDAY: 4, + WEDNESDAY: 4, + THURSDAY: 4, + FRIDAY: 5, + SATURDAY: 5, + SUNDAY: 4, + HOLIDAY: 0}, + JULY: {MONDAY: 5, + TUESDAY: 5, + WEDNESDAY: 4, + THURSDAY: 4, + FRIDAY: 4, + SATURDAY: 4, + SUNDAY: 5, + HOLIDAY: 0}, + AUGUST: {MONDAY: 4, + TUESDAY: 4, + WEDNESDAY: 5, + THURSDAY: 5, + FRIDAY: 5, + SATURDAY: 4, + SUNDAY: 4, + HOLIDAY: 0}, + SEPTEMBER: {MONDAY: 4, + TUESDAY: 4, + WEDNESDAY: 4, + THURSDAY: 4, + FRIDAY: 4, + SATURDAY: 5, + SUNDAY: 5, + HOLIDAY: 0}, + OCTOBER: {MONDAY: 5, + TUESDAY: 5, + WEDNESDAY: 5, + THURSDAY: 4, + FRIDAY: 4, + SATURDAY: 4, + SUNDAY: 4, + HOLIDAY: 0}, + NOVEMBER: {MONDAY: 4, + TUESDAY: 4, + WEDNESDAY: 4, + THURSDAY: 5, + FRIDAY: 5, + SATURDAY: 4, + SUNDAY: 4, + HOLIDAY: 0}, + DECEMBER: {MONDAY: 5, + TUESDAY: 4, + WEDNESDAY: 4, + THURSDAY: 4, + FRIDAY: 4, + SATURDAY: 5, + SUNDAY: 5, + HOLIDAY: 0}, + } + +WEEK_DAYS_A_YEAR = {MONDAY: 51, + TUESDAY: 50, + WEDNESDAY: 50, + THURSDAY: 50, + FRIDAY: 50, + SATURDAY: 52, + SUNDAY: 52, + HOLIDAY: 10} + +DAYS_A_MONTH = {JANUARY: 31, + FEBRUARY: 28, + MARCH: 31, + APRIL: 30, + MAY: 31, + JUNE: 30, + JULY: 31, + AUGUST: 31, + SEPTEMBER: 30, + OCTOBER: 31, + NOVEMBER: 30, + DECEMBER: 31} # data types ANY_NUMBER = 'any_number' diff --git a/hub/imports/results/insel_monthly_energry_balance.py b/hub/imports/results/insel_monthly_energry_balance.py index 34aab2ec..37783185 100644 --- a/hub/imports/results/insel_monthly_energry_balance.py +++ b/hub/imports/results/insel_monthly_energry_balance.py @@ -59,7 +59,7 @@ class InselMonthlyEnergyBalance: lighting_density = thermal_zone.lighting.density appliances_density = thermal_zone.appliances.density - for month in range(0, 12): + for i_month, month in enumerate(cte.MONTHS): total_dhw_demand = 0 total_lighting = 0 total_appliances = 0 @@ -69,7 +69,7 @@ class InselMonthlyEnergyBalance: for value in schedule.values: total_day += value for day_type in schedule.day_types: - total_lighting += total_day * cte.WEEK_DAYS_A_MONTH[day_type][month] \ + total_lighting += total_day * cte.WEEK_DAYS_A_MONTH[month][day_type] \ * lighting_density / cte.WATTS_HOUR_TO_JULES lighting_demand.append(total_lighting * area) @@ -78,7 +78,7 @@ class InselMonthlyEnergyBalance: for value in schedule.values: total_day += value for day_type in schedule.day_types: - total_appliances += total_day * cte.WEEK_DAYS_A_MONTH[day_type][month] \ + total_appliances += total_day * cte.WEEK_DAYS_A_MONTH[month][day_type] \ * appliances_density / cte.WATTS_HOUR_TO_JULES appliances_demand.append(total_appliances * area) @@ -89,9 +89,9 @@ class InselMonthlyEnergyBalance: for day_type in schedule.day_types: demand = ( peak_flow * cte.WATER_DENSITY * cte.WATER_HEAT_CAPACITY - * (service_temperature - cold_water[month]) / cte.WATTS_HOUR_TO_JULES + * (service_temperature - cold_water[i_month]) / cte.WATTS_HOUR_TO_JULES ) - total_dhw_demand += total_day * cte.WEEK_DAYS_A_MONTH[day_type][month] * demand + total_dhw_demand += total_day * cte.WEEK_DAYS_A_MONTH[month][day_type] * demand domestic_hot_water_demand.append(total_dhw_demand * area) except AttributeError: domestic_hot_water_demand = [0] * 12 diff --git a/tests/test_results_import.py b/tests/test_results_import.py index 1befac19..76be5876 100644 --- a/tests/test_results_import.py +++ b/tests/test_results_import.py @@ -40,7 +40,7 @@ class TestResultsImport(TestCase): function_to_hub=Dictionaries().montreal_function_to_hub_function).city ConstructionFactory('nrcan', self._city).enrich() - UsageFactory('nrcan', self._city).enrich() + UsageFactory('comnet', self._city).enrich() def test_sra_import(self): ExportsFactory('sra', self._city, self._output_path).export()