Skip to content

Commit

Permalink
Fixes schedule order + uses calendar modules instead of an array
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelduchesne committed Jan 6, 2020
1 parent 116636f commit 84211f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
35 changes: 14 additions & 21 deletions archetypal/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging as lg
import tempfile
from datetime import datetime, timedelta
from itertools import groupby

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -911,17 +912,13 @@ def to_year_week_day(self, values=None, idf=None):
dict_week[week_id]["day_{}".format(i)] = key

# Create idf_objects for schedule:week:daily
list_day_of_week = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
]
ordered_day_n = np.array([6, 0, 1, 2, 3, 4, 5])
ordered_day_n = np.roll(ordered_day_n, self.startDayOfTheWeek)
# We use the calendar module to set the week days order
import calendar

# initialize the calendar object
c = calendar.Calendar(firstweekday=self.startDayOfTheWeek)

# Create ep_weeks list and iterate over dict_week
ep_weeks = []
for week_id in dict_week:
ep_week = self.idf.add_object(
Expand All @@ -930,10 +927,10 @@ def to_year_week_day(self, values=None, idf=None):
**dict(
Name=week_id,
**{
"{}_ScheduleDay_Name".format(weekday): dict_week[week_id][
"day_{}".format(i)
]
for i, weekday in zip(ordered_day_n, list_day_of_week)
"{}_ScheduleDay_Name".format(
calendar.day_name[day_num]
): dict_week[week_id]["day_{}".format(day_num)]
for day_num in c.iterweekdays()
},
Holiday_ScheduleDay_Name=dict_week[week_id]["day_6"],
SummerDesignDay_ScheduleDay_Name=dict_week[week_id]["day_1"],
Expand All @@ -944,17 +941,13 @@ def to_year_week_day(self, values=None, idf=None):
)
ep_weeks.append(ep_week)

import itertools

blocks = {}
from_date = datetime(self.year, 1, 1)
bincount = [
sum(1 for _ in group) for key, group in itertools.groupby(nws + 1) if key
]
bincount = [sum(1 for _ in group) for key, group in groupby(nws + 1) if key]
week_order = {
i: v
for i, v in enumerate(
np.array([key for key, group in itertools.groupby(nws + 1) if key]) - 1
np.array([key for key, group in groupby(nws + 1) if key]) - 1
)
}
for i, (week_n, count) in enumerate(zip(week_order, bincount)):
Expand Down
1 change: 1 addition & 0 deletions tests/test_schedules.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import pytest

from archetypal import Schedule, load_idf, copy_file, run_eplus, UmiSchedule, config


Expand Down

0 comments on commit 84211f6

Please sign in to comment.