split updating nmax and checking readiness

This commit is contained in:
2024-08-30 18:01:13 +02:00
parent a65553e13a
commit 35c50b472f
2 changed files with 8 additions and 6 deletions

View File

@ -51,8 +51,9 @@ def calc_aggregate(results, data, aggregator):
def calc_aggregation_ready(results, aggregator): def calc_aggregation_ready(results, aggregator):
aggregation_max = results.get("aggregation_max") aggregator.nmax = results.get("aggregation_max")
if not aggregator.is_ready(aggregation_max):
if not aggregator.is_ready():
return False return False
aggregator.reset() aggregator.reset()

View File

@ -7,6 +7,7 @@ class Aggregator:
def reset(self): def reset(self):
self.data = None self.data = None
self.counter = 0 self.counter = 0
self.nmax = None
def add(self, item): def add(self, item):
if self.data is None: if self.data is None:
@ -19,13 +20,13 @@ class Aggregator:
__iadd__ = add __iadd__ = add
def is_ready(self, nmax): def is_ready(self):
if nmax is None: if self.nmax is None:
return False return False
return (self.counter >= nmax) return (self.counter >= self.nmax)
def __repr__(self): def __repr__(self):
return f"{self.data!r} / {self.counter}" return f"{self.data!r} # ({self.counter} / {self.nmax})"