Search in sources :

Example 6 with DocumentStats

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;
}
Also used : DocumentStats(com.xpn.xwiki.stats.impl.DocumentStats) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 7 with DocumentStats

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;
}
Also used : DocumentStats(com.xpn.xwiki.stats.impl.DocumentStats) XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) ArrayList(java.util.ArrayList) XWikiException(com.xpn.xwiki.XWikiException)

Example 8 with DocumentStats

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();
}
Also used : DocumentStats(com.xpn.xwiki.stats.impl.DocumentStats) Scope(com.xpn.xwiki.criteria.impl.Scope) XWikiStatsService(com.xpn.xwiki.stats.api.XWikiStatsService) Period(com.xpn.xwiki.criteria.impl.Period) Range(com.xpn.xwiki.criteria.impl.Range)

Aggregations

DocumentStats (com.xpn.xwiki.stats.impl.DocumentStats)8 XWikiException (com.xpn.xwiki.XWikiException)4 XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)4 Period (com.xpn.xwiki.criteria.impl.Period)3 ArrayList (java.util.ArrayList)3 Range (com.xpn.xwiki.criteria.impl.Range)2 Scope (com.xpn.xwiki.criteria.impl.Scope)2 XWikiStatsService (com.xpn.xwiki.stats.api.XWikiStatsService)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1