HomeServer/plot_meross.py
2023-09-20 06:46:07 +02:00

25 lines
No EOL
563 B
Python

import sqlite3
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
import datetime
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:
x_values.append(datetime.datetime.fromtimestamp(time / 1000))
y_values.append(watts)
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"))
plt.ylim([0, max(y_values) + 50])
plt.show()