mirror of
https://github.com/verigak/progress.git
synced 2025-12-10 12:15:34 +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):
|
class Infinite(object):
|
||||||
file = stderr
|
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):
|
def __init__(self, *args, **kwargs):
|
||||||
self.index = 0
|
self.index = 0
|
||||||
self.start_ts = time()
|
self.start_ts = time()
|
||||||
self._ts = self.start_ts
|
self._ts = self.start_ts
|
||||||
self._dt = deque(maxlen=self.sma_window)
|
self._dt = deque(maxlen=self.sma_window)
|
||||||
|
self._pending = 0
|
||||||
for key, val in kwargs.items():
|
for key, val in kwargs.items():
|
||||||
setattr(self, key, val)
|
setattr(self, key, val)
|
||||||
|
|
||||||
@@ -65,9 +67,13 @@ class Infinite(object):
|
|||||||
def next(self, n=1):
|
def next(self, n=1):
|
||||||
if n > 0:
|
if n > 0:
|
||||||
now = time()
|
now = time()
|
||||||
dt = (now - self._ts) / n
|
dt = now - self._ts
|
||||||
self._dt.append(dt)
|
if dt < self.time_threshold:
|
||||||
self._ts = now
|
self._pending += n
|
||||||
|
else:
|
||||||
|
self._dt.append(dt / (n + self._pending))
|
||||||
|
self._ts = now
|
||||||
|
self._pending = 0
|
||||||
|
|
||||||
self.index = self.index + n
|
self.index = self.index + n
|
||||||
self.update()
|
self.update()
|
||||||
|
|||||||
Reference in New Issue
Block a user