[Moin-devel] CVS: MoinMoin/macro EventStats.py,1.1,1.2

J?rgen Hermann jhermann at users.sourceforge.net
Fri Feb 1 15:35:31 EST 2002


Update of /cvsroot/moin/MoinMoin/macro
In directory usw-pr-cvs1:/tmp/cvs-serv22314/MoinMoin/macro

Modified Files:
	EventStats.py 
Log Message:
EventStats now shows real data


Index: EventStats.py
===================================================================
RCS file: /cvsroot/moin/MoinMoin/macro/EventStats.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** EventStats.py	2002/02/01 22:53:41	1.1
--- EventStats.py	2002/02/01 23:34:51	1.2
***************
*** 12,24 ****
  # Imports
  import string
! from MoinMoin import config, webapi
  from MoinMoin.Page import Page
  from MoinMoin.i18n import _
  
! width = 480
! height = 300
  
  
  def execute(macro, args, **kw):
      page = Page(macro.formatter.page.page_name)
      result = []
--- 12,29 ----
  # Imports
  import string
! from MoinMoin import config, webapi, eventlog, user
  from MoinMoin.Page import Page
  from MoinMoin.i18n import _
  
! _debug = 0
  
+ width = 720
+ height = 540
  
+ 
  def execute(macro, args, **kw):
+     if _debug:
+         return chart(macro.formatter.page.page_name, {})
+ 
      page = Page(macro.formatter.page.page_name)
      result = []
***************
*** 30,46 ****
  
  def chart(pagename, form):
!     import sys, shutil, cStringIO
      from MoinMoin.stats import chart
  
!     image = cStringIO.StringIO()
  
      c = chart.Chart()
!     c.addData(chart.ChartData(range(20), color='green'))
      c.option(
!         title = 'Page hits',
          xtitle = 'date',
          ytitle = '# of hits'
      )
!     c.draw(c.GDC_LINE, (width, height), image)
  
      # send HTTP headers
--- 35,79 ----
  
  def chart(pagename, form):
!     import cgi, sys, shutil, cStringIO
      from MoinMoin.stats import chart
  
!     # prepare data
!     days = []
!     views = []
!     edits = []
!     ratchet_day = None
!     data = eventlog.logger.read(['VIEWPAGE', 'SAVEPAGE'])
!     for event in data:
!         time_tuple = user.current.getTime(event[0])
!         day = tuple(time_tuple[0:3])
!         if day != ratchet_day:
!             # new day
!             # !!! this is not really correct, if we have days
!             # without data, we have to add more 0 values
!             days.append(user.current.getFormattedDate(event[0]))
!             views.append(0)
!             edits.append(0)
!             ratchet_day = day
!         if event[1] == 'VIEWPAGE':
!             views[-1] = views[-1] + 1
!         elif event[1] == 'SAVEPAGE':
!             edits[-1] = edits[-1] + 1
! 
!     # give us a chance to develop this
!     if _debug:
!         return "labels = %s<br>views = %s<br>edits = %s<br>" % \
!             tuple(map(cgi.escape, map(repr, [days, views, edits])))
  
+     # create image
+     image = cStringIO.StringIO()
      c = chart.Chart()
!     c.addData(chart.ChartData(views, color='green'))
!     c.addData(chart.ChartData(edits, color='red'))
      c.option(
!         title = 'Page hits and edits',
          xtitle = 'date',
          ytitle = '# of hits'
      )
!     c.draw(c.GDC_LINE, (width, height), image, days)
  
      # send HTTP headers





More information about the Moin-devel mailing list