pywatts/pywatts/db.py

48 lines
988 B
Python
Raw Normal View History

2018-05-29 15:17:49 +02:00
import pandas as pd
from peewee import *
from playhouse import sqlite_ext
2018-05-17 14:19:05 +02:00
from playhouse.sqlite_ext import SqliteExtDatabase
2018-08-07 15:04:23 +02:00
import os.path
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
2018-08-09 11:54:33 +02:00
db_path = os.path.join(BASE_DIR, "pywatts.db")
2018-08-07 15:04:23 +02:00
db = SqliteExtDatabase(db_path)
class WeatherStation(Model):
longitude = IntegerField()
latitude = IntegerField()
location = CharField()
elevation = IntegerField()
city = CharField()
state = CharField()
id = CharField(unique=True)
2018-05-17 14:19:05 +02:00
class Meta:
database = db
class Result(Model):
station = ForeignKeyField(WeatherStation)
dc_output = sqlite_ext.JSONField()
temperature = sqlite_ext.JSONField()
wind_speed = sqlite_ext.JSONField()
2018-05-17 14:19:05 +02:00
class Meta:
database = db
2018-05-29 15:17:49 +02:00
def rows_to_df(indices):
dcs = []
db.connect()
for result in Result.select().where(Result.id << indices):
dcs += result.dc_output
db.close()
return pd.DataFrame(
2018-09-12 17:52:05 +02:00
{'dc': dcs})