use of com.xpn.xwiki.stats.impl.DocumentStats 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();
}
use of com.xpn.xwiki.stats.impl.DocumentStats in project xwiki-platform by xwiki.
the class DocumentStatsStoreItem method storeInternal.
@Override
public void storeInternal(List<XWikiStatsStoreItem> stats) {
DocumentStatsStoreItem lastItem = (DocumentStatsStoreItem) stats.get(stats.size() - 1);
XWikiHibernateStore store = this.context.getWiki().getHibernateStore();
if (store == null) {
return;
}
DocumentStats documentStat = new DocumentStats(lastItem.name, lastItem.action, lastItem.periodDate, lastItem.periodType);
// Load old statistics object from database
try {
// TODO Fix use of deprecated call.
store.loadXWikiCollection(documentStat, this.context, true);
} catch (XWikiException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Failed to load document statistics object [{}]", getId(), e);
}
}
// Increment counters
documentStat.setIntValue("pageViews", documentStat.getPageViews() + stats.size());
for (XWikiStatsStoreItem statItem : stats) {
DocumentStatsStoreItem docStat = (DocumentStatsStoreItem) statItem;
if (docStat.isVisit) {
documentStat.incVisits();
}
}
// Re-save statistics object
try {
// TODO Fix use of deprecated call.
store.saveXWikiCollection(documentStat, this.context, true);
} catch (XWikiException e) {
LOGGER.error("Failed to save document statistics object [{}]", getId(), e);
}
}
use of com.xpn.xwiki.stats.impl.DocumentStats in project xwiki-platform by xwiki.
the class XWikiStatsReader method getDocMonthStats.
// ////////////////////////////////////////////////////////////////////////////////////////
// Deprecated methods
// ////////////////////////////////////////////////////////////////////////////////////////
/**
* Gets monthly statistics on a document for a specific action.
*
* @param docname fully qualified document name.
* @param action can be "view", "edit", "save", etc..
* @param month the month.
* @param context the XWiki context.
* @return DocumentStats - statistics object.
* @deprecated use {@link #getDocumentStatistics(String, Scope, Period, Range , XWikiContext)} instead.
*/
@Deprecated
public DocumentStats getDocMonthStats(String docname, String action, Date month, XWikiContext context) {
XWikiHibernateStore store = context.getWiki().getHibernateStore();
DocumentStats object = new DocumentStats(docname, action, month, PeriodType.MONTH);
try {
// TODO Fix use of deprecated call.
store.loadXWikiCollection(object, context, true);
return object;
} catch (XWikiException e) {
e.printStackTrace();
return new DocumentStats();
}
}
use of com.xpn.xwiki.stats.impl.DocumentStats in project xwiki-platform by xwiki.
the class XWikiStatsReader method getBackLinkStatistics.
/**
* Retrieves back-link statistics.
*
* @param domain the domain used for filtering the results.
* @param scope the scope of referred 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> getBackLinkStatistics(String domain, 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 RefererStats" + " where ({0}) and referer like ? and ? <= period and period < ? group by name" + " order by sum(pageViews) {1}", nameFilter, sortOrder);
paramList.add(getHqlValidDomain(domain));
paramList.add(period.getStartCode());
paramList.add(period.getEndCode());
List<?> solist = store.search(query, range.getAbsoluteSize(), range.getAbsoluteStart(), paramList, context);
documentStatsList = getDocumentStatistics(solist, "refer");
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 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;
}
Aggregations