mirror of
https://github.com/verigak/progress.git
synced 2025-12-08 19:33:24 +00:00
Improve stats when progressing too quickly
Do not update stats if time between data points is less than `time_threshold`. This should fix the issue reported in #24.
This commit is contained in:
@@ -26,13 +26,15 @@ __version__ = '1.2'
|
||||
|
||||
class Infinite(object):
|
||||
file = stderr
|
||||
sma_window = 10
|
||||
sma_window = 10 # Simple Moving Average window
|
||||
time_threshold = 0.1 # Minimum distance between data points (in seconds)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.index = 0
|
||||
self.start_ts = time()
|
||||
self._ts = self.start_ts
|
||||
self._dt = deque(maxlen=self.sma_window)
|
||||
self._pending = 0
|
||||
for key, val in kwargs.items():
|
||||
setattr(self, key, val)
|
||||
|
||||
@@ -65,9 +67,13 @@ class Infinite(object):
|
||||
def next(self, n=1):
|
||||
if n > 0:
|
||||
now = time()
|
||||
dt = (now - self._ts) / n
|
||||
self._dt.append(dt)
|
||||
self._ts = now
|
||||
dt = now - self._ts
|
||||
if dt < self.time_threshold:
|
||||
self._pending += n
|
||||
else:
|
||||
self._dt.append(dt / (n + self._pending))
|
||||
self._ts = now
|
||||
self._pending = 0
|
||||
|
||||
self.index = self.index + n
|
||||
self.update()
|
||||
|
||||
Reference in New Issue
Block a user