Prepare consolidation of data.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 18 Jul 2018 21:26:47 +0000 (23:26 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 18 Jul 2018 21:26:47 +0000 (23:26 +0200)
web/seepark_web.py

index 18bedc9c6548e98f20772d5f5dad0af748e7ec42..c19e9b92e177cfac69d57eadd6f9ba9cca5d0a6a 100644 (file)
@@ -71,29 +71,39 @@ def select_sensordata(sensor_id, sensor_type, begin, end, mode):
         query = query.filter(Sensors.timestamp >= begin)
     if end is not None:
         query = query.filter(Sensors.timestamp <= end)
         query = query.filter(Sensors.timestamp >= begin)
     if end is not None:
         query = query.filter(Sensors.timestamp <= end)
-    if mode == 'consolidated':
-        if begin is None or end is None:
-            pass
+    if mode == 'consolidated' and begin is None and end is None:
+        # copied from munin/master/_bin/munin-cgi-graph.in
+        # interval in seconds for data points
+        resolutions = dict(
+            day   =   300,
+            week  =  1800,
+            month =  7200,
+            year  = 86400,
+        )
+        duration = (end - begin).total_seconds()
+        day = 60 * 60 * 24
+        if duration < day:
+            resolution = resolutions['day']
+        elif duration < 7 * day:
+            resolution = resolutions['week']
+        elif duration < 31 * day:
+            resolution = resolutions['month']
         else:
         else:
-            # copied from munin/master/_bin/munin-cgi-graph.in
-            resolutions = dict(
-                day   =   300,
-                week  =  1800,
-                month =  7200,
-                year  = 86400,
-            )
-            duration = (end - begin).total_seconds()
-            day = 60 * 60 * 24
-            if duration < day:
-                resolution = resolutions['day']
-            elif duration < 7 * day:
-                resolution = resolutions['week']
-            elif duration < 31 * day:
-                resolution = resolutions['month']
-            else:
-                resolution = resolutions['year']
-            # TODO: filter out samples from 'result'
-            # like loop over results and skip if timestamp(n+1)-timestamp(n)<resolution
+            resolution = resolutions['year']
+        # TODO: filter out samples from 'result'
+        # something like 
+        # select mean(temperature) from sensors where ... group by mod(timestamp, resolution)
+        # func.avg(...)
+        #
+        # from https://stackoverflow.com/questions/4342370/grouping-into-interval-of-5-minutes-within-a-time-range
+        # SELECT
+        #    timestamp,  -- not sure about that
+        #        name,
+        #            count(b.name)
+        #            FROM time a, id 
+        #            WHERE …
+        #            GROUP BY 
+        #            UNIX_TIMESTAMP(timestamp) DIV 300, name
     return query.all()
 
 
     return query.all()