changeset 376:41c3d817878d

merge
author Matt Johnston <matt@ucc.asn.au>
date Wed, 27 Jun 2012 23:46:12 +0800
parents f0a61b700d23 (current diff) f22427bcfda8 (diff)
children 16f96019a9e0
files
diffstat 4 files changed, 72 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/web/config.py	Tue Jun 26 23:49:31 2012 +0800
+++ b/web/config.py	Wed Jun 27 23:46:12 2012 +0800
@@ -23,3 +23,6 @@
 
 GRAPH_FONT = "Prociono"
 #GRAPH_FONT = "URW Gothic L"
+
+# determine by zooming in an image viewer
+GRAPH_LEFT_MARGIN = 95
--- a/web/log.py	Tue Jun 26 23:49:31 2012 +0800
+++ b/web/log.py	Wed Jun 27 23:46:12 2012 +0800
@@ -97,7 +97,6 @@
         '--color', 'MGRID#aaaaaa',
         '--color', 'BACK#ffffff',
         '--disable-rrdtool-tag',
-        'VRULE:%d#ee0000' % time.time(),
         '--watermark', watermark,
         '--imgformat', 'PNG'] \
         + graph_args
--- a/web/templog.py	Tue Jun 26 23:49:31 2012 +0800
+++ b/web/templog.py	Wed Jun 27 23:46:12 2012 +0800
@@ -3,8 +3,10 @@
 import binascii
 import hmac
 import zlib
-import datetime
+from datetime import datetime, timedelta
 import time
+import urllib
+import sys
 
 import bottle
 from bottle import route, request, response
@@ -12,6 +14,9 @@
 import config
 import log
 
+DATE_FORMAT = '%Y%m%d-%H.%M'
+ZOOM_SCALE = 2.0
+
 @route('/update', method='post')
 def update():
     enc_lines = request.forms.lines
@@ -28,26 +33,51 @@
 
 @route('/graph.png')
 def graph():
-    # url takes time in hours or days
-    if 'day' in request.query:
-        start_day = datetime.datetime.strptime(request.query.day, '%Y%m%d')
-        start = time.mktime(start_day.timetuple())
-        length = int(request.query.get('length', 5)) * 3600 * 24
-    else:
-        if 'hour' in request.query:
-            start_hour = datetime.datetime.strptime(request.query.hour, '%Y%m%d%H')
-        else:
-            start_hour = datetime.datetime.now() - datetime.timedelta(days=1)
-
-        start = time.mktime(start_hour.timetuple())
-        length = int(request.query.get('length', 26)) * 3600
+    length_minutes = int(request.query.length)
+    end = datetime.strptime(request.query.end, DATE_FORMAT)
+    start = end - timedelta(minutes=length_minutes)
 
     response.set_header('Content-Type', 'image/png')
-    return log.graph_png(start, length)
+    start_epoch = time.mktime(start.timetuple())
+    return log.graph_png(start_epoch, length_minutes * 60)
 
 @route('/')
 def top():
-    return bottle.template('top', urlparams=request.query_string)
+
+    minutes = int(request.query.get('length', 26*60))
+
+    if 'end' in request.query:
+        end = datetime.strptime(request.query.end, DATE_FORMAT)
+    else:
+        end = datetime.now()
+
+    if 'zoom' in request.query:
+        orig_start = end - timedelta(minutes=minutes)
+        orig_end = end
+        xpos = int(request.query.x)
+        xpos -= config.GRAPH_LEFT_MARGIN
+
+        if xpos >= 0 and xpos < config.GRAPH_WIDTH:
+            click_time = orig_start \
+                + timedelta(minutes=(float(xpos) / config.GRAPH_WIDTH) * minutes)
+            minutes = int(minutes / ZOOM_SCALE)
+
+            end = click_time + timedelta(minutes=minutes/2)
+        else:
+            # zoom out
+            minutes = int(minutes*ZOOM_SCALE)
+            end += timedelta(minutes=minutes/2)
+
+    if end > datetime.now():
+        end = datetime.now()
+        
+    request.query.replace('length', minutes)
+    request.query.replace('end', end.strftime(DATE_FORMAT))
+
+    urlparams = urllib.urlencode(request.query)
+    return bottle.template('top', urlparams=urlparams,
+                    end = end.strftime(DATE_FORMAT),
+                    length = minutes)
 
 @route('/test')
 def test():
--- a/web/views/top.tpl	Tue Jun 26 23:49:31 2012 +0800
+++ b/web/views/top.tpl	Wed Jun 27 23:46:12 2012 +0800
@@ -1,5 +1,26 @@
-<html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+
+<head>
+
+<style type="text/css"><!--
+span.no_selection {
+    -webkit-user-select: none; // webkit (safari, chrome) browsers
+    -moz-user-select: none; // mozilla browsers
+    -khtml-user-select: none; // webkit (konqueror) browsers
+}
+//-->
+</style>
+
+
+</head>
+
 <body>
-<img src="graph.png?{{urlparams}}"/>
+<form action="" method=GET>
+<span class="no_selection"><input type="image" src="graph.png?{{urlparams}}"/></span>
+<input type="hidden" name="length" value="{{length}}"/>
+<input type="hidden" name="end" value="{{end}}"/>
+<input type="hidden" name="zoom" value="yeah"/>
+</form>
 </body>
 </html>