aboutsummaryrefslogtreecommitdiffstats
path: root/database.py
diff options
context:
space:
mode:
Diffstat (limited to 'database.py')
-rw-r--r--database.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/database.py b/database.py
index b31f905..60ad520 100644
--- a/database.py
+++ b/database.py
@@ -135,6 +135,21 @@ class PowerDatabase:
return out
+ def get_kwh_chart(self):
+ with self.__connection.cursor() as cursor:
+ cursor.execute("SELECT DISTINCT host FROM kwh_readings;")
+ hosts = [i[0] for i in cursor.fetchall()]
+
+ out = {}
+ for host in hosts:
+ cursor.execute("SELECT datetime, reading FROM kwh_readings WHERE host = %s ORDER BY datetime;", (host, ))
+ out[host] = cursor.fetchall()
+
+ return out
+
+def to_series(timeseriesforeach):
+ print(timeseriesforeach)
+
if __name__ == "__main__":
if not os.path.exists(".docker"):
import dotenv
@@ -144,4 +159,4 @@ if __name__ == "__main__":
host = None
with PowerDatabase(host = host) as db:
- print(db.get_watt_chart())
+ print(to_series(db.get_kwh_chart()))