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")
def search():
log.debug("search: %s", request.args)
return jsonify(_search())
def _search():
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:
if timeseries is None:
timeseries = set()
log.debug("search: %s: %s", k, index[k])
for m in v:
@ -77,8 +80,7 @@ def search():
filter |= set(index[k][m])
timeseries &= filter
results = list(timeseries)
return jsonify(results)
return results
def verify_node(d):
node = d["auth"]["node"]
@ -112,6 +114,9 @@ def verify_node(d):
@app.get("/v")
def visualize():
timeseries_ids = request.args.getlist("ts")
if not timeseries_ids:
timeseries_ids = _search()
log.debug("timeseries_ids = %s", timeseries_ids)
timeseries_data = []
for id in timeseries_ids:
ts = LTS(id=id)