Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,21 @@
|
|||
from collections import deque
|
||||
|
||||
class Simplemovingaverage():
|
||||
def __init__(self, period):
|
||||
assert period == int(period) and period > 0, "Period must be an integer >0"
|
||||
self.period = period
|
||||
self.stream = deque()
|
||||
|
||||
def __call__(self, n):
|
||||
stream = self.stream
|
||||
stream.append(n) # appends on the right
|
||||
streamlength = len(stream)
|
||||
if streamlength > self.period:
|
||||
stream.popleft()
|
||||
streamlength -= 1
|
||||
if streamlength == 0:
|
||||
average = 0
|
||||
else:
|
||||
average = sum( stream ) / streamlength
|
||||
|
||||
return average
|
||||
Loading…
Add table
Add a link
Reference in a new issue