diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2023-06-08 14:26:51 +0000 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2023-06-08 14:26:51 +0000 |
commit | 34aa84a8b01ede09a2e483a6db1201595c86ec96 (patch) | |
tree | d6d7078f44aa027d191a682905b5b33b6f2403a5 /api_plotter.py | |
parent | 4db18513cbf647d5e9dd7a4c20266470c4752818 (diff) | |
download | SmallYTChannelBot-34aa84a8b01ede09a2e483a6db1201595c86ec96.tar.gz SmallYTChannelBot-34aa84a8b01ede09a2e483a6db1201595c86ec96.zip |
Switched to older logging system, added plotting
Diffstat (limited to 'api_plotter.py')
-rwxr-xr-x | api_plotter.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/api_plotter.py b/api_plotter.py new file mode 100755 index 0000000..83d4f08 --- /dev/null +++ b/api_plotter.py @@ -0,0 +1,38 @@ +import matplotlib.pyplot as plt +import datetime +import math +import os +import re + +def round_to_min(dt: datetime.datetime): + return datetime.datetime( + year = dt.year, + month = dt.month, + day = dt.day, + hour = dt.hour, + minute = math.floor(dt.minute) + ) + +with open(os.path.join("logs", "api.log"), "r") as f: + s = f.read().split("\n") + +timestamps = set() + +for l in s: + x = re.search(r"^.*\tResponse: 200", l) + if x is not None: + timestamps.add(datetime.datetime.strptime(x.group()[1:24], "%Y-%m-%d %H:%M:%S,%f")) + +d = {} +for timestamp in timestamps: + nearest = round_to_min(timestamp) + + try: + d[nearest] += 1 + except KeyError: + d[nearest] = 1 + +fig, ax = plt.subplots() +ax.plot(list(d.keys()), list(d.values())) + +plt.show()
\ No newline at end of file |