changeset 995:b6ae650aec74

stats package whitespace-only and style cleanup
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 19 Jul 2006 11:30:12 +0200
parents 862edd1566bb
children bd54096490d3
files MoinMoin/stats/chart.py MoinMoin/stats/hitcounts.py MoinMoin/stats/pagesize.py MoinMoin/stats/useragents.py
diffstat 4 files changed, 71 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/stats/chart.py	Wed Jul 19 11:17:54 2006 +0200
+++ b/MoinMoin/stats/chart.py	Wed Jul 19 11:30:12 2006 +0200
@@ -48,8 +48,8 @@
         self.datasets = []
 
         self.option(
-            bg_color = 0xffffff, 
-            line_color = 0x000000
+            bg_color=0xffffff,
+            line_color=0x000000,
         )
 
     def addData(self, data):
@@ -74,7 +74,7 @@
         if not labels: labels = map(str, range(1, len(args[0])+1))
 
         # set colors for the data sets
-        if colors: self.option(set_color = map(int, map(Color, colors)))
+        if colors: self.option(set_color=map(int, map(Color, colors)))
 
         # pass options to gdchart and render the chart
         gdchart.option(**self.options)
@@ -93,14 +93,14 @@
 if __name__ == "__main__":
     import os, sys, random
     c = Chart()
-    c.addData(ChartData([random.randrange(0,i+1) for i in range(20)], color='green'))
+    c.addData(ChartData([random.randrange(0, i+1) for i in range(20)], color='green'))
     c.addData(ChartData([random.gauss(30, 5.0) for i in range(20)], color='blue'))
     c.option(
-        title = 'gdchart Demo',
-        xtitle = 'X axis',
-        ytitle = 'random values'
+        title='gdchart Demo',
+        xtitle='X axis',
+        ytitle='random values',
     )
-    c.draw(Chart.GDC_LINE, (600,300), 'test.gif')
+    c.draw(Chart.GDC_LINE, (600, 300), 'test.gif')
     if sys.platform == "win32":
         os.system("explorer test.gif")
     else:
--- a/MoinMoin/stats/hitcounts.py	Wed Jul 19 11:17:54 2006 +0200
+++ b/MoinMoin/stats/hitcounts.py	Wed Jul 19 11:30:12 2006 +0200
@@ -36,7 +36,7 @@
     querystr = wikiutil.escape(querystr)
     if params:
         querystr += '&amp;' + params
-    
+
     # TODO: remove escape=0 in 2.0
     data = {'url': page.url(request, querystr, escape=0)}
     data.update(request.cfg.chart_options)
@@ -47,13 +47,13 @@
 
 
 def get_data(pagename, request, filterpage=None):
-    
+
     # Get results from cache
     if filterpage:
         arena = Page(request, pagename)
     else:
         arena = 'charts'
-    
+
     cache_days, cache_views, cache_edits = [], [], []
     cache_date = 0
     cache = caching.CacheEntry(request, arena, 'hitcounts', scope='wiki')
@@ -69,7 +69,7 @@
         new_date = log.date()
     except logfile.LogMissing:
         new_date = None
-        
+
     # prepare data
     days = []
     views = []
@@ -80,11 +80,11 @@
         log.set_filter(['VIEWPAGE', 'SAVEPAGE'])
         for event in log.reverse():
             #print ">>>", wikiutil.escape(repr(event)), "<br>"
-    
-            if event[0] <=  cache_date:
+
+            if event[0] <= cache_date:
                 break
             # XXX Bug: event[2].get('pagename') -> u'Aktuelle%C4nderungen' 8(
-            eventpage = event[2].get('pagename','')
+            eventpage = event[2].get('pagename', '')
             if filterpage and eventpage != filterpage:
                 continue
             time_tuple = request.user.getTime(wikiutil.version2timestamp(event[0]))
@@ -107,7 +107,7 @@
                 views[-1] = views[-1] + 1
             elif event[1] == 'SAVEPAGE':
                 edits[-1] = edits[-1] + 1
-    
+
         days.reverse()
         views.reverse()
         edits.reverse()
@@ -123,7 +123,7 @@
     cache_views.extend(views)
     cache_edits.extend(edits)
     if new_date is not None:
