From 5ab325ea568f74f13132697e6836772acc1ac2de Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Tue, 6 Sep 2022 22:47:52 +0200 Subject: [PATCH] List dimensions and members and search for timeseries by the same This should be enough to implement a simple query tool. --- app.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/app.py b/app.py index f6e6d0e..bab18ef 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,4 @@ +import fcntl import hmac import json import logging @@ -44,6 +45,41 @@ def get_timeseries(id): abort(404) 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): node = d["auth"]["node"] timestamp = d["auth"]["timestamp"]