50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
import requests
|
|
import matplotlib.pyplot as plt
|
|
from datetime import datetime
|
|
import json
|
|
|
|
|
|
file_path = "history.json"
|
|
history_url = "http://192.168.178.84:9587/bettwaage/history"
|
|
|
|
convert_time_to_seconds = True
|
|
|
|
# Script
|
|
data = None
|
|
|
|
if file_path is None:
|
|
data = requests.get(history_url)
|
|
data = data.json()
|
|
else:
|
|
with open(file_path, "r") as fp:
|
|
data = json.load(fp)
|
|
|
|
# make data
|
|
x = [d["timestamp"] for d in data]
|
|
x = [datetime.strptime(d, "%Y-%m-%d %H:%M:%S.%f") for d in x]
|
|
|
|
if convert_time_to_seconds:
|
|
max_time = max(x)
|
|
x = [(d - max_time).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()
|
|
|
|
ax1.set_xlabel("Time (s)")
|
|
ax1.set_ylabel("Weight (kg)")
|
|
|
|
line_total = ax1.plot(x, total, color="tab:blue")
|
|
line_tl = ax1.plot(x, tl, color="tab:red")
|
|
line_tr = ax1.plot(x, tr, color="tab:green")
|
|
line_bl = ax1.plot(x, bl, color="tab:orange")
|
|
line_br = ax1.plot(x, br, color="tab:purple")
|
|
|
|
ax1.legend(["Total", "Top Left", "Top Right", "Bottom Left", "Bottom Right"])
|
|
|
|
plt.show()
|