40146343ea
Signed-off-by: Thomas Klaehn <thomas.klaehn@u-blox.com>
33 lines
658 B
Python
33 lines
658 B
Python
'''
|
|
Created on Mar 30, 2017
|
|
|
|
@author: tkla
|
|
'''
|
|
|
|
class DataBuffer(object):
|
|
def __init__(self, length):
|
|
self.__max = length
|
|
self.__data = []
|
|
|
|
def push(self, element):
|
|
if self.__max == 0:
|
|
return False
|
|
if len(self.__data) == self.__max:
|
|
_ = self.__data.pop(0)
|
|
self.__data.append(element)
|
|
return True
|
|
|
|
def get(self):
|
|
return self.__data
|
|
|
|
def average(self):
|
|
if len(self.__data) is 0:
|
|
return None
|
|
return sum(self.__data) / len(self.__data)
|
|
|
|
def length(self):
|
|
return len(self.__data)
|
|
|
|
def clear(self):
|
|
self.__data = []
|