]> 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 74daa2fdc248ecb7625818ad22dd01b2fa0be295..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 = {
-        'water_temperature': [20, 19, 20, 21, 20, 21],
-        'water_temperature_x': ['2018-05-20', '2018-05-21', '2018-05-22', '2018-05-23', '2018-05-24', '2018-05-27'],
-        'air_temperature': [27, 32, 26, 29, 30, 31],
-        'air_temperature_x': ['2018-05-21', '2018-05-22', '2018-05-23', '2018-05-24', '2018-05-25', '2018-05-27'],
+        '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')