Initial commit
This commit is contained in:
93
t.py
Normal file
93
t.py
Normal file
@ -0,0 +1,93 @@
|
||||
import time
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from influx import InfluxDBWrapper, NamedTuple
|
||||
|
||||
NAN = float('nan')
|
||||
|
||||
token = "zqDbTcMv9UizfdTj15Fx_6vBetkM5mXN56EE9CiDaFsh7O2FFWZ2X4VwAAmdyqZr3HbpIr5ixRju07-oQmxpXw=="
|
||||
|
||||
db = InfluxDBWrapper('http://pc16392:8086', token, 'linse', 'curve-test')
|
||||
|
||||
print('read(dev, [param], [start], [end], [interval])')
|
||||
|
||||
|
||||
def read(dev=None, param='value_float', start=None, end=None, interval=None, offset=None, **tags):
|
||||
now = time.time()
|
||||
if start is None:
|
||||
start = now - 1800
|
||||
elif start < 0:
|
||||
start += now
|
||||
measurement = dev
|
||||
# measurement = f'nicos/{dev}' if dev else None
|
||||
print('QUERY', measurement, param, start, end, interval)
|
||||
tables = db.query(measurement, param, start, end, interval, **tags)
|
||||
sec = time.time()-now
|
||||
print(f'query took {sec:.3f} seconds')
|
||||
now = time.time()
|
||||
result = {}
|
||||
if offset is None:
|
||||
offset = start
|
||||
elif offset == 'now':
|
||||
offset = now
|
||||
for table in tables:
|
||||
for rec in table.records:
|
||||
# value = None if rec['expired'] == 'True' else rec['_value']
|
||||
value = rec['_value']
|
||||
ts = rec['_time'].timestamp()
|
||||
key = f"{rec['_measurement']}:{rec['_field']}"
|
||||
# print(rec['expired'])
|
||||
result.setdefault(key, []).append(((rec['_time'].timestamp() - offset), value))
|
||||
sec = time.time()-now
|
||||
print(f'rearrange took {sec:.3f} seconds')
|
||||
pts = sum(len(v) for v in result.values())
|
||||
print(pts, 'points', round(pts / sec / 1000), 'points/ms')
|
||||
for curve, data in result.items():
|
||||
result[curve] = sorted(data)
|
||||
return result
|
||||
|
||||
|
||||
def summ(result):
|
||||
for meas, curves in result.items():
|
||||
print(meas)
|
||||
for field, curve in curves.items():
|
||||
timerange = '..'.join([time.strftime('%m-%d %H:%M:%S', time.localtime(curve[i][0])) for i in [0,-1]])
|
||||
print(' ', timerange, len(curve[:,0]), field)
|
||||
|
||||
|
||||
def getlast(*args, **kwds):
|
||||
for meas, params in db.getLast(*args, **kwds).items():
|
||||
print('---', meas)
|
||||
for key, (value, error) in params.items():
|
||||
if key[0].startswith('?'):
|
||||
continue
|
||||
if error:
|
||||
print(key, 'ERROR', error)
|
||||
else:
|
||||
print(key, value)
|
||||
|
||||
|
||||
def curves(*args, offset=0, **kwds):
|
||||
result = db.curves(*args, **kwds)
|
||||
for key, curve in result.items():
|
||||
print('---', key)
|
||||
for row in curve:
|
||||
print(round(row[0]-offset, db.timedig), row[1:])
|
||||
|
||||
|
||||
start = time.mktime((2024, 5, 30, 0, 0, 0, 0, 0, -1))
|
||||
end = time.mktime((2024, 6, 19, 0, 0, 0, 0, 0, -1))
|
||||
DAY = 24 * 3600
|
||||
now = time.time()
|
||||
|
||||
|
||||
def prt(key, *args, offset=0, scale=1, **kwds):
|
||||
for key, curve in db.getCurve(key, *args, **kwds).items():
|
||||
print('---', key)
|
||||
for t, v in curve:
|
||||
print(t, v)
|
||||
|
||||
|
||||
def test():
|
||||
pass
|
||||
|
Reference in New Issue
Block a user