2017-03-30 13:15:00 +00:00
|
|
|
'''
|
|
|
|
Created on Mar 30, 2017
|
|
|
|
|
|
|
|
@author: tkla
|
|
|
|
'''
|
2016-12-20 21:09:01 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-04-09 06:24:40 +00:00
|
|
|
def get(self):
|
|
|
|
return self.__data
|
|
|
|
|
2016-12-20 21:09:01 +00:00
|
|
|
def average(self):
|
2017-03-30 12:09:49 +00:00
|
|
|
if len(self.__data) is 0:
|
2016-12-20 21:09:01 +00:00
|
|
|
return None
|
2017-03-30 09:05:31 +00:00
|
|
|
return sum(self.__data) / len(self.__data)
|
2016-12-20 21:09:01 +00:00
|
|
|
|
|
|
|
def length(self):
|
|
|
|
return len(self.__data)
|
|
|
|
|
|
|
|
def clear(self):
|
|
|
|
self.__data = []
|