Skip to content

Instantly share code, notes, and snippets.

@kojiromike
Created February 27, 2014 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kojiromike/9258780 to your computer and use it in GitHub Desktop.
Save kojiromike/9258780 to your computer and use it in GitHub Desktop.
from collections import deque
last3 = deque(maxlen=3)
def pings():
while True:
yield timepassed() * 17000 # Assume timepassed is updated somehow
# This may seem not D.R.Y., but there are only three…
ping = next(pings) # ;) Who knows how the pings are gotten
print("Current average: " + ping) # avg = ping/1
last3.append(ping)
last3.append(next(pings))
print("Current average: " + sum(last3) / 2)
while True:
last3.append(next(pings))
print("Current average: " + sum(last3) / 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment