List dimensions and members and search for timeseries by the same

This should be enough to implement a simple query tool.
This commit is contained in:
Peter J. Holzer 2022-09-06 22:47:52 +02:00
parent 2b54a3862e
commit 5ab325ea56
1 changed files with 36 additions and 0 deletions

36
app.py
View File

@ -1,3 +1,4 @@
import fcntl
import hmac
import json
import logging
@ -44,6 +45,41 @@ def get_timeseries(id):
abort(404)
return jsonify({"description": ts.description, "data": ts.data})
@app.route("/dimensions")
def list_dimensions():
with open("data/.index") as fh:
fcntl.flock(fh, fcntl.LOCK_SH)
index = json.load(fh)
# Just return the number of timeseries for each dimension/member, not
# the timeseries themselves
for d in index.keys():
for m in index[d].keys():
index[d][m] = len(index[d][m])
return jsonify(index)
@app.route("/search")
def search():
log.debug("search: %s", request.args)
timeseries = None
with open("data/.index") as fh:
fcntl.flock(fh, fcntl.LOCK_SH)
index = json.load(fh)
for k, v in request.args.lists():
log.debug("search: %s -> %s", k, v)
if timeseries == None:
timeseries = set()
log.debug("search: %s: %s", k, index[k])
for m in v:
timeseries |= set(index[k][m])
else:
filter = set()
for m in v:
filter |= set(index[k][m])
timeseries &= filter
results = list(timeseries)
return jsonify(results)
def verify_node(d):
node = d["auth"]["node"]
timestamp = d["auth"]["timestamp"]