Implemented simple plotter

This commit is contained in:
Maximilian Giller 2024-05-02 20:06:47 +02:00
parent 5bc507f38a
commit 21376509ff
2 changed files with 47 additions and 0 deletions

44
bettwaage-plotter/main.py Normal file
View file

@ -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()

View file

@ -0,0 +1,3 @@
matplotlib
requests
numpy