diff --git a/exports/formats/idf.py b/exports/formats/idf.py index b3512260..45c5990a 100644 --- a/exports/formats/idf.py +++ b/exports/formats/idf.py @@ -105,6 +105,9 @@ class Idf: for schedule in self._idf.idfobjects[self._HOURLY_SCHEDULE]: if schedule.Name == f'{schedule_type} schedules {usage_zone.usage}': return + if usage_zone.schedules is None or schedule_type not in usage_zone.schedules: + # there are no schedule for this type + return schedule = self._idf.newidfobject(self._HOURLY_SCHEDULE, Name=f'{schedule_type} schedules {usage_zone.usage}') schedule.Schedule_Type_Limits_Name = limit_name diff --git a/imports/schedules/doe_idf.py b/imports/schedules/doe_idf.py index c9203dbd..da8a5468 100644 --- a/imports/schedules/doe_idf.py +++ b/imports/schedules/doe_idf.py @@ -29,7 +29,7 @@ class DoeIdf: self._idf_schedules_path = base_path / 'ASHRAE901_OfficeSmall_STD2019_Buffalo.idf' with open(self._idf_schedules_path, 'r') as f: idf = parseidf.parse(f.read()) - self._load_schedule(idf, 'small_office') + self._load_schedule(idf, 'residential') def _load_schedule(self, idf, building_usage): schedules_day = {} @@ -47,7 +47,13 @@ class DoeIdf: # store a cleaned version of the compact schedule days_schedules.append(element_title) days_index.append(len(days_schedules)) - + # create panda + data = {'WD': [], 'Sat': [], 'Sun': []} + rows = [] + for j in range(1, 13): + rows.append(f'{j}am') + for j in range(1, 13): + rows.append(f'{j}pm') for i, day_index in enumerate(days_index): if day_index == len(days_schedules): break @@ -63,75 +69,47 @@ class DoeIdf: hour_index += index break else: - entry = (hour, days_schedules[hours_values + 1]) + entry = days_schedules[hours_values + 1] schedules_day[f'{days_schedules[day_index]}'].append(entry) - print(schedules_day[f'{days_schedules[day_index]}']) - ''' - for i in range(len(index) - 1): - number_of_day_schedule = list(day_types[index[i] + 1:index[i + 1]]) - hourly_values = list(range(24)) - start_hour = 0 - for num in range(int(len(number_of_day_schedule) / 2)): - until_time = list(map(int, (number_of_day_schedule[2*num].split('Until: ')[-1]).split(":")[0:])) - end_hour = int(until_time[0] + until_time[1] / 60) - value = float(number_of_day_schedule[2 * num + 1]) - for hour in range(start_hour, end_hour): - hourly_values[hour] = value - start_hour = end_hour - print(f'{compact_schedule}') - print(f'{building_usage} {schedule_type} {hourly_values}') - if day_type[index[i]] == 'Weekdays': - weekday.append(hourly_values) - elif day_type[index[i]] == 'Weekends': - weekend.append(hourly_values) - elif day_type[index[i]] == 'Holiday': - holiday.append(hourly_values) - elif day_type[index[i]] == 'Winterdesignday': - winter_design_day.append(hourly_values) - elif day_type[index[i]] == 'Summerdesignday': - summer_design_day.append(hourly_values) - elif day_type[index[i]] == 'Customday1': - custom_day_1.append(hourly_values) - elif day_type[index[i]] == 'Customday2': - custom_day_2.append(hourly_values) - else: - raise ValueError('Unknown schedule day type') + if 'Weekdays' in days_schedules[day_index]: + data['WD'] = [] + for entry in schedules_day[f'{days_schedules[day_index]}']: + data['WD'].append(entry) - idf_schedules = pd.DataFrame( - {'week_day': schedules_day['Weekdays'], - 'Weekends': schedules_day['Weekends'], - 'Holiday': schedules_day['Holiday'], - 'Winterdesignday': schedules_day['Winterdesignday'], - 'Summerdesignday': schedules_day['Summerdesignday'], - 'Customday1': schedules_day['Customday1'], - 'Customday2': schedules_day['Customday2'] - }) - print(idf_schedules) -''' - ''' - for building in city.buildings: - schedules = dict() - for usage_zone in building.usage_zones: - usage_schedules = idf_schedules + elif 'Alldays' in days_schedules[day_index]: + data['WD'] = [] + data['Sat'] = [] + data['Sun'] = [] + for entry in schedules_day[f'{days_schedules[day_index]}']: + data['WD'].append(entry) + data['Sat'].append(entry) + data['Sun'].append(entry) + + elif 'Weekends' in days_schedules[day_index]: + # Weekends schedule present so let's re set the values + data['Sat'] = [] + data['Sun'] = [] + for entry in schedules_day[f'{days_schedules[day_index]}']: + data['Sat'].append(entry) + data['Sun'].append(entry) + + elif 'Saturday' in days_schedules[day_index]: + data['Sat'] = [] + for entry in schedules_day[f'{days_schedules[day_index]}']: + data['Sat'].append(entry) + + elif 'Sunday' in days_schedules[day_index]: + data['Sun'] = [] + for entry in schedules_day[f'{days_schedules[day_index]}']: + data['Sun'].append(entry) + else: + continue + df = pd.DataFrame(data, index=rows) + for building in self._city.buildings: + for usage_zone in building.usage_zones: + if usage_zone.usage == building_usage: + if usage_zone.schedules is None: + usage_zone.schedules = {} + usage_zone.schedules[schedule_type] = df - # todo: should we save the data type? How? - number_of_schedule_types = 5 - schedules_per_schedule_type = 6 - idf_day_types = dict({'week_day': 0, 'Weekends': 1, 'Holiday': 2, 'Winterdesignday': 3, 'Summerdesignday': - 4, 'Customday1': 5, 'Customday2': 6}) - for schedule_types in range(0, number_of_schedule_types): - data = pd.DataFrame() - columns_names = [] - name = '' - for schedule_day in range(0, len(idf_schedules)): - row_cells = usage_schedules.iloc[schedules_per_schedule_type*schedule_types + schedule_day] - if schedule_day == idf_day_types['week_day']: - name = row_cells[0] - columns_names.append(row_cells[2]) - data1 = row_cells[schedules_per_schedule_type:] - data = pd.concat([data, data1], axis=1) - data.columns = columns_names - schedules[name] = data - usage_zone.schedules = schedules - ''' diff --git a/imports/schedules_factory.py b/imports/schedules_factory.py index 0e1a2da7..42b3d986 100644 --- a/imports/schedules_factory.py +++ b/imports/schedules_factory.py @@ -22,7 +22,6 @@ class SchedulesFactory: ComnetSchedules(self._city, self._base_path) def _doe_idf(self): - print('Idf handler call') DoeIdf(self._city, self._base_path) def enrich(self): diff --git a/non_functional_tests/test_schedules_factory.py b/non_functional_tests/test_schedules_factory.py index 9cc622e3..3a538917 100644 --- a/non_functional_tests/test_schedules_factory.py +++ b/non_functional_tests/test_schedules_factory.py @@ -44,9 +44,10 @@ class TestSchedulesFactory(TestCase): for building in city.buildings: self.assertIsNot(len(building.usage_zones), 0, 'no building usage_zones defined') for usage_zone in building.usage_zones: + print(usage_zone.schedules) self.assertTrue(usage_zone.schedules) - def test_deo_idf_archetypes(self): + def test_doe_idf_archetypes(self): file = (self._example_path / 'C40_Final.gml').resolve() city = self._get_citygml(file) occupancy_handler = 'doe_idf'