Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin.stats.pagesize Namespace Reference

Functions

def linkto
def _slice
def draw

Variables

int _debug = 0

Function Documentation

def MoinMoin.stats.pagesize._slice (   data,
  lo,
  hi 
) [private]

Definition at line 44 of file pagesize.py.

00044 
00045 def _slice(data, lo, hi):
00046     data = data[:]
00047     if lo: data[:lo] = [None] * lo
00048     if hi < len(data):
00049         data[hi:] = [None] * (len(data)-hi)
00050     return data
00051 

Here is the caller graph for this function:

def MoinMoin.stats.pagesize.draw (   pagename,
  request 
)

Definition at line 52 of file pagesize.py.

00052 
00053 def draw(pagename, request):
00054     import bisect, shutil, cStringIO
00055     from MoinMoin.stats.chart import Chart, ChartData, Color
00056 
00057     _ = request.getText
00058     style = Chart.GDC_3DBAR
00059 
00060     # get data
00061     pages = request.rootpage.getPageDict()
00062     sizes = []
00063     for name, page in pages.items():
00064         sizes.append((page.size(), name.encode('iso-8859-1', 'replace')) ) # gdchart does no utf-8
00065     sizes.sort()
00066 
00067     upper_bound = sizes[-1][0]
00068     bounds = [s*128 for s in range(1, 9)]
00069     if upper_bound >= 1024:
00070         bounds.extend([s*1024 for s in range(2, 9)])
00071     if upper_bound >= 8192:
00072         bounds.extend([s*8192 for s in range(2, 9)])
00073     if upper_bound >= 65536:
00074         bounds.extend([s*65536 for s in range(2, 9)])
00075 
00076     data = [None] * len(bounds)
00077     for size, name in sizes:
00078         idx = bisect.bisect(bounds, size)
00079         ##idx = int((size / upper_bound) * classes)
00080         data[idx] = (data[idx] or 0) + 1
00081 
00082     labels = ["%d" % b for b in bounds]
00083 
00084     # give us a chance to develop this
00085     if _debug:
00086         return "<p>data = %s</p>" % \
00087             '<br>'.join([wikiutil.escape(repr(x)) for x in [labels, data]])
00088 
00089     # create image
00090     image = cStringIO.StringIO()
00091     c = Chart()
00092     ##c.addData(ChartData(data, 'magenta'))
00093     c.addData(ChartData(_slice(data, 0, 7), 'blue'))
00094     if upper_bound >= 1024:
00095         c.addData(ChartData(_slice(data, 7, 14), 'green'))
00096     if upper_bound >= 8192:
00097         c.addData(ChartData(_slice(data, 14, 21), 'red'))
00098     if upper_bound >= 65536:
00099         c.addData(ChartData(_slice(data, 21, 28), 'magenta'))
00100     title = ''
00101     if request.cfg.sitename: title = "%s: " % request.cfg.sitename
00102     title = title + _('Page Size Distribution')
00103     c.option(
00104         annotation=(bisect.bisect(bounds, upper_bound), Color('black'), "%d %s" % sizes[-1]),
00105         title=title.encode('iso-8859-1', 'replace'), # gdchart can't do utf-8
00106         xtitle=_('page size upper bound [bytes]').encode('iso-8859-1', 'replace'),
00107         ytitle=_('# of pages of this size').encode('iso-8859-1', 'replace'),
00108         title_font=c.GDC_GIANT,
00109         threed_depth=2.0,
00110         requested_yinterval=1.0,
00111         stack_type=c.GDC_STACK_LAYER,
00112     )
00113     c.draw(style,
00114         (request.cfg.chart_options['width'], request.cfg.chart_options['height']),
00115         image, labels)
00116 
00117     request.content_type = 'image/gif'
00118     request.content_length = len(image.getvalue())
00119 
00120     # copy the image
00121     image.reset()
00122     shutil.copyfileobj(image, request, 8192)
00123 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.stats.pagesize.linkto (   pagename,
  request,
  params = '' 
)

Definition at line 17 of file pagesize.py.

00017 
00018 def linkto(pagename, request, params=''):
00019     _ = request.getText
00020 
00021     if not request.cfg.chart_options:
00022         return (request.formatter.sysmsg(1) +
00023                 request.formatter.text(_('Charts are not available!')) +
00024                 request.formatter.sysmsg(0))
00025 
00026     if _debug:
00027         return draw(pagename, request)
00028 
00029     page = Page(request, pagename)
00030 
00031     # Create escaped query string from dict and params
00032     querystr = {'action': 'chart', 'type': 'pagesize'}
00033     querystr = wikiutil.makeQueryString(querystr)
00034     querystr = wikiutil.escape(querystr)
00035     if params:
00036         querystr += '&amp;' + params
00037 
00038     data = {'url': page.url(request, querystr)}
00039     data.update(request.cfg.chart_options)
00040     result = ('<img src="%(url)s" width="%(width)d" height="%(height)d"'
00041               ' alt="pagesize chart">') % data
00042     return result
00043 

Here is the call graph for this function:


Variable Documentation

Definition at line 11 of file pagesize.py.