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)