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"]