reorder structure
This commit is contained in:
committed by
Thomas Klaehn
parent
2fc4339f61
commit
4d76bc4e88
20
src/light_data/light_data.py
Normal file
20
src/light_data/light_data.py
Normal file
@@ -0,0 +1,20 @@
|
||||
class light_data:
|
||||
def __init__(self, length=10):
|
||||
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 average(self):
|
||||
if len(self.data) != self.max:
|
||||
return None
|
||||
return sum(self.data) / self.max
|
||||
|
||||
def length(self):
|
||||
return len(self.data)
|
||||
Reference in New Issue
Block a user