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:
parent
2b54a3862e
commit
5ab325ea56
36
app.py
36
app.py
|
@ -1,3 +1,4 @@
|
||||||
|
import fcntl
|
||||||
import hmac
|
import hmac
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
@ -44,6 +45,41 @@ def get_timeseries(id):
|
||||||
abort(404)
|
abort(404)
|
||||||
return jsonify({"description": ts.description, "data": ts.data})
|
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):
|
def verify_node(d):
|
||||||
node = d["auth"]["node"]
|
node = d["auth"]["node"]
|
||||||
timestamp = d["auth"]["timestamp"]
|
timestamp = d["auth"]["timestamp"]
|
||||||
|
|
Loading…
Reference in New Issue