Partial implementation for idf schedule import (doe_idf)

This commit is contained in:
Guille Gutierrez 2021-08-25 11:05:22 -04:00
parent 5af0984aee
commit c861dc6bc3
4 changed files with 129 additions and 146 deletions

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>

View File

@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/.idea/libs_EPlus.iml" filepath="$PROJECT_DIR$/.idea/libs_EPlus.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/libs.iml" filepath="$PROJECT_DIR$/.idea/libs.iml" />
</modules> </modules>
</component> </component>
</project> </project>

View File

@ -3,8 +3,6 @@ MyClass module
SPDX - License - Identifier: LGPL - 3.0 - or -later SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Copyright © 2020 Project
""" """
import pandas as pd import pandas as pd
import parseidf import parseidf
@ -23,6 +21,10 @@ class DoeIdf:
_SCHEDULE_TYPE_NAME = 1 _SCHEDULE_TYPE_NAME = 1
def __init__(self, city, base_path): 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._city = city
self._idf_schedules_path = base_path / 'ASHRAE901_OfficeSmall_STD2019_Buffalo.idf' self._idf_schedules_path = base_path / 'ASHRAE901_OfficeSmall_STD2019_Buffalo.idf'
with open(self._idf_schedules_path, 'r') as f: with open(self._idf_schedules_path, 'r') as f:
@ -30,54 +32,41 @@ class DoeIdf:
self._load_schedule(idf, 'small_office') self._load_schedule(idf, 'small_office')
def _load_schedule(self, idf, building_usage): def _load_schedule(self, idf, building_usage):
holiday = [] schedules_day = {}
winter_design_day = []
summer_design_day = []
custom_day_1 = []
custom_day_2 = []
weekday = []
weekend = []
day_types = []
schedules_day = {'None':[]}
compact_keywords = ['Weekdays', 'Weekends', 'Alldays', 'AllOtherDays', 'Sunday', 'Monday', 'Tuesday',
'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Holiday', 'Winterdesignday',
'Summerdesignday', 'Customday1', 'Customday2']
j = 0
for compact_schedule in idf[self._SCHEDULE_COMPACT_TYPE]: for compact_schedule in idf[self._SCHEDULE_COMPACT_TYPE]:
j = j +1 if compact_schedule[self._SCHEDULE_TYPE_NAME] in self.idf_schedule_to_commet_schedule:
if 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]] schedule_type = self.idf_schedule_to_commet_schedule[compact_schedule[self._SCHEDULE_TYPE_NAME]]
else: else:
schedule_type = 'Unknown' continue
# todo: check this piece of code logic
days_index = [] days_index = []
days_schedules = []
for position, elements in enumerate(compact_schedule): for position, elements in enumerate(compact_schedule):
element_title = elements.title().replace('For: ', '') element_title = elements.title().replace('For: ', '')
if elements.title() != element_title: if elements.title() != element_title:
days_index.append(position) days_index.append(position)
day_types.append(element_title) # store a cleaned version of the compact schedule
days_index.append(len(day_types)) days_schedules.append(element_title)
print(day_types) days_index.append(len(days_schedules))
print(days_index)
'''
for count, word_day_type in enumerate(day_type):
if word_day_type in compact_keywords:
index.append(count)
index.append(len(day_type))
'''
for i, day_index in enumerate(days_index): for i, day_index in enumerate(days_index):
if day_index == len(day_types): if day_index == len(days_schedules):
break break
schedules_day[f'{day_types[day_index]}'] = [] schedules_day[f'{days_schedules[day_index]}'] = []
print(f'{day_types[day_index]}') hour_index = 0
for hours_values in range(day_index + 1, days_index[i + 1] - 1, 2): 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:
entry = (hour, days_schedules[hours_values + 1])
schedules_day[f'{days_schedules[day_index]}'].append(entry)
print(f'{day_types[hours_values]}# {day_types[hours_values+1]} ') print(schedules_day[f'{days_schedules[day_index]}'])
if j == 2:
return
''' '''
for i in range(len(index) - 1): for i in range(len(index) - 1):
number_of_day_schedule = list(day_types[index[i] + 1:index[i + 1]]) number_of_day_schedule = list(day_types[index[i] + 1:index[i + 1]])
@ -108,18 +97,18 @@ class DoeIdf:
custom_day_2.append(hourly_values) custom_day_2.append(hourly_values)
else: else:
raise ValueError('Unknown schedule day type') raise ValueError('Unknown schedule day type')
'''
idf_schedules = pd.DataFrame( idf_schedules = pd.DataFrame(
{'week_day': weekday, {'week_day': schedules_day['Weekdays'],
'Weekends': weekend, 'Weekends': schedules_day['Weekends'],
'Holiday': holiday, 'Holiday': schedules_day['Holiday'],
'Winterdesignday': winter_design_day, 'Winterdesignday': schedules_day['Winterdesignday'],
'Summerdesignday': summer_design_day, 'Summerdesignday': schedules_day['Summerdesignday'],
'Customday1': custom_day_1, 'Customday1': schedules_day['Customday1'],
'Customday2': custom_day_2, 'Customday2': schedules_day['Customday2']
}) })
print(idf_schedules) print(idf_schedules)
'''
''' '''
for building in city.buildings: for building in city.buildings:
schedules = dict() schedules = dict()

View File

@ -8,6 +8,7 @@ from unittest import TestCase
from imports.geometry_factory import GeometryFactory from imports.geometry_factory import GeometryFactory
from imports.usage_factory import UsageFactory from imports.usage_factory import UsageFactory
from imports.construction_factory import ConstructionFactory
from imports.schedules_factory import SchedulesFactory from imports.schedules_factory import SchedulesFactory
from imports.geometry.helpers.geometry_helper import GeometryHelper from imports.geometry.helpers.geometry_helper import GeometryHelper
@ -28,6 +29,7 @@ class TestSchedulesFactory(TestCase):
def _get_citygml(self, file): def _get_citygml(self, file):
file_path = (self._example_path / file).resolve() file_path = (self._example_path / file).resolve()
self._city = GeometryFactory('citygml', file_path).city self._city = GeometryFactory('citygml', file_path).city
ConstructionFactory('nrel', self._city).enrich()
self.assertIsNotNone(self._city, 'city is none') self.assertIsNotNone(self._city, 'city is none')
for building in self._city.buildings: for building in self._city.buildings:
building.function = GeometryHelper.hft_to_function[building.function] building.function = GeometryHelper.hft_to_function[building.function]
@ -43,3 +45,9 @@ class TestSchedulesFactory(TestCase):
self.assertIsNot(len(building.usage_zones), 0, 'no building usage_zones defined') self.assertIsNot(len(building.usage_zones), 0, 'no building usage_zones defined')
for usage_zone in building.usage_zones: for usage_zone in building.usage_zones:
self.assertTrue(usage_zone.schedules) self.assertTrue(usage_zone.schedules)
def test_deo_idf_archetypes(self):
file = (self._example_path / 'C40_Final.gml').resolve()
city = self._get_citygml(file)
occupancy_handler = 'doe_idf'
SchedulesFactory(occupancy_handler, city).enrich()