Skip to content

Commit

Permalink
Adds ability to scale a schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelduchesne committed Dec 8, 2021
1 parent 48768f0 commit 4b4c40a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions archetypal/schedule.py
Expand Up @@ -1316,6 +1316,14 @@ def startDate(self):
year = get_year_for_first_weekday(self.startDayOfTheWeek)
return datetime(year, 1, 1)

def scale(self, diversity=0.1):
"""Scale the schedule values by a diversity factor around the average."""
average = np.average(self.Values)
new_values = ((average - self.Values) * diversity) + self.Values

self.Values = new_values
return self

def plot(self, **kwargs):
"""Plot the schedule. Implements the .loc accessor on the series object.
Expand Down
8 changes: 8 additions & 0 deletions tests/test_schedules.py
Expand Up @@ -47,6 +47,14 @@ def schedules_in_necb_specific(self, config):
s = Schedule.from_epbunch(epbunch, start_day_of_the_week=0)
yield s

def test_scale(self, schedules_in_necb_specific):
before_sum = sum(schedules_in_necb_specific.Values)
ax = schedules_in_necb_specific.series.iloc[0:24].plot()
assert pytest.approx(
before_sum, sum(schedules_in_necb_specific.scale(0.1).Values)
)
schedules_in_necb_specific.series.iloc[0:24].plot(ax=ax)

def test_plot(self, schedules_in_necb_specific):
schedules_in_necb_specific.plot(drawstyle="steps-post")

Expand Down

0 comments on commit 4b4c40a

Please sign in to comment.