added Schedule class. Modified schedules attribute in usage_zone.py according to this new class. Modified comnet import and its test. Other imports and exports related to schedules will be broken.

This commit is contained in:
Pilar 2021-09-01 12:14:48 -04:00
parent b21f7a9f65
commit e116acdeca
6 changed files with 197 additions and 43 deletions

View File

@ -0,0 +1,132 @@
"""
Schedule module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2021 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import uuid
class Schedule:
"""
Schedule class
"""
def __init__(self):
self._id = None
self._type = None
self._values = None
self._data_type = None
self._time_step = None
self._time_range = None
self._day_types = None
@property
def id(self):
"""
Get schedule id, an universally unique identifier randomly generated
:return: str
"""
if self._id is None:
self._id = uuid.uuid4()
return self._id
@property
def type(self):
"""
Get schedule type
:return: str
"""
return self._type
@type.setter
def type(self, value):
"""
Set schedule type
:param: str
"""
self._type = value
@property
def values(self):
"""
Get schedule values
:return: Union([float], [int])
"""
return self._values
@values.setter
def values(self, value):
"""
Set schedule values
:param: Union([float], [int])
"""
self._values = value
@property
def data_type(self):
"""
Get schedule data type from:
['any_number', 'fraction', 'on_off', 'temperature', 'humidity', 'control_type']
:return: str
"""
return self._data_type
@data_type.setter
def data_type(self, value):
"""
Set schedule data type
:param: str
"""
self._data_type = value
@property
def time_step(self):
"""
Get schedule time step from:
['second', 'minute', 'hour', 'day', 'week', 'month']
:return: str
"""
return self._time_step
@time_step.setter
def time_step(self, value):
"""
Set schedule time step
:param: str
"""
self._time_step = value
@property
def time_range(self):
"""
Get schedule time range from:
['minute', 'hour', 'day', 'week', 'month', 'year']
:return: str
"""
return self._time_range
@time_range.setter
def time_range(self, value):
"""
Set schedule time range
:param: str
"""
self._time_range = value
@property
def day_types(self):
"""
Get schedule day types, as many as needed from:
['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'holiday', 'winter_design_day',
'summer_design_day']
:return: [str]
"""
return self._day_types
@day_types.setter
def day_types(self, value):
"""
Set schedule day types
:param: [str]
"""
self._day_types = value

View File

@ -1,31 +0,0 @@
"""
Building module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Sanam Dabirian sanam.dabirian@mail.concordia.ca
"""
class ScheduleValue:
"""
Schedule Values class
"""
def __init__(self, hour, probability):
self._hour = hour
self._probability = probability
@property
def hour(self):
"""
Get hours
:return: str
"""
return self._hour
@property
def probability(self):
"""
Get probabilities of occupants' presence
:return: float
"""
return self._probability

View File

@ -9,6 +9,7 @@ Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.mons
KELVIN = 273.15 KELVIN = 273.15
# time # time
SECOND = 'second'
MINUTE = 'minute' MINUTE = 'minute'
HOUR = 'hour' HOUR = 'hour'
DAY = 'day' DAY = 'day'
@ -16,6 +17,26 @@ WEEK = 'week'
MONTH = 'month' MONTH = 'month'
YEAR = 'year' YEAR = 'year'
# day types
MONDAY = 'monday'
TUESDAY = 'tuesday'
WEDNESDAY = 'wednesday'
THURSDAY = 'thursday'
FRIDAY = 'friday'
SATURDAY = 'saturday'
SUNDAY = 'sunday'
HOLIDAY = 'holiday'
WINTER_DESIGN_DAY = 'winter_design_day'
SUMMER_DESIGN_DAY = 'summer_design_day'
# data types
ANY_NUMBER = 'any_number'
FRACTION = 'fraction'
ON_OFF = 'on_off'
TEMPERATURE = 'temperature'
HUMIDITY = 'humidity'
CONTROL_TYPE = 'control_type'
# todo: modify code to use global constants instead of hard-coded values # todo: modify code to use global constants instead of hard-coded values
# surface types # surface types
WALL = 'Wall' WALL = 'Wall'

View File

@ -6,37 +6,45 @@ contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
""" """
import pandas as pd import pandas as pd
from imports.schedules.helpers.schedules_helper import SchedulesHelper from imports.schedules.helpers.schedules_helper import SchedulesHelper
from city_model_structure.attributes.schedule import Schedule
import helpers.constants as cte
class ComnetSchedules: class ComnetSchedules:
""" """
Commet based schedules Comnet based schedules
""" """
def __init__(self, city, base_path): def __init__(self, city, base_path):
self._city = city self._city = city
self._comnet_schedules_path = base_path / 'comnet_archetypes.xlsx' self._comnet_schedules_path = base_path / 'comnet_archetypes.xlsx'
xls = pd.ExcelFile(self._comnet_schedules_path) xls = pd.ExcelFile(self._comnet_schedules_path)
for building in city.buildings: for building in city.buildings:
schedules = dict()
for usage_zone in building.usage_zones: for usage_zone in building.usage_zones:
schedules = []
usage_schedules = pd.read_excel(xls, usage_schedules = pd.read_excel(xls,
sheet_name=SchedulesHelper.comnet_from_usage(usage_zone.usage), sheet_name=SchedulesHelper.comnet_from_usage(usage_zone.usage),
skiprows=[0, 1, 2, 3], nrows=39, usecols="A:AA") skiprows=[0, 1, 2, 3], nrows=39, usecols="A:AA")
# todo: should we save the data type? How?
number_of_schedule_types = 13 number_of_schedule_types = 13
schedules_per_schedule_type = 3 schedules_per_schedule_type = 3
day_types = dict({'week_day': 0, 'saturday': 1, 'sunday': 2}) day_types = dict({'week_day': 0, 'saturday': 1, 'sunday': 2})
for schedule_types in range(0, number_of_schedule_types): for schedule_types in range(0, number_of_schedule_types):
data = pd.DataFrame()
columns_names = []
name = '' name = ''
data_type = ''
for schedule_day in range(0, schedules_per_schedule_type): for schedule_day in range(0, schedules_per_schedule_type):
schedule = Schedule()
schedule.time_step = cte.HOUR
schedule.time_range = cte.DAY
row_cells = usage_schedules.iloc[schedules_per_schedule_type*schedule_types + schedule_day] row_cells = usage_schedules.iloc[schedules_per_schedule_type*schedule_types + schedule_day]
if schedule_day == day_types['week_day']: if schedule_day == day_types['week_day']:
name = row_cells[0] name = row_cells[0]
columns_names.append(row_cells[2]) data_type = row_cells[1]
data1 = row_cells[schedules_per_schedule_type:] schedule.day_types = [cte.MONDAY, cte.TUESDAY, cte.WEDNESDAY, cte.THURSDAY, cte.FRIDAY]
data = pd.concat([data, data1], axis=1) elif schedule_day == day_types['saturday']:
data.columns = columns_names schedule.day_types = [cte.SATURDAY]
schedules[name] = data else:
schedule.day_types = [cte.SUNDAY]
schedule.type = name
schedule.data_type = SchedulesHelper.data_type_from_comnet(data_type)
schedule.values = row_cells[schedules_per_schedule_type:].to_numpy()
schedules.append(schedule)
usage_zone.schedules = schedules usage_zone.schedules = schedules

View File

@ -25,6 +25,12 @@ class SchedulesHelper:
} }
comnet_default_value = 'C-12 Residential' comnet_default_value = 'C-12 Residential'
comnet_to_data_type = {
'Fraction': cte.FRACTION,
'OnOff': cte.ON_OFF,
'Temperature': cte.TEMPERATURE
}
@staticmethod @staticmethod
def comnet_from_usage(usage): def comnet_from_usage(usage):
""" """
@ -37,3 +43,15 @@ class SchedulesHelper:
except KeyError: except KeyError:
sys.stderr.write('Error: keyword not found. Returned default Comnet schedules "residential"\n') sys.stderr.write('Error: keyword not found. Returned default Comnet schedules "residential"\n')
return SchedulesHelper.comnet_default_value return SchedulesHelper.comnet_default_value
@staticmethod
def data_type_from_comnet(comnet_data_type):
"""
Get data_type from the Comnet data type definitions
:param comnet_data_type: str
:return: str
"""
try:
return SchedulesHelper.comnet_to_data_type[comnet_data_type]
except KeyError:
raise ValueError(f"Error: comnet data type keyword not found.")

View File

@ -46,8 +46,14 @@ class TestSchedulesFactory(TestCase):
for building in city.buildings: for building in city.buildings:
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:
print(usage_zone.schedules) self.assertIsNot(len(usage_zone.schedules), 0, 'no usage_zones schedules defined')
self.assertTrue(usage_zone.schedules) for schedule in usage_zone.schedules:
self.assertIsNotNone(schedule.type)
self.assertIsNotNone(schedule.values)
self.assertIsNotNone(schedule.data_type)
self.assertIsNotNone(schedule.time_step)
self.assertIsNotNone(schedule.time_range)
self.assertIsNotNone(schedule.day_types)
def test_doe_idf_archetypes(self): def test_doe_idf_archetypes(self):
""" """