Skip to content

Instantly share code, notes, and snippets.

@seanbreckenridge
Created June 28, 2019 03:16
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 seanbreckenridge/fe58a62dd60f36599e36ff1645abc8c1 to your computer and use it in GitHub Desktop.
Save seanbreckenridge/fe58a62dd60f36599e36ff1645abc8c1 to your computer and use it in GitHub Desktop.
LagTracker
# Didnt end up using this, but it could be useful in the future.
class LagTracker:
"""A class representing a moving average; lag time between sending messages"""
__slots__ = ["latency", "cur_avg"]
def __init__(self):
self.latency = []
self.cur_avg = 0
def add(self, n):
self.latency.append(n)
self.cur_avg = self.cur_avg + (n - self.cur_avg)/len(self.latency)
def __str__(self): return f"Lag({self.cur_avg}: {str(self.latency)})"
def __repr__(self): return str(self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment