[Moin-devel] CVS: MoinMoin/stats pagesize.py,NONE,1.1

J?rgen Hermann jhermann at users.sourceforge.net
Fri Feb 1 20:30:21 EST 2002


Update of /cvsroot/moin/MoinMoin/stats
In directory usw-pr-cvs1:/tmp/cvs-serv13668/MoinMoin/stats

Added Files:
	pagesize.py 
Log Message:
"pagesize" chart type


--- NEW FILE: pagesize.py ---
"""
    MoinMoin - Pagesize Statistics

    Copyright (c) 2002 by Jürgen Hermann <jh at web.de>
    All rights reserved, see COPYING for details.

    This macro creates a bar graph of page size classes.

    $Id: pagesize.py,v 1.1 2002/02/02 04:29:55 jhermann Exp $
"""

_debug = 0

import string
from MoinMoin import config, wikiutil
from MoinMoin.Page import Page
from MoinMoin.i18n import _


def linkto(pagename, params=''):
    if not config.chart_options:
        return _('<div class="message"><b>Charts are not available!</b></div>')

    if _debug:
        return draw(pagename, {})

    page = Page(pagename)
    result = []
    data = {
        'url': page.url("action=chart&type=pagesize"),
    }
    data.update(config.chart_options)
    result.append('<img src="%(url)s" border="0" '
        'width="%(width)d" height="%(height)d">' % data)

    return string.join(result, '')


def draw(pagename, form):
    import cgi, sys, shutil, cStringIO
    from MoinMoin import config, webapi
    from MoinMoin.stats.chart import Chart, ChartData, Color

    style = Chart.GDC_3DBAR

    # get data
    pages = wikiutil.getPageDict(config.text_dir)
    sizes = [(p.size(), name) for name, p in pages.items()]
    sizes.sort()
    upper_bound = int((sizes[-1][0] + 1023) / 1024) * 1024.0

    classes = 20
    data = [None] * classes
    for size, name in sizes:
        idx = int((size / upper_bound) * classes)
        data[idx] = (data[idx] or 0) + 1

    labels = []
    for idx in range(classes):
        label = "%.1f" % (
            upper_bound / classes * (idx+1) / 1024,
        )
        labels.append(label)

    # give us a chance to develop this
    if _debug:
        return "<p>data = %s</p>" % \
            string.join(map(cgi.escape, map(repr, [labels, data])), '<br>')

    # create image
    image = cStringIO.StringIO()
    c = Chart()
    c.addData(ChartData(data, 'green'))
    title = ''
    if config.sitename: title = "%s: " % config.sitename
    title = title + 'Page Size Distribution'
    c.option(
        annotation = (len(labels)-1, Color('black'), "%d %s" % sizes[-1]),
        title = title,
        xtitle = 'page size upper bound [K]',
        ytitle = '# of pages of this size',
        title_font = c.GDC_GIANT,
        #thumblabel = 'THUMB', thumbnail = 1, thumbval = 10,
        #ytitle_color = Color('green'),
        #yaxis2 = 1,
        #ytitle2 = '# of edits',
        #ytitle2_color = Color('red'),
        #ylabel2_color = Color('black'),
        requested_yinterval = 1.0,
        stack_type = c.GDC_STACK_BESIDE
    )
    c.draw(style,
        (config.chart_options['width'], config.chart_options['height']),
        image, labels)

    # send HTTP headers
    headers = [
        "Content-Type: image/gif",
        "Content-Length: %d" % len(image.getvalue()),
    ]
    webapi.http_headers(headers)

    # copy the image
    image.reset()
    shutil.copyfileobj(image, sys.stdout, 8192)
    sys.exit(0)






More information about the Moin-devel mailing list