Influxdb is a time series database written from scratch (in go) and independent of any other database infrastructure. Using the basic influxdb python client, we create a database, a measurement and upload some time series data
In [1]:
%%bash
pip install influxdb
In [2]:
import pandas as pd
import charts
from opengrid.library import houseprint
from influxdb import DataFrameClient
In [3]:
indbclient = DataFrameClient(host='influxdb')
In [60]:
indbclient.drop_database('opengrid')
indbclient.create_database('opengrid')
In [5]:
hp = houseprint.Houseprint()
hp.sync_tmpos()
In [63]:
for tpe in [#'electricity',
'water',
'gas']:
df = hp.get_data(sensortype=tpe, diff=False, resample='raw')
for col in df:
print("Writing data for {}, sensor {}".format(tpe, col))
try:
indbclient.write_points(dataframe=df[[col]].dropna(),
measurement=tpe,
database='opengrid')
except:
print(' Upload to influxdb failed')
In [11]:
df.info()
In [69]:
head_str = "2016-01-01 00:00:00"
head = pd.Timestamp(head_str)
tpe = 'gas'
In [70]:
%%timeit
df = indbclient.query("SELECT * from {} where time > '{}'".format(tpe, head_str), database='opengrid')[tpe]
In [71]:
df = indbclient.query("SELECT * from {} where time > '{}'".format(tpe, head_str), database='opengrid')[tpe]
df.info()
In [72]:
%%timeit
df = hp.get_data(sensortype=tpe, head=head, diff=False, resample='raw')
In [73]:
df = hp.get_data(sensortype=tpe, head=head, diff=False, resample='raw')
df.info()
In [ ]: