Search in sources :

Example 1 with Period

use of com.xpn.xwiki.criteria.impl.Period in project xwiki-platform by xwiki.

the class Document method getCurrentMonthRefStats.

/**
 * Get referer statistics for the current document during the current month.
 *
 * @return a list of referer statistics for the document's space
 */
public List<RefererStats> getCurrentMonthRefStats() {
    Scope scope = ScopeFactory.createPageScope(this.getFullName());
    Range range = RangeFactory.ALL;
    Period period = PeriodFactory.getCurrentMonth();
    XWikiStatsService statisticsService = getXWikiContext().getWiki().getStatsService(getXWikiContext());
    List<RefererStats> stats = statisticsService.getRefererStatistics("", scope, period, range, this.context);
    return stats;
}
Also used : RefererStats(com.xpn.xwiki.stats.impl.RefererStats) 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)

Example 2 with Period

use of com.xpn.xwiki.criteria.impl.Period in project xwiki-platform by xwiki.

the class Document method getCurrentMonthPageStats.

/**
 * Get statistics about the number of request for the current page during the current month.
 *
 * @param action the type of request for which to retrieve statistics: view, edit...
 * @return the statistics object holding information for this document and the current month
 */
public DocumentStats getCurrentMonthPageStats(String action) {
    Scope scope = ScopeFactory.createPageScope(this.getFullName());
    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)

Example 3 with Period

use of com.xpn.xwiki.criteria.impl.Period in project xwiki-platform by xwiki.

the class XWikiStatsReader method getActionStatistics.

/**
 * Shows how the statistics for the specified action have evolved over the specified period of time.
 *
 * @param action the action for which to retrieve statistics.
 * @param scope the set of documents to consider.
 * @param period the period of time, including its start date but excluding its end date.
 * @param step the step used for sampling the period.
 * @param context the XWiki context.
 * @return a map of (date, actionCount) pairs.
 */
public Map<DateTime, Integer> getActionStatistics(String action, Scope scope, Period period, Duration step, XWikiContext context) {
    DateTime stepStart = new DateTime(period.getStart());
    DateTime periodEnd = new DateTime(period.getEnd());
    org.joda.time.Period stepDuration = new org.joda.time.Period(step.getYears(), step.getMonths(), step.getWeeks(), step.getDays(), 0, 0, 0, 0);
    Map<DateTime, Integer> activity = new HashMap<DateTime, Integer>();
    while (stepStart.compareTo(periodEnd) < 0) {
        DateTime stepEnd = stepStart.plus(stepDuration);
        if (stepEnd.compareTo(periodEnd) > 0) {
            stepEnd = periodEnd;
        }
        List<DocumentStats> stats = getDocumentStatistics(action, scope, new Period(stepStart.getMillis(), stepEnd.getMillis()), RangeFactory.FIRST, context);
        int actionCount = 0;
        if (stats.size() > 0) {
            actionCount = stats.get(0).getPageViews();
        }
        activity.put(stepStart, actionCount);
        stepStart = stepEnd;
    }
    return activity;
}
Also used : DocumentStats(com.xpn.xwiki.stats.impl.DocumentStats) HashMap(java.util.HashMap) Period(com.xpn.xwiki.criteria.impl.Period) DateTime(org.joda.time.DateTime)

Example 4 with Period

use of com.xpn.xwiki.criteria.impl.Period 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

Period (com.xpn.xwiki.criteria.impl.Period)4 Range (com.xpn.xwiki.criteria.impl.Range)3 Scope (com.xpn.xwiki.criteria.impl.Scope)3 XWikiStatsService (com.xpn.xwiki.stats.api.XWikiStatsService)3 DocumentStats (com.xpn.xwiki.stats.impl.DocumentStats)3 RefererStats (com.xpn.xwiki.stats.impl.RefererStats)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1