From 21376509ffaceb9fc48c56eb28f935e111c99256 Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Thu, 2 May 2024 20:06:47 +0200 Subject: [PATCH] Implemented simple plotter --- bettwaage-plotter/main.py | 44 ++++++++++++++++++++++++++++++ bettwaage-plotter/requirements.txt | 3 ++ 2 files changed, 47 insertions(+) create mode 100644 bettwaage-plotter/main.py create mode 100644 bettwaage-plotter/requirements.txt diff --git a/bettwaage-plotter/main.py b/bettwaage-plotter/main.py new file mode 100644 index 0000000..abff5be --- /dev/null +++ b/bettwaage-plotter/main.py @@ -0,0 +1,44 @@ +import requests +import matplotlib.pyplot as plt +import numpy as np +from datetime import datetime + +history_url = "http://192.168.178.84:9587/bettwaage/history" + +data = requests.get(history_url) + +data = data.json() + + +# make data +x = [datetime.strptime(d["timestamp"], "%Y-%m-%d %H:%M:%S.%f") for d in data] +max_time = max(x) +x = [(max_time - d).total_seconds() for d in x] + +total = [d["total"] for d in data] +tl = [d["tl"] for d in data] +tr = [d["tr"] for d in data] +bl = [d["bl"] for d in data] +br = [d["br"] for d in data] + + +fig, ax1 = plt.subplots() + +color = "tab:red" +ax1.set_xlabel("time (s)") +ax1.set_ylabel("Total", color=color) +ax1.plot(x, total, color=color) + +ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis + +color = "tab:blue" +ax2.set_ylabel("Legs", color=color) # we already handled the x-label with ax1 +ax2.plot(x, tl, color="tab:red") +ax2.plot(x, tr, color="tab:green") +ax2.plot(x, bl, color="tab:purple") +ax2.plot(x, br, color="tab:orange") + +fig.tight_layout() # otherwise the right y-label is slightly clipped +plt.show() + +plt.show() diff --git a/bettwaage-plotter/requirements.txt b/bettwaage-plotter/requirements.txt new file mode 100644 index 0000000..74599f5 --- /dev/null +++ b/bettwaage-plotter/requirements.txt @@ -0,0 +1,3 @@ +matplotlib +requests +numpy