From 658fbdf83cdea320d35c8c5b7f5797ccf1ed4b14 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Fri, 9 Dec 2022 22:55:07 +0100 Subject: [PATCH] Filter graphs by dimension=value --- app.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 343ae0b..3e23cd2 100644 --- a/app.py +++ b/app.py @@ -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)