mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-13 07:29:39 +00:00
Load downloads statistics
This commit is contained in:
parent
cfbead0bac
commit
f07cd333d2
@ -38,9 +38,9 @@ class RHApiEventBase(RHApiBase):
|
||||
self._report_params['contrib_id'] = params.get('contrib_id')
|
||||
|
||||
|
||||
class RHApiDownloads(RHApiBase):
|
||||
class RHApiDownloads(RHApiEventBase):
|
||||
def _checkParams(self, params):
|
||||
RHApiBase._checkParams(self, params)
|
||||
RHApiEventBase._checkParams(self, params)
|
||||
self._report_params['download_url'] = params['download_url']
|
||||
|
||||
def _process(self):
|
||||
|
||||
@ -29,7 +29,7 @@ class PiwikQueryReportEventMetricVisitsBase(PiwikQueryReportEventMetricBase):
|
||||
|
||||
class PiwikQueryReportEventMetricDownloads(PiwikQueryReportEventMetricBase):
|
||||
def call(self, download_url):
|
||||
return super(PiwikQueryReportEventMetricReferrers, self).call(method='Actions.getDownload',
|
||||
return super(PiwikQueryReportEventMetricDownloads, self).call(method='Actions.getDownload',
|
||||
downloadUrl=quote(download_url))
|
||||
|
||||
def get_result(self, download_url):
|
||||
@ -42,28 +42,28 @@ class PiwikQueryReportEventMetricDownloads(PiwikQueryReportEventMetricBase):
|
||||
|
||||
# Piwik returns hits as a list of hits per date
|
||||
for date, hits in results.iteritems():
|
||||
day_hits = {'total_hits': 0, 'unique_hits': 0}
|
||||
day_hits = {'total': 0, 'unique': 0}
|
||||
if hits:
|
||||
for metrics in hits:
|
||||
day_hits['total_hits'] += metrics['nb_hits']
|
||||
day_hits['unique_hits'] += metrics['nb_uniq_visitors']
|
||||
day_hits['total'] += metrics['nb_hits']
|
||||
day_hits['unique'] += metrics['nb_uniq_visitors']
|
||||
hits_calendar[date] = day_hits
|
||||
|
||||
return hits_calendar
|
||||
|
||||
def _get_cumulative_results(self, results):
|
||||
"""
|
||||
Returns a dictionary of {'total_hits': x, 'unique_hits': y} for the
|
||||
Returns a dictionary of {'total': x, 'unique': y} for the
|
||||
date range.
|
||||
"""
|
||||
total_hits = {'total_hits': 0, 'unique_hits': 0}
|
||||
hits = {'total': 0, 'unique': 0}
|
||||
|
||||
day_hits = list(hits[0] for hits in results.values() if hits)
|
||||
for metrics in day_hits:
|
||||
total_hits['total_hits'] += metrics['nb_hits']
|
||||
total_hits['unique_hits'] += metrics['nb_uniq_visitors']
|
||||
hits['total'] += metrics['nb_hits']
|
||||
hits['unique'] += metrics['nb_uniq_visitors']
|
||||
|
||||
return total_hits
|
||||
return hits
|
||||
|
||||
|
||||
class PiwikQueryReportEventMetricReferrers(PiwikQueryReportEventMetricBase):
|
||||
|
||||
@ -182,26 +182,23 @@ $(function() {
|
||||
replot = typeof replot !== 'undefined' ? replot : false;
|
||||
var DOMTarget = 'materialDownloadChart';
|
||||
var graphParams = getIndicoBaseParams();
|
||||
graphParams['materialURL'] = uri;
|
||||
graphParams.download_url = uri;
|
||||
|
||||
indicoRequest('piwik.getMaterialStatistics', graphParams,
|
||||
function(result, error) {
|
||||
if (!error) {
|
||||
if (result !== null) {
|
||||
var materialHits = [getArrayValues(result['individual'],
|
||||
'total_hits'),
|
||||
getArrayValues(result['individual'],
|
||||
'unique_hits')];
|
||||
|
||||
drawGraph(materialHits, DOMTarget, replot);
|
||||
// Write to the title the total material downloads
|
||||
$('#materialTotalDownloads').html(result['cumulative']['total_hits']);
|
||||
}
|
||||
} else {
|
||||
$('#dialogNoGraphData').dialog('open');
|
||||
$.ajax({
|
||||
url: build_url(PiwikPlugin.urls.data_downloads, {'confId': $('#confId').val(), 'download_url': uri}),
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
if (handleAjaxError(data)) {
|
||||
return;
|
||||
}
|
||||
var materialHits = [getArrayValues(data.metrics.downloads.individual, 'total'),
|
||||
getArrayValues(data.metrics.downloads.individual, 'unique')];
|
||||
drawGraph(materialHits, DOMTarget, replot);
|
||||
// Write to the title the total material downloads
|
||||
$('#materialTotalDownloads').html(data.metrics.downloads.cumulative.total);
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/* jqTree Specifics */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user