-        cache.update("(%r, %r, %r, %r)" % 
+        cache.update("(%r, %r, %r, %r)" %
                      (new_date, cache_days, cache_views, cache_edits))
 
     return cache_days, cache_views, cache_edits
@@ -137,9 +137,9 @@
     # check params
     filterpage = None
     if params.startswith('page='):
-        params = params[len('page='):]        
+        params = params[len('page='):]
         filterpage = wikiutil.decodeUserInput(params)
-    
+
     if request and request.form and request.form.has_key('page'):
         filterpage = request.form['page'][0]
 
@@ -147,8 +147,8 @@
 
     hits = TupleDataset()
     hits.columns = [Column('day', label=_("Date"), align='left'),
-                    Column('views', label=_("Views/day") , align='right'),
-                    Column('edits', label=_("Edits/day") , align='right')
+                    Column('views', label=_("Views/day"), align='right'),
+                    Column('edits', label=_("Edits/day"), align='right'),
                     ]
 
     maxentries = 30
@@ -157,14 +157,14 @@
         step = float(len(days))/ maxentries
     else:
         step = 1
-        
+
     sv = 0.0
     se = 0.0
     sd = 0.0
     cnt = 0
 
-    for i in xrange(len(days)-1,-1,-1):
-        d,v,e = days[i], views[i], edits[i]
+    for i in xrange(len(days)-1, -1, -1):
+        d, v, e = days[i], views[i], edits[i]
         # sum up views and edits to step days 
         sd += 1
         cnt += 1
@@ -196,7 +196,7 @@
     days, views, edits = get_data(pagename, request, filterpage)
 
     import math
-    
+
     try:
         scalefactor = float(max(views))/max(edits)
     except (ZeroDivisionError, ValueError):
@@ -213,16 +213,20 @@
     c.addData(ChartData(views, color='green'))
     c.addData(ChartData(edits, color='red'))
     chart_title = ''
-    if request.cfg.sitename: chart_title = "%s: " % request.cfg.sitename
+    if request.cfg.sitename:
+        chart_title = "%s: " % request.cfg.sitename
     chart_title = chart_title + _('Page hits and edits')
-    if filterpage: chart_title = _("%(chart_title)s for %(filterpage)s") % {
-        'chart_title': chart_title, 'filterpage': filterpage}
+    if filterpage:
+        chart_title = _("%(chart_title)s for %(filterpage)s") % {
+            'chart_title': chart_title,
+            'filterpage': filterpage,
+        }
     chart_title = "%s\n%sx%d" % (chart_title, _("green=view\nred=edit"), scalefactor)
     c.option(
-        title = chart_title.encode('iso-8859-1', 'replace'), # gdchart can't do utf-8
-        xtitle = (_('date') + ' (Server)').encode('iso-8859-1', 'replace'),
-        ytitle = _('# of hits').encode('iso-8859-1', 'replace'),
-        title_font = c.GDC_GIANT,
+        title=chart_title.encode('iso-8859-1', 'replace'), # gdchart can't do utf-8
+        xtitle=(_('date') + ' (Server)').encode('iso-8859-1', 'replace'),
+        ytitle=_('# of hits').encode('iso-8859-1', 'replace'),
+        title_font=c.GDC_GIANT,
         #thumblabel = 'THUMB', thumbnail = 1, thumbval = 10,
         #ytitle_color = Color('green'),
         #yaxis2 = 1,
@@ -230,9 +234,9 @@
         #ytitle2_color = Color('red'),
         #ylabel2_color = Color('black'),
         #interpolations = 0,
-        threed_depth = 1.0,
-        requested_yinterval = 1.0,
-        stack_type = c.GDC_STACK_BESIDE
+        threed_depth=1.0,
+        requested_yinterval=1.0,
+        stack_type=c.GDC_STACK_BESIDE
     )
     c.draw(c.GDC_LINE,
         (request.cfg.chart_options['width'], request.cfg.chart_options['height']),
--- a/MoinMoin/stats/pagesize.py	Wed Jul 19 11:17:54 2006 +0200
+++ b/MoinMoin/stats/pagesize.py	Wed Jul 19 11:30:12 2006 +0200
@@ -33,7 +33,7 @@
     querystr = wikiutil.escape(querystr)
     if params:
         querystr += '&amp;' + params
-    
+
     # TODO: remove escape=0 in 2.0
     data = {'url': page.url(request, querystr, escape=0)}
     data.update(request.cfg.chart_options)
@@ -45,7 +45,8 @@
 def _slice(data, lo, hi):
     data = data[:]
     if lo: data[:lo] = [None] * lo
-    if hi < len(data): data[hi:] =  [None] * (len(data)-hi)
+    if hi < len(data):
+        data[hi:] = [None] * (len(data)-hi)
     return data
 
 
@@ -60,7 +61,7 @@
     pages = request.rootpage.getPageDict()
     sizes = []
     for name, page in pages.items():
-        sizes.append( (page.size(), name.encode('iso-8859-1', 'replace')) ) # gdchart does no utf-8
+        sizes.append((page.size(), name.encode('iso-8859-1', 'replace')) ) # gdchart does no utf-8
     sizes.sort()
 
     upper_bound = sizes[-1][0]
@@ -71,14 +72,14 @@
         bounds.extend([s*8192 for s in range(2, 9)])
     if upper_bound >= 65536:
         bounds.extend([s*65536 for s in range(2, 9)])
-        
+
     data = [None] * len(bounds)
     for size, name in sizes:
         idx = bisect.bisect(bounds, size)
         ##idx = int((size / upper_bound) * classes)
         data[idx] = (data[idx] or 0) + 1
 
-    labels = ["%d" %b for b in bounds]
+    labels = ["%d" % b for b in bounds]
 
     # give us a chance to develop this
     if _debug:
@@ -100,14 +101,14 @@
     if request.cfg.sitename: title = "%s: " % request.cfg.sitename
     title = title + _('Page Size Distribution')
     c.option(
-        annotation = (bisect.bisect(bounds, upper_bound), Color('black'), "%d %s" % sizes[-1]),
-        title = title.encode('iso-8859-1', 'replace'), # gdchart can't do utf-8
-        xtitle = _('page size upper bound [bytes]').encode('iso-8859-1', 'replace'),
-        ytitle = _('# of pages of this size').encode('iso-8859-1', 'replace'),
-        title_font = c.GDC_GIANT,
-        threed_depth = 2.0,
-        requested_yinterval = 1.0,
-        stack_type = c.GDC_STACK_LAYER
+        annotation=(bisect.bisect(bounds, upper_bound), Color('black'), "%d %s" % sizes[-1]),
+        title=title.encode('iso-8859-1', 'replace'), # gdchart can't do utf-8
+        xtitle=_('page size upper bound [bytes]').encode('iso-8859-1', 'replace'),
+        ytitle=_('# of pages of this size').encode('iso-8859-1', 'replace'),
+        title_font=c.GDC_GIANT,
+        threed_depth=2.0,
+        requested_yinterval=1.0,
+        stack_type=c.GDC_STACK_LAYER,
     )
     c.draw(style,
         (request.cfg.chart_options['width'], request.cfg.chart_options['height']),
--- a/MoinMoin/stats/useragents.py	Wed Jul 19 11:17:54 2006 +0200
+++ b/MoinMoin/stats/useragents.py	Wed Jul 19 11:30:12 2006 +0200
@@ -13,7 +13,7 @@
 
 _debug = 0
 
-from MoinMoin import wikiutil, caching, logfile 
+from MoinMoin import wikiutil, caching, logfile
 from MoinMoin.Page import Page
 from MoinMoin.logfile import eventlog
 
@@ -34,7 +34,7 @@
     querystr = wikiutil.escape(querystr)
     if params:
         querystr += '&amp;' + params
-    
+
     # TODO: remove escape=0 in 2.0
     data = {'url': page.url(request, querystr, escape=0)}
     data.update(request.cfg.chart_options)
@@ -53,13 +53,13 @@
             cache_date, data = eval(cache.content())
         except:
             cache.remove() # cache gone bad
-    
+
     log = eventlog.EventLog(request)
     try:
         new_date = log.date()
     except logfile.LogMissing:
         new_date = None
-    
+
     if new_date is not None:
         log.set_filter(['VIEWPAGE', 'SAVEPAGE'])
         for event in log.reverse():
@@ -74,10 +74,10 @@
                     ua = ua.split()[0]
                 #ua = ua.replace(';', '\n')
                 data[ua] = data.get(ua, 0) + 1
-    
+
         # write results to cache
         cache.update("(%r, %r)" % (new_date, data))
-            
+
     data = [(cnt, ua) for ua, cnt in data.items()]
     data.sort()
     data.reverse()
@@ -89,7 +89,7 @@
 
     fmt = request.formatter
     _ = request.getText
-    
+
     data = get_data(request)
 
     sum = 0.0
@@ -99,7 +99,7 @@
 
     agents = TupleDataset()
     agents.columns = [Column('agent', label=_("User agent"), align='left'),
-                      Column('value', label= '%', align='right')]
+                      Column('value', label='%', align='right')]
 
     cnt_printed = 0
     data = data[:10]
@@ -115,7 +115,7 @@
     table = DataBrowserWidget(request)
     table.setData(agents)
     return table.toHTML()
-    
+
 
 def draw(pagename, request):
     import shutil, cStringIO, operator
@@ -158,15 +158,15 @@
     if request.cfg.sitename: title = "%s: " % request.cfg.sitename
     title = title + _('Distribution of User-Agent Types')
     c.option(
-        pie_color = colors,
-        label_font = Chart.GDC_SMALL,
-        label_line = 1,
-        label_dist = 20,
-        threed_depth = 20,
-        threed_angle = 225,
-        percent_labels = Chart.GDCPIE_PCT_RIGHT,
-        title_font = c.GDC_GIANT,
-        title = title.encode('iso-8859-1', 'replace')) # gdchart can't do utf-8
+        pie_color=colors,
+        label_font=Chart.GDC_SMALL,
+        label_line=1,
+        label_dist=20,
+        threed_depth=20,
+        threed_angle=225,
+        percent_labels=Chart.GDCPIE_PCT_RIGHT,
+        title_font=c.GDC_GIANT,
+        title=title.encode('iso-8859-1', 'replace')) # gdchart can't do utf-8
     labels = [label.encode('iso-8859-1', 'replace') for label in labels]
     c.draw(style,
         (request.cfg.chart_options['width'], request.cfg.chart_options['height']),