cogStatistics about edited articles over time
Developed by

Marius Dumitru Florea

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

Shows how the number of edited articles changes in time, per day or per week. This statistic refers only to existing articles, i.e. shows how existing articles have been edited over time. This limitation is due to the fact that XWiki doesn't store information about the deleted pages and going through page revisions to see if a page met some requirements at some point in time is costly. Another solution would be to use the observation manager to record custom statistics.

Statistics must be enabled and this code must be saved with programming rights because the search is done using protected API.

{{velocity}}
##
## Define the scope.
##
#set($space = "Blog")
#set($className = "Blog.BlogPostClass")
#set($scope = "select doc.fullName from XWikiDocument doc, BaseObject obj where doc.space = ? and doc.fullName = obj.name and obj.className = ?")

= Per Day =

##
## Define the period.
##
#set($days = 7)
#set($period = $xwiki.criteriaService.periodFactory.createSinceDaysPeriod($days))
##
## Retrieve the stats.
##
#set($action = "save")
#set($hql = "select ds.period, count(*) from DocumentStats ds where ds.action = ? and ? <= ds.period and ds.period <= ? and ds.name in (${scope}) group by ds.period order by ds.period")
#set($stats = $context.xWiki.store.search($hql, $days, 0, [$action, $period.startCode, $period.endCode, $space, $className], $context.context))
##
## Display the stats.
##
#set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern("yyyyMMdd"))
|=Year|=Month|=Day|=Number of edited pages
#foreach($stat in $stats)
#set($statDate = $dateFormatter.parseDateTime("$stat.get(0)"))
|$statDate.year|(% style="text-align:right" %)$statDate.monthOfYear|(% style="text-align:right" %)$statDate.dayOfMonth|(% style="text-align:right" %)$stat.get(1)
#end

= Per Week =

##
## Define the period.
##
#set($weeks = 5)
#set($period = $xwiki.criteriaService.periodFactory.createSinceWeeksPeriod($weeks))
#set($startDate = $xwiki.criteriaService.periodFactory.createWeekPeriod($period.start).start)
#set($endDate = $xwiki.criteriaService.periodFactory.createWeekPeriod($period.end).end)
#set($startDateCode = $util.parseInt($dateFormatter.print($startDate)))
#set($endDateCode = $util.parseInt($dateFormatter.print($endDate)))
##
## Retrieve the stats.
##
#set($year = "substring(str(ds.period), 1, 4)")
#set($month = "substring(str(ds.period), 5, 2)")
#set($day = "substring(str(ds.period), 7, 2))")
#set($week = "week(${year}||'-'||${month}||'-'||${day}")
#set($hql = "select ${year}, ${week}, count(distinct ds.name) from DocumentStats ds where ds.action = ? and ? <= ds.period and ds.period < ? and ds.name in (${scope}) group by ${year}, ${week} order by ${year}, ${week}")
#set($stats = $context.xWiki.store.search($hql, $weeks, 0, [$action, $startDateCode, $endDateCode, $space, $className], $context.context))
##
## Display the stats.
##
|=Year|=Week|=Number of edited pages
#foreach($stat in $stats)
#foreach($part in $stat)|(% style="text-align:right" %)$part#end

#end
{{/velocity}}

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Tags: statistics
Created by Marius Dumitru Florea on 2010/03/09 15:11
     

Get Connected