HomeServer/plot_meross.py

25 lines
563 B
Python
Raw Normal View History

2023-09-19 08:52:12 +00:00
import sqlite3
import matplotlib.pyplot as plt
2023-09-20 04:46:07 +00:00
import matplotlib.dates as mdates
2023-09-19 08:52:12 +00:00
import numpy as np
2023-09-20 04:46:07 +00:00
import datetime
2023-09-19 08:52:12 +00:00
con = sqlite3.connect("data.db")
cur = con.cursor()
res = cur.execute("SELECT time, watts FROM data")
x_values = []
y_values = []
for time, watts in res:
2023-09-20 04:46:07 +00:00
x_values.append(datetime.datetime.fromtimestamp(time / 1000))
2023-09-19 08:52:12 +00:00
y_values.append(watts)
2023-09-20 04:46:07 +00:00
fig, ax = plt.subplots()
ax.plot(x_values, y_values)
plt.tick_params(rotation=45)
ax.xaxis.set_major_formatter(mdates.DateFormatter("%H:%M - %d.%m"))
2023-09-19 08:52:12 +00:00
2023-09-20 04:46:07 +00:00
plt.ylim([0, max(y_values) + 50])
2023-09-19 08:52:12 +00:00
plt.show()