From 35c50b472ffb15f32cffbc84e5dd47caab69e14b Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Fri, 30 Aug 2024 18:01:13 +0200 Subject: [PATCH] split updating nmax and checking readiness --- dap/algos/aggregation.py | 5 +++-- dap/utils/aggregator.py | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dap/algos/aggregation.py b/dap/algos/aggregation.py index 87987fd..f7d3e71 100644 --- a/dap/algos/aggregation.py +++ b/dap/algos/aggregation.py @@ -51,8 +51,9 @@ def calc_aggregate(results, data, aggregator): def calc_aggregation_ready(results, aggregator): - aggregation_max = results.get("aggregation_max") - if not aggregator.is_ready(aggregation_max): + aggregator.nmax = results.get("aggregation_max") + + if not aggregator.is_ready(): return False aggregator.reset() diff --git a/dap/utils/aggregator.py b/dap/utils/aggregator.py index d1f18f7..03f7ba8 100644 --- a/dap/utils/aggregator.py +++ b/dap/utils/aggregator.py @@ -7,6 +7,7 @@ class Aggregator: def reset(self): self.data = None self.counter = 0 + self.nmax = None def add(self, item): if self.data is None: @@ -19,13 +20,13 @@ class Aggregator: __iadd__ = add - def is_ready(self, nmax): - if nmax is None: + def is_ready(self): + if self.nmax is None: return False - return (self.counter >= nmax) + return (self.counter >= self.nmax) def __repr__(self): - return f"{self.data!r} / {self.counter}" + return f"{self.data!r} # ({self.counter} / {self.nmax})"