fix indentation. or actually logic: mode handling after the sql query
authorgregor herrmann <gregor@toastfreeware.priv.at>
Wed, 13 Jun 2018 15:58:56 +0000 (17:58 +0200)
committergregor herrmann <gregor@toastfreeware.priv.at>
Wed, 13 Jun 2018 16:30:22 +0000 (18:30 +0200)
web/seepark_web.py

index 68929fc8154afdaf09b44c25c4d4b70de4278f63..340c7b600511206f35646c92d3d36ce88c69c968 100644 (file)
@@ -54,30 +54,30 @@ def select_sensordata(initial_where, initial_sql_args):
         cursor = conn.execute(sql, *sql_args)
         result = [dict(row) for row in cursor]
 
-        mode = request.args.get('mode', 'full')
-        if mode == 'consolidated':
-            if begin is None or end is None:
-                pass
+    mode = request.args.get('mode', 'full')
+    if mode == 'consolidated':
+        if begin is None or end is None:
+            pass
+        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:
-                # 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'
+            # like loop over results and skip if timestamp(n+1)-timestamp(n)<resolution
 
     return result