2021-08-25 07:24:21 -04:00
|
|
|
"""
|
|
|
|
MyClass module
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project
|
|
|
|
"""
|
|
|
|
import pandas as pd
|
|
|
|
import parseidf
|
|
|
|
|
|
|
|
|
|
|
|
class DoeIdf:
|
2021-08-25 11:05:22 -04:00
|
|
|
"""
|
|
|
|
This is a import factory to add Idf schedules into the data model
|
|
|
|
"""
|
|
|
|
idf_schedule_to_commet_schedule = {'BLDG_LIGHT_SCH': 'Lights',
|
|
|
|
'BLDG_OCC_SCH_wo_SB': 'Occupancy',
|
|
|
|
'BLDG_EQUIP_SCH': 'Equipment',
|
|
|
|
'ACTIVITY_SCH': 'Activity',
|
|
|
|
'INFIL_QUARTER_ON_SCH': 'Infiltration'}
|
2021-08-25 07:24:21 -04:00
|
|
|
|
2021-08-25 11:05:22 -04:00
|
|
|
_SCHEDULE_COMPACT_TYPE = 'SCHEDULE:COMPACT'
|
|
|
|
_SCHEDULE_TYPE_NAME = 1
|
2021-08-25 07:24:21 -04:00
|
|
|
|
2021-08-25 11:05:22 -04:00
|
|
|
def __init__(self, city, base_path):
|
|
|
|
self._hours = []
|
|
|
|
panda_hours = pd.timedelta_range(0, periods=24, freq='H')
|
|
|
|
for i, hour in enumerate(panda_hours):
|
|
|
|
self._hours.append(str(hour).replace('0 days ', '').replace(':00:00', ':00'))
|
|
|
|
self._city = city
|
|
|
|
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())
|
2021-08-25 14:32:34 -04:00
|
|
|
self._load_schedule(idf, 'small_office')
|
2021-08-25 14:29:30 -04:00
|
|
|
self._load_schedule(idf, 'residential')
|
2021-08-25 07:24:21 -04:00
|
|
|
|
2021-08-25 11:05:22 -04:00
|
|
|
def _load_schedule(self, idf, building_usage):
|
|
|
|
schedules_day = {}
|
|
|
|
for compact_schedule in idf[self._SCHEDULE_COMPACT_TYPE]:
|
|
|
|
if compact_schedule[self._SCHEDULE_TYPE_NAME] in self.idf_schedule_to_commet_schedule:
|
|
|
|
schedule_type = self.idf_schedule_to_commet_schedule[compact_schedule[self._SCHEDULE_TYPE_NAME]]
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
days_index = []
|
|
|
|
days_schedules = []
|
|
|
|
for position, elements in enumerate(compact_schedule):
|
|
|
|
element_title = elements.title().replace('For: ', '')
|
|
|
|
if elements.title() != element_title:
|
|
|
|
days_index.append(position)
|
|
|
|
# store a cleaned version of the compact schedule
|
|
|
|
days_schedules.append(element_title)
|
|
|
|
days_index.append(len(days_schedules))
|
2021-08-25 14:29:30 -04:00
|
|
|
# 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')
|
2021-08-25 11:05:22 -04:00
|
|
|
for i, day_index in enumerate(days_index):
|
|
|
|
if day_index == len(days_schedules):
|
|
|
|
break
|
|
|
|
schedules_day[f'{days_schedules[day_index]}'] = []
|
|
|
|
hour_index = 0
|
|
|
|
for hours_values in range(day_index + 1, days_index[i + 1] - 1, 2):
|
|
|
|
# Create 24h sequence
|
|
|
|
for index, hour in enumerate(self._hours[hour_index:]):
|
|
|
|
hour_formatted = days_schedules[hours_values].replace("Until: ", "")
|
|
|
|
if len(hour_formatted) == 4:
|
|
|
|
hour_formatted = f'0{hour_formatted}'
|
|
|
|
if hour == hour_formatted:
|
|
|
|
hour_index += index
|
|
|
|
break
|
|
|
|
else:
|
2021-08-25 14:29:30 -04:00
|
|
|
entry = days_schedules[hours_values + 1]
|
2021-08-25 11:05:22 -04:00
|
|
|
schedules_day[f'{days_schedules[day_index]}'].append(entry)
|
2021-08-25 07:24:21 -04:00
|
|
|
|
2021-08-25 14:29:30 -04:00
|
|
|
if 'Weekdays' in days_schedules[day_index]:
|
|
|
|
data['WD'] = []
|
|
|
|
for entry in schedules_day[f'{days_schedules[day_index]}']:
|
|
|
|
data['WD'].append(entry)
|
|
|
|
|
|
|
|
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)
|
2021-08-25 07:24:21 -04:00
|
|
|
|
2021-08-25 14:29:30 -04:00
|
|
|
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
|
2021-08-25 07:24:21 -04:00
|
|
|
|