Timeout for current data implemented
This commit is contained in:
parent
1819df790c
commit
26a4ed180f
14
__init__.py
14
__init__.py
@ -1,7 +1,11 @@
|
||||
import logging
|
||||
import numbers
|
||||
import os
|
||||
import time
|
||||
|
||||
logger_name = 'HELPERS'
|
||||
logger = logging.getLogger(logger_name)
|
||||
|
||||
|
||||
class continues_statistic(dict):
|
||||
KEY_SINGLE_VALUE = '_'
|
||||
@ -88,9 +92,11 @@ class ringbuffer(list):
|
||||
|
||||
|
||||
class data_collector(object):
|
||||
def __init__(self, bufferlength):
|
||||
def __init__(self, bufferlength, current_max_age=300.):
|
||||
self.__current_max_age__ = current_max_age
|
||||
self.__current_data_rinbuffer__ = ringbuffer(length=3)
|
||||
#
|
||||
self.__last_add_data__ = 0
|
||||
self.__continues_statistic__ = None
|
||||
self.__yesterdays_statistic__ = None
|
||||
self.__measurement_day__ = None
|
||||
@ -114,6 +120,8 @@ class data_collector(object):
|
||||
|
||||
|
||||
def add_data(self, **kwargs):
|
||||
logger.debug('Got data %s', repr(kwargs))
|
||||
self.__last_add_data__ = time.time()
|
||||
self.__current_data_rinbuffer__.append(kwargs)
|
||||
self.__process_continues_statistic__(**kwargs)
|
||||
self.__ringbuffer__.append(kwargs)
|
||||
@ -121,6 +129,10 @@ class data_collector(object):
|
||||
@property
|
||||
def current(self):
|
||||
if len(self.__current_data_rinbuffer__) == 0:
|
||||
logger.info('No data available, yet.')
|
||||
return None
|
||||
elif time.time() > self.__last_add_data__ + self.__current_max_age__:
|
||||
logger.info('Data max age reached. No current data available.')
|
||||
return None
|
||||
elif len(self.__current_data_rinbuffer__) < 3:
|
||||
return self.__current_data_rinbuffer__[-1]
|
||||
|
Loading…
x
Reference in New Issue
Block a user