Created
June 28, 2019 03:16
-
-
Save purarue/fe58a62dd60f36599e36ff1645abc8c1 to your computer and use it in GitHub Desktop.
LagTracker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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