homepage: sensor history json download

master
Nicolò Balzarotti 2023-02-25 10:55:32 +01:00
parent 56fdb75831
commit c29b3d49cf
3 changed files with 9 additions and 1 deletions

5
app.py
View File

@ -3,6 +3,7 @@ import json
from flask import Flask, Response
from flask import render_template, render_template_string, escape
from flask import request, send_file
from flask import jsonify
from flask_socketio import SocketIO, join_room
from random import randint
@ -81,6 +82,10 @@ def dist(filename):
print('Missing', filename)
return ''
@app.route('/sensors.json')
def get_sensors():
return jsonify(sensors.get_history())
@app.route('/recipe')
def recipe():
return render_template('recipe.html', recipe=phasectrl.recipe)

View File

@ -212,7 +212,7 @@ class Sensors():
def get_history(self, n=None):
l = len(self.history)
return tuple(islice(self.history, max(0, l - n), l))
return tuple(islice(self.history, max(0, l - (n or l)), l))
sensors = Sensors()

View File

@ -47,6 +47,9 @@
Update #of points
</a>
</div>
<a class="button is-link" href="/sensors.json">
Download
</a>
</div>
<div id="data-plot"></div>
<br/>