finally use random data but change granularity in dependenc of timespan
authorgregor herrmann <gregor@toastfreeware.priv.at>
Mon, 4 Jun 2018 16:28:02 +0000 (18:28 +0200)
committergregor herrmann <gregor@toastfreeware.priv.at>
Mon, 4 Jun 2018 16:28:02 +0000 (18:28 +0200)
timespan should come from GET later

web/seepark_web.py

index 753456ff8d15e615d407bbafdd51c4a0b6c7b305..0a1aa34a7f502fa28e4eb73dde60074dc173daa0 100644 (file)
@@ -5,38 +5,32 @@ app = Flask(__name__)
 
 @app.route("/data")
 def data():
+
+    timespan = 1                             # days
+    granularity = 5 * timespan               # (every) minute(s)
+    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,
         }
 
-#    years = 3
-#    granularity = 5 # minutes
-#    samples = 60/granularity * 24 * 365 * years # every "granularity" minutes for "years" years
-#    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':   s4m,
-#        '0316a2193bff_x': s4m_x,
-#        '0316a21383ff':   s5m,
-#        '0316a21383ff_x': s5m_x,
-#        }
-
     return jsonify(data)