next attempt with the reload-on-zoom function. not yet working, esp. one doesn't...
[chrisu/seepark.git] / web / seepark_web.py
1 from flask import Flask, render_template, jsonify
2 from random import uniform
3 import time
4 app = Flask(__name__)
5
6 @app.route('/data/', defaults={'timespan': 1})
7 @app.route("/data/<int:timespan>", methods=['GET'])
8 def data(timespan):
9
10     granularity = 5 * timespan               # (every) minute(s) per day
11     samples = 60/granularity * 24 * timespan # per hour over whole timespan
12     s4m   = []
13     s4m_x = []
14     s5m   = []
15     s5m_x = []
16     end   = time.time()
17     start = end - samples * granularity * 60
18
19     for i in range(int(samples)):
20         s4m.append(uniform(-10,30))
21         s5m.append(uniform(-10,30))
22         s4mt = uniform(start, end)
23         s5mt = uniform(start, end)
24         s4m_x.append(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(s4mt)))
25         s5m_x.append(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(s5mt)))
26
27     data = {
28         '0316a2193bff':   s4m,
29         '0316a2193bff_x': s4m_x,
30         '0316a21383ff':   s5m,
31         '0316a21383ff_x': s5m_x,
32         }
33
34     return jsonify(data)
35
36
37 @app.route("/")
38 def index():
39     return render_template('seepark_web.html')
40