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:
Georgios Verigakis
2016-03-06 17:37:49 +02:00
parent 0435756cf7
commit 61ac9b6980

View File

@@ -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()