use of com.xpn.xwiki.stats.impl.DocumentStats in project xwiki-platform by xwiki.
the class XWikiStatsReader method getDocumentStatistics.
/**
* Converts the rows retrieved from the database to a list of DocumentStats instances.
*
* @param resultSet the result of a database query for document statistics.
* @param action the action for which the statistics were retrieved.
* @return a list of {@link com.xpn.xwiki.stats.impl.DocumentStats} objects.
* @see #getDocumentStatistics(String, Scope, com.xpn.xwiki.criteria.impl.Period , Range , XWikiContext)
*/
private List<DocumentStats> getDocumentStatistics(List<?> resultSet, String action) {
List<DocumentStats> documentStatsList = new ArrayList<DocumentStats>(resultSet.size());
Date now = new Date();
for (Object name : resultSet) {
Object[] result = (Object[]) name;
// We can't represent a custom period (e.g. year, week or some time interval) in the
// database and thus we use a default one, which sould be ignored
DocumentStats docStats = new DocumentStats((String) result[0], action, now, PeriodType.DAY);
docStats.setPageViews(((Number) result[1]).intValue());
documentStatsList.add(docStats);
}
return documentStatsList;
}
use of com.xpn.xwiki.stats.impl.DocumentStats in project xwiki-platform by xwiki.
the class XWikiStatsReader method getDocumentStatistics.
/**
* Retrieves document statistics.
*
* @param action the action the results should be ordered by. It can be one of: "view", "save" or "download". If the
* action is "view" then the documents are ordered by the number of times they have been viewed so far.
* @param scope the set of documents for which to retrieve statistics.
* @param period the period of time, including its start date but excluding its end date.
* @param range the sub-range to return from the entire result set. Use this parameter for pagination.
* @param context the XWiki context.
* @return A list of DocumentStats objects
*/
public List<DocumentStats> getDocumentStatistics(String action, Scope scope, Period period, Range range, XWikiContext context) {
List<DocumentStats> documentStatsList;
List<Object> paramList = new ArrayList<Object>(4);
String nameFilter = getHqlNameFilterFromScope(scope, paramList);
String sortOrder = getHqlSortOrderFromRange(range);
XWikiHibernateStore store = context.getWiki().getHibernateStore();
try {
String query = MessageFormat.format("select name, sum(pageViews) from DocumentStats" + " where ({0}) and action=? and ? <= period and period < ? group by name order" + " by sum(pageViews) {1}", nameFilter, sortOrder);
paramList.add(action);
paramList.add(period.getStartCode());
paramList.add(period.getEndCode());
List<?> solist = store.search(query, range.getAbsoluteSize(), range.getAbsoluteStart(), paramList, context);
documentStatsList = getDocumentStatistics(solist, action);
if (range.getSize() < 0) {
Collections.reverse(documentStatsList);
}
} catch (XWikiException e) {
documentStatsList = Collections.emptyList();
}
return documentStatsList;
}
use of com.xpn.xwiki.stats.impl.DocumentStats in project xwiki-platform by xwiki.
the class Document method getCurrentMonthSpaceStats.
/**
* Get statistics about the number of request for the current space during the current month.
*
* @param action the type of request for which to retrieve statistics: view, edit...
* @return the statistics object holding information for the document's space and the current month
*/
public DocumentStats getCurrentMonthSpaceStats(String action) {
Scope scope = ScopeFactory.createSpaceScope(this.doc.getSpace(), false);
Range range = RangeFactory.ALL;
Period period = PeriodFactory.getCurrentMonth();
XWikiStatsService statisticsService = getXWikiContext().getWiki().getStatsService(getXWikiContext());
List<DocumentStats> stats = statisticsService.getDocumentStatistics(action, scope, period, range, this.context);
if (stats.size() > 0) {
return stats.get(0);
}
return new DocumentStats();
}
Aggregations