Commits

George Notaras committed b11bd15

Added support for custom timeframe represented in seconds.

Comments (0)

Files changed (3)

src/sysscope/templatetags/sysscope_tags.py

 
 @register.filter
 def timelyadverb(value):
-    return TIME_FRAME_POOL[value][2]
+    try:
+        return TIME_FRAME_POOL[value][2]
+    except KeyError:
+        try:
+            int(value)
+        except ValueError:
+            raise Exception('Invalid timeframe: %s' % repr(timeframe))
+        else:
+            return value
 
 
 @register.filter
 def friendlytime(value):
-    return TIME_FRAME_POOL[value][1]
+    try:
+        return TIME_FRAME_POOL[value][1]
+    except KeyError:
+        try:
+            int(value)
+        except ValueError:
+            raise Exception('Invalid timeframe: %s' % repr(timeframe))
+        else:
+            return value
 

src/sysscope/utils.py

             t = int(time_current) - int(t)
     
     # timestamp
-    return int(t)
+    try:
+        return int(t)
+    except ValueError:
+        raise Exception('Invalid time: %s' % repr(t))
 
 
     
     """
     # If a special notation has been used (eg 12H), then we only need the last
     # character in order to determine which entry of the TIME_FRAME_POOL we need
-    time_frame_data = TIME_FRAME_POOL[timeframe[-1]]
-    return '%s %s graphs' % (section_obj.name, time_frame_data[2].title())
+    try:
+        time_frame_data = TIME_FRAME_POOL[timeframe[-1]]
+    except KeyError:
+        try:
+            return '%s timely graphs (%d seconds)' % (section_obj.name, int(timeframe))
+        except ValueError:
+            raise Exception('Invalid timeframe: %s' % repr(timeframe))
+    else:
+        return '%s %s graphs' % (section_obj.name, time_frame_data[2])
 

src/sysscope/views.py

 from sysscope.core.config import Section
 from sysscope.core.commons import get_graph_image_data
 from sysscope.utils import resolve_time
-from sysscope.utils import TIME_FRAMES_ORDERED
+from sysscope.utils import TIME_FRAME_POOL
 
 
 @login_required
         if selected_timeframe:
             
             # Check value
-            if selected_timeframe not in TIME_FRAMES_ORDERED:
+            if selected_timeframe not in TIME_FRAME_POOL.keys():
                 try:
                     int(selected_timeframe)
                 except ValueError:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.