From cebed01f35683211a8259a47644c90f7dae14588 Mon Sep 17 00:00:00 2001 From: reedts Date: Tue, 29 May 2018 15:17:49 +0200 Subject: [PATCH] Make results retrievable per row index --- pywatts/db.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pywatts/db.py b/pywatts/db.py index f505ecb..4374867 100644 --- a/pywatts/db.py +++ b/pywatts/db.py @@ -1,3 +1,4 @@ +import pandas as pd from peewee import * from playhouse import sqlite_ext from playhouse.sqlite_ext import SqliteExtDatabase @@ -27,3 +28,23 @@ class Result(Model): class Meta: database = db + +def rows_to_df(indices): + temps = [] + dcs = [] + winds = [] + + db.connect() + + for result in Result.select().where(Result.id << indices): + temps += result.temperature + dcs += result.dc_output + winds += result.wind_speed + + db.close() + + return pd.DataFrame( + {'temp': temps, + 'dc': dcs, + 'wind': winds + })