Idf parser and standardization is done (correct version)_need to be updated

This commit is contained in:
Soroush Samareh Abolhassani 2021-08-20 18:36:28 -04:00
parent 1d0dd11409
commit 665adae908
2 changed files with 94 additions and 16990 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,65 +1,105 @@
import pandas as pd import pandas as pd
from imports.schedules.helpers.schedules_helper import SchedulesHelper from imports.schedules.helpers.schedules_helper import SchedulesHelper
import parseidf 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, type): class IDFParser:
self._city = city _OCCUPANCY_SCHEDULE = ("BLDG_OCC_SCH_wo_SB", "Occupancy")
self._idf_schedules_path = base_path / 'ASHRAE901_OfficeSmall_STD2019_Buffalo.idf' _Activity_Schedule = "ACTIVITY_SCH"
with open(self._idf_schedules_path, 'r') as f: _Electrical_Equipent_Schedule = "BLDG_EQUIP_SCH"
idf = parseidf.parse(f.read()) _Lighting_Schedule = "BLDG_LIGHT_SCH"
_Infiltration_Ventilation_Schedule = "INFIL_QUARTER_ON_SCH"
for building in city.buildings: def __init__(self, city, base_path):
schedules = dict() self._city = city
for usage_zone in building.usage_zones: self._idf_schedules_path = base_path / 'ASHRAE901_OfficeSmall_STD2019_Buffalo.idf'
usage_schedules = pd.Datafram(idf['SCHEDULE:COMPACT']) 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)
Small_Office_Occupancy = [] for building in city.buildings:
Small_Office_OccupancyActivity = [] schedules = dict()
Small_Office_ElectricalEquipment = [] for usage_zone in building.usage_zones:
Small_Office_Lighting = [] usage_schedules = idf_schedules
Small_Office_Infiltration = []
for i in usage_schedules: # todo: should we save the data type? How?
if i[1] == self._Occupancy_Schedule: number_of_schedule_types = 5
return Small_Office_Occupancy.append(i) schedules_per_schedule_type = 6
elif i[1] == 'ACTIVITY_SCH': idf_day_types = dict({'week_day': 0, 'Weekends': 1, 'Holiday': 2, 'Winterdesignday': 3, 'Summerdesignday': 4, 'Customday1': 5, 'Customday2': 6})
Small_Office_OccupancyActivity.append(i) for schedule_types in range(0, number_of_schedule_types):
elif i[1] == 'BLDG_EQUIP_SCH': data = pd.DataFrame()
Small_Office_ElectricalEquipment.append(i) columns_names = []
elif i[1] == 'BLDG_LIGHT_SCH': name = ''
Small_Office_Lighting.append(i) for schedule_day in range(0, len(idf_schedules)):
elif i[1] == 'INFIL_QUARTER_ON_SCH': row_cells = usage_schedules.iloc[schedules_per_schedule_type*schedule_types + schedule_day]
Small_Office_Infiltration.append(i) if schedule_day == idf_day_types['week_day']:
else: name = row_cells[0]
print("The schedule name is not standard") 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
'''
# todo: should we save the data type? How?
number_of_schedule_types = 13
schedules_per_schedule_type = 3
day_types = dict({'week_day': 0, 'saturday': 1, 'sunday': 2})
for schedule_types in range(0, number_of_schedule_types):
data = pd.DataFrame()
columns_names = []
name = ''
for schedule_day in range(0, schedules_per_schedule_type):
row_cells = usage_schedules.iloc[schedules_per_schedule_type*schedule_types + schedule_day]
if schedule_day == 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
'''