Retrieve a single timeseries by id
This commit is contained in:
parent
5eb0edaaf9
commit
a8bfb68c8c
6
app.py
6
app.py
|
@ -36,6 +36,12 @@ def report():
|
||||||
n_ts += 1
|
n_ts += 1
|
||||||
return jsonify({ "success": True, "timeseries": n_ts, "datapoints": n_dp })
|
return jsonify({ "success": True, "timeseries": n_ts, "datapoints": n_dp })
|
||||||
|
|
||||||
|
@app.route("/ts/<id>")
|
||||||
|
def get_timeseries(id):
|
||||||
|
breakpoint()
|
||||||
|
ts = LTS(id=id)
|
||||||
|
return jsonify({"description": ts.description, "data": ts.data})
|
||||||
|
|
||||||
def verify_node(d):
|
def verify_node(d):
|
||||||
node = d["auth"]["node"]
|
node = d["auth"]["node"]
|
||||||
timestamp = d["auth"]["timestamp"]
|
timestamp = d["auth"]["timestamp"]
|
||||||
|
|
|
@ -11,19 +11,21 @@ class LTS:
|
||||||
base_dir = "data"
|
base_dir = "data"
|
||||||
limit = 1000
|
limit = 1000
|
||||||
|
|
||||||
def __init__(self, description):
|
def __init__(self, description=None, id=None):
|
||||||
# Oh, I think we need to be able to load by hash, too
|
if description:
|
||||||
canonical_description = {x: description[x] for x in sorted(description.keys())}
|
canonical_description = {x: description[x] for x in sorted(description.keys())}
|
||||||
self.description = canonical_description
|
self.description = canonical_description
|
||||||
serialized_description = json.dumps(canonical_description)
|
serialized_description = json.dumps(canonical_description)
|
||||||
m = hashlib.sha256()
|
m = hashlib.sha256()
|
||||||
m.update(bytes(serialized_description, encoding="UTF-8"))
|
m.update(bytes(serialized_description, encoding="UTF-8"))
|
||||||
self.filename = self.base_dir + "/" + m.hexdigest()
|
id = m.hexdigest()
|
||||||
|
self.filename = self.base_dir + "/" + id
|
||||||
try:
|
try:
|
||||||
with open(self.filename, "r") as fh:
|
with open(self.filename, "r") as fh:
|
||||||
fcntl.flock(fh, fcntl.LOCK_SH)
|
fcntl.flock(fh, fcntl.LOCK_SH)
|
||||||
d = json.load(fh)
|
d = json.load(fh)
|
||||||
self.new = False
|
self.new = False
|
||||||
|
self.description = d["description"]
|
||||||
self.data = d["data"]
|
self.data = d["data"]
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
self.new = True
|
self.new = True
|
||||||
|
|
Loading…
Reference in New Issue