45 lines
1 KiB
Python
45 lines
1 KiB
Python
|
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()
|