system_assignation/imports/schedules/DOE_IDF.py

106 lines
4.8 KiB
Python

import pandas as pd
from imports.schedules.helpers.schedules_helper import SchedulesHelper
import parseidf
class IDFParser:
_OCCUPANCY_SCHEDULE = ("BLDG_OCC_SCH_wo_SB", "Occupancy")
_Activity_Schedule = "ACTIVITY_SCH"
_Electrical_Equipent_Schedule = "BLDG_EQUIP_SCH"
_Lighting_Schedule = "BLDG_LIGHT_SCH"
_Infiltration_Ventilation_Schedule = "INFIL_QUARTER_ON_SCH"
def __init__(self, city, base_path):
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())
print(idf.keys()) # lists the object types in the idf file
print(idf['SCHEDULE:COMPACT']) # lists all the Output:Variable objects in the idf file
Holiday = []
Winterdesignday = []
Summerdesignday = []
Customday1 = []
Customday2 = []
Weekday = []
Weekend = []
dayType = []
compactKeywords = ['Weekdays', 'Weekends', 'Alldays', 'AllOtherDays', 'Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday', 'Holiday', 'Winterdesignday', 'Summerdesignday', 'Customday1',
'Customday2']
for val in idf['SCHEDULE:COMPACT']:
if val[1] == 'BLDG_LIGHT_SCH':
count = 0
for words in val:
dayType.append(words.title().split('For: ')[-1])
index = []
for count, word_dayType in enumerate(dayType):
if word_dayType in compactKeywords:
index.append(count)
index.append(len(dayType))
for i in range(len(index) - 1):
numberOfDaySch = list(dayType[index[i] + 1:index[i + 1]])
hourlyValues = list(range(24))
startHour = 0
for num in range(int(len(numberOfDaySch) / 2)):
untilTime = list(map(int, (numberOfDaySch[2 * num].split('Until: ')[-1]).split(":")[0:]))
endHour = int(untilTime[0] + untilTime[1] / 60)
value = float(numberOfDaySch[2 * num + 1])
for hour in range(startHour, endHour):
hourlyValues[hour] = value
print(hour, value)
startHour = endHour
if dayType[index[i]] == 'Weekdays':
Weekday.append(hourlyValues)
elif dayType[index[i]] == 'Weekends':
Weekend.append(hourlyValues)
elif dayType[index[i]] == 'Holiday':
Holiday.append(hourlyValues)
elif dayType[index[i]] == 'Winterdesignday':
Winterdesignday.append(hourlyValues)
elif dayType[index[i]] == 'Summerdesignday':
Summerdesignday.append(hourlyValues)
elif dayType[index[i]] == 'Customday1':
Customday1.append(hourlyValues)
elif dayType[index[i]] == 'Customday2':
Customday2.append(hourlyValues)
else:
print('its none of them')
idf_schedules = pd.DataFrame(
{'week_day': Weekday,
'Weekends': Weekend,
'Holiday': Holiday,
'Winterdesignday': Winterdesignday,
'Summerdesignday': Summerdesignday,
'Customday1': Customday1,
'Customday2': Customday2,
})
print(idf_schedules)
for building in city.buildings:
schedules = dict()
for usage_zone in building.usage_zones:
usage_schedules = idf_schedules
# 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