Filter graphs by dimension=value

This commit is contained in:
Peter J. Holzer 2022-12-09 22:55:07 +01:00
parent cf32c72b8f
commit 658fbdf83c
1 changed files with 8 additions and 3 deletions

11
app.py
View File

@ -60,13 +60,16 @@ def list_dimensions():
@app.route("/search") @app.route("/search")
def search(): def search():
log.debug("search: %s", request.args) log.debug("search: %s", request.args)
return jsonify(_search())
def _search():
timeseries = None timeseries = None
with open("data/.index") as fh: with open("data/.index") as fh:
fcntl.flock(fh, fcntl.LOCK_SH) fcntl.flock(fh, fcntl.LOCK_SH)
index = json.load(fh) index = json.load(fh)
for k, v in request.args.lists(): for k, v in request.args.lists():
log.debug("search: %s -> %s", k, v) log.debug("search: %s -> %s", k, v)
if timeseries == None: if timeseries is None:
timeseries = set() timeseries = set()
log.debug("search: %s: %s", k, index[k]) log.debug("search: %s: %s", k, index[k])
for m in v: for m in v:
@ -77,8 +80,7 @@ def search():
filter |= set(index[k][m]) filter |= set(index[k][m])
timeseries &= filter timeseries &= filter
results = list(timeseries) results = list(timeseries)
return jsonify(results) return results
def verify_node(d): def verify_node(d):
node = d["auth"]["node"] node = d["auth"]["node"]
@ -112,6 +114,9 @@ def verify_node(d):
@app.get("/v") @app.get("/v")
def visualize(): def visualize():
timeseries_ids = request.args.getlist("ts") timeseries_ids = request.args.getlist("ts")
if not timeseries_ids:
timeseries_ids = _search()
log.debug("timeseries_ids = %s", timeseries_ids)
timeseries_data = [] timeseries_data = []
for id in timeseries_ids: for id in timeseries_ids:
ts = LTS(id=id) ts = LTS(id=id)