diff --git a/bugsink/period_counter.py b/bugsink/period_counter.py index 1ac74d5..751020c 100644 --- a/bugsink/period_counter.py +++ b/bugsink/period_counter.py @@ -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 { diff --git a/bugsink/tests.py b/bugsink/tests.py index 25d3163..79cc715 100644 --- a/bugsink/tests.py +++ b/bugsink/tests.py @@ -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) diff --git a/performance/some_script.py b/performance/some_script.py index 036bd4b..4709fca 100644 --- a/performance/some_script.py +++ b/performance/some_script.py @@ -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(