]> ToastFreeware Gitweb - chrisu/seepark.git/blobdiff - web/seepark_web.py
add buttons for day/week/month/year, + css and a js function
[chrisu/seepark.git] / web / seepark_web.py
index 912b09aa1646d46fc869d9e98e5869f24f19fbe8..fa08f12480bf96d5a6ace7283fdf1b579efd1b7c 100644 (file)
@@ -1,18 +1,40 @@
 from flask import Flask, render_template, jsonify
+from random import uniform
+import time
 app = Flask(__name__)
 
-@app.route("/data")
-def data():
+@app.route('/data/', defaults={'timespan': 1})
+@app.route("/data/<int:timespan>", methods=['GET'])
+def data(timespan):
+
+    granularity = 5 * timespan               # (every) minute(s) per day
+    samples = 60/granularity * 24 * timespan # per hour over whole timespan
+    s4m   = []
+    s4m_x = []
+    s5m   = []
+    s5m_x = []
+    end   = time.time()
+    start = end - samples * granularity * 60
+
+    for i in range(int(samples)):
+        s4m.append(uniform(-10,30))
+        s5m.append(uniform(-10,30))
+        s4mt = uniform(start, end)
+        s5mt = uniform(start, end)
+        s4m_x.append(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(s4mt)))
+        s5m_x.append(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(s5mt)))
+
     data = {
-        '0316a2193bff': [20, 19, 20, 21, 20, 21],
-        '0316a2193bff_x': ['2018-05-20 12:00:01', '2018-05-21 13:01:02', '2018-05-22 14:05:00', '2018-05-23 14:05:01', '2018-05-24 14:05:00',                        '2018-05-27 14:05:02'],
-        '0316a21383ff': [27, 32, 26, 29, 30, 31],
-        '0316a21383ff_x': [                       '2018-05-21 18:00:00', '2018-05-22 14:05:00', '2018-05-23 14:05:00', '2018-05-24 14:05:02', '2018-05-25 14:05:01', '2018-05-27 14:05:01'],
+        '0316a2193bff':   s4m,
+        '0316a2193bff_x': s4m_x,
+        '0316a21383ff':   s5m,
+        '0316a21383ff_x': s5m_x,
         }
+
     return jsonify(data)
 
 
 @app.route("/")
-def hello():
+def index():
     return render_template('seepark_web.html')