Rename -> initial_event_state

This commit is contained in:
Klaas van Schelven
2024-01-04 20:20:11 +01:00
parent bf9c40c0e2
commit 02180d391d
3 changed files with 11 additions and 11 deletions

View File

@@ -99,18 +99,18 @@ class PeriodCounter(object):
wbt()
def add_event_listener(self, period_name, how_many_periods, gte_threshold, when_becomes_true, when_becomes_false,
event_state=None, tup=None):
initial_event_state=None, tup=None):
if len([arg for arg in [event_state, tup] if arg is None]) != 1:
if len([arg for arg in [initial_event_state, tup] if arg is None]) != 1:
# either be explicit, or let us deduce
raise ValueError("Provide exactly one of (event_state, tup)")
raise ValueError("Provide exactly one of (initial_event_state, tup)")
tl = self._tl_for_period(period_name)
if event_state is None:
event_state = self._get_event_state(tup, tl, how_many_periods, gte_threshold)
if initial_event_state is None:
initial_event_state = self._get_event_state(tup, tl, how_many_periods, gte_threshold)
self.event_listeners[tl][(how_many_periods, gte_threshold)] = \
(when_becomes_true, when_becomes_false, event_state)
(when_becomes_true, when_becomes_false, initial_event_state)
def _tl_for_period(self, period_name):
return {

View File

@@ -57,7 +57,7 @@ class PeriodCounterTestCase(TestCase):
pc = PeriodCounter()
wbt = callback()
wbf = callback()
pc.add_event_listener("total", 1, 2, wbt, wbf, event_state=False)
pc.add_event_listener("total", 1, 2, wbt, wbf, initial_event_state=False)
# first inc: should not yet trigger
pc.inc(timepoint)
@@ -79,7 +79,7 @@ class PeriodCounterTestCase(TestCase):
pc = PeriodCounter()
wbt = callback()
wbf = callback()
pc.add_event_listener("year", 2, 3, wbt, wbf, event_state=False)
pc.add_event_listener("year", 2, 3, wbt, wbf, initial_event_state=False)
pc.inc(tp_2020)
self.assertEquals(0, wbt.calls)

View File

@@ -77,9 +77,9 @@ def print_thoughts_about_event_evaluation():
# Project. In this setup, the monthly maximum is spread out in a way that the smaller parts are a bit more than just
# splitting things equally. Why? We want some flexibility for bursts of activity without using up the entire budget
# for a longer time all at once.
pc.add_event_listener("day", 30, 10_000, noop, noop, event_state=False) # 1 month rolling window
pc.add_event_listener("hour", 24, 1_000, noop, noop, event_state=False) # 1 day rolling window
pc.add_event_listener("minute", 60, 200, noop, noop, event_state=False) # 1 hour rolling window
pc.add_event_listener("day", 30, 10_000, noop, noop, initial_event_state=False) # 1 month rolling window
pc.add_event_listener("hour", 24, 1_000, noop, noop, initial_event_state=False) # 1 day rolling window
pc.add_event_listener("minute", 60, 200, noop, noop, initial_event_state=False) # 1 hour rolling window
# make sure the pc has some data before we start. we pick a 1-month period to match the listeners in the above.
for point in buckets_to_points_in_time(