Skip to content

Commit

Permalink
Handle all cases for current and previous buckets and scale
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jun 20, 2024
1 parent aa654de commit 4d83990
Showing 1 changed file with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -809,16 +809,34 @@ def collect(

# TODO, implement this case

if current_value_positive is None:
# This happens if collect is called before aggregate is
# called or if collect is called twice with no calls to
# aggregate in between.
if (
current_value_positive is None and
self._previous_cumulative_value_positive is None
):
# This happens if collect is called for the first time
# and aggregate has not yet been called.
current_value_positive = Buckets()
if current_value_negative is None:
self._previous_cumulative_value_positive = (
current_value_positive.copy_empty()
)
if (
current_value_negative is None and
self._previous_cumulative_value_negative is None
):
current_value_negative = Buckets()
self._previous_cumulative_value_negative = (
current_value_negative.copy_empty()
)
if scale is None and self._previous_scale is None:
scale = self._mapping.scale
self._previous_scale = scale

if self._previous_cumulative_value_positive is None:
# This happens when collect is called the very first time.
if (
current_value_positive is not None and
self._previous_cumulative_value_positive is None
):
# This happens when collect is called the very first time
# and aggregate has been called before.

# We need previous buckets to add them to the current ones.
# When collect is called for the first time, there are no
Expand All @@ -839,13 +857,33 @@ def collect(
self._previous_cumulative_value_positive = (
current_value_positive.copy_empty()
)
if self._previous_cumulative_value_negative is None:
if (
current_value_negative is not None and
self._previous_cumulative_value_negative is None
):
self._previous_cumulative_value_negative = (
current_value_negative.copy_empty()
)
if self._previous_scale is None:
if scale is not None and self._previous_scale is None:
self._previous_scale = scale

if (
current_value_positive is None and
self._previous_cumulative_value_positive is not None
):
current_value_positive = (
self._previous_cumulative_value_positive.copy_empty()
)
if (
current_value_negative is None and
self._previous_cumulative_value_negative is not None
):
current_value_negative = (
self._previous_cumulative_value_negative.copy_empty()
)
if scale is None and self._previous_scale is not None:
scale = self._previous_scale

min_scale = min(self._previous_scale, scale)

low_positive, high_positive = (
Expand Down

0 comments on commit 4d83990

Please sign in to comment.