mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-13 07:29:39 +00:00
Draw visits chart
This commit is contained in:
parent
275f2a1aac
commit
cfbead0bac
@ -11,7 +11,7 @@ from indico.web.flask.util import url_rule_to_js
|
||||
from MaKaC.conference import ConferenceHolder, LocalFile
|
||||
from MaKaC.webinterface.wcomponents import SideMenuItem
|
||||
|
||||
from .controllers import (RHStatistics, RHApiMaterial, RHApiDownloads, RHApiEventVisits,
|
||||
from .controllers import (RHStatistics, RHApiMaterial, RHApiDownloads, RHApiEventVisitsPerDay,
|
||||
RHApiEventGraphCountries, RHApiEventGraphDevices)
|
||||
from .forms import SettingsForm
|
||||
from .queries.tracking import PiwikQueryTrackDownload
|
||||
@ -113,6 +113,6 @@ blueprint = IndicoPluginBlueprint('piwik', __name__, url_prefix='/event/<confId>
|
||||
blueprint.add_url_rule('/', 'view', RHStatistics)
|
||||
blueprint.add_url_rule('/material', 'material', RHApiMaterial, methods=('GET', 'POST'))
|
||||
blueprint.add_url_rule('/data/downloads', 'data_downloads', RHApiDownloads, methods=('GET', 'POST'))
|
||||
blueprint.add_url_rule('/data/visits', 'data_visits', RHApiEventVisits, methods=('GET', 'POST'))
|
||||
blueprint.add_url_rule('/data/visits', 'data_visits', RHApiEventVisitsPerDay, methods=('GET', 'POST'))
|
||||
blueprint.add_url_rule('/graph/countries', 'graph_countries', RHApiEventGraphCountries, methods=('GET', 'POST'))
|
||||
blueprint.add_url_rule('/graph/devices', 'graph_devices', RHApiEventGraphDevices, methods=('GET', 'POST'))
|
||||
|
||||
@ -6,7 +6,7 @@ from MaKaC.conference import ConferenceHolder
|
||||
from MaKaC.webinterface.rh.conferenceModif import RHConferenceModifBase
|
||||
|
||||
from .views import WPStatistics
|
||||
from .reports import ReportCountries, ReportDevices, ReportDownloads, ReportGeneral, ReportVisits
|
||||
from .reports import ReportCountries, ReportDevices, ReportDownloads, ReportGeneral, ReportVisitsPerDay
|
||||
|
||||
|
||||
class RHStatistics(RHConferenceModifBase):
|
||||
@ -47,9 +47,9 @@ class RHApiDownloads(RHApiBase):
|
||||
return jsonify(ReportDownloads.get(**self._report_params))
|
||||
|
||||
|
||||
class RHApiEventVisits(RHApiEventBase):
|
||||
class RHApiEventVisitsPerDay(RHApiEventBase):
|
||||
def _process(self):
|
||||
return jsonify(ReportVisits.get(**self._report_params))
|
||||
return jsonify(ReportVisitsPerDay.get(**self._report_params))
|
||||
|
||||
|
||||
class RHApiEventGraphCountries(RHApiEventBase):
|
||||
|
||||
@ -13,12 +13,18 @@ class PiwikQueryReportEventMetricBase(PiwikQueryReportEventBase):
|
||||
def call(self, method, **query_params):
|
||||
return super(PiwikQueryReportEventMetricBase, self).call(method=method, format='JSON', **query_params)
|
||||
|
||||
def get_result(self, return_json=False):
|
||||
def get_result(self):
|
||||
"""Perform the call and return the sum of all unique values"""
|
||||
result = get_json_from_remote_server(self.call)
|
||||
if not result:
|
||||
return 0
|
||||
return result if return_json else int(reduce_json(result))
|
||||
pass
|
||||
|
||||
|
||||
class PiwikQueryReportEventMetricVisitsBase(PiwikQueryReportEventMetricBase):
|
||||
def get_result(self, reduced=True):
|
||||
query_params = {} if reduced else {'segmentation_enabled': False}
|
||||
result = get_json_from_remote_server(self.call, **query_params)
|
||||
if reduced:
|
||||
return int(reduce_json(result)) if result else 0
|
||||
return result if result else {}
|
||||
|
||||
|
||||
class PiwikQueryReportEventMetricDownloads(PiwikQueryReportEventMetricBase):
|
||||
@ -34,7 +40,7 @@ class PiwikQueryReportEventMetricDownloads(PiwikQueryReportEventMetricBase):
|
||||
def _get_per_day_results(self, results):
|
||||
hits_calendar = {}
|
||||
|
||||
# Piwik returns hits as a list of hits per date.
|
||||
# Piwik returns hits as a list of hits per date
|
||||
for date, hits in results.iteritems():
|
||||
day_hits = {'total_hits': 0, 'unique_hits': 0}
|
||||
if hits:
|
||||
@ -74,14 +80,15 @@ class PiwikQueryReportEventMetricReferrers(PiwikQueryReportEventMetricBase):
|
||||
return sorted(referrers, key=itemgetter('nb_visits'), reverse=True)[0:10]
|
||||
|
||||
|
||||
class PiwikQueryReportEventMetricUniqueVisits(PiwikQueryReportEventMetricBase):
|
||||
def call(self):
|
||||
return super(PiwikQueryReportEventMetricUniqueVisits, self).call(method='VisitsSummary.getUniqueVisitors')
|
||||
class PiwikQueryReportEventMetricUniqueVisits(PiwikQueryReportEventMetricVisitsBase):
|
||||
def call(self, **query_params):
|
||||
return super(PiwikQueryReportEventMetricUniqueVisits, self).call(method='VisitsSummary.getUniqueVisitors',
|
||||
**query_params)
|
||||
|
||||
|
||||
class PiwikQueryReportEventMetricVisits(PiwikQueryReportEventMetricBase):
|
||||
def call(self):
|
||||
return super(PiwikQueryReportEventMetricVisits, self).call(method='VisitsSummary.getVisits')
|
||||
class PiwikQueryReportEventMetricVisits(PiwikQueryReportEventMetricVisitsBase):
|
||||
def call(self, **query_params):
|
||||
return super(PiwikQueryReportEventMetricVisits, self).call(method='VisitsSummary.getVisits', **query_params)
|
||||
|
||||
|
||||
class PiwikQueryReportEventMetricVisitDuration(PiwikQueryReportEventMetricBase):
|
||||
|
||||
@ -121,12 +121,12 @@ class ReportGeneral(ReportBase):
|
||||
self.contributions[contrib_id] = info
|
||||
|
||||
|
||||
class ReportVisits(ReportBase):
|
||||
class ReportVisitsPerDay(ReportBase):
|
||||
__public__ = ['metrics']
|
||||
|
||||
def _build_report(self):
|
||||
self.metrics['unique'] = PiwikQueryReportEventMetricUniqueVisits(**self.params).get_result()
|
||||
self.metrics['total'] = PiwikQueryReportEventMetricVisits(**self.params).get_result()
|
||||
self.metrics['unique'] = PiwikQueryReportEventMetricUniqueVisits(**self.params).get_result(reduced=False)
|
||||
self.metrics['total'] = PiwikQueryReportEventMetricVisits(**self.params).get_result(reduced=False)
|
||||
self._reduce_metrics()
|
||||
|
||||
def _reduce_metrics(self):
|
||||
|
||||
@ -160,16 +160,18 @@ $(function() {
|
||||
var DOMTarget = 'visitorChart';
|
||||
$('#' + DOMTarget).html(progressIndicator(true, true).dom);
|
||||
|
||||
indicoRequest('piwik.getEventVisits', getIndicoBaseParams(),
|
||||
function(result, error) {
|
||||
if (!error) {
|
||||
var source = [getArrayValues(result, 'total_hits'),
|
||||
getArrayValues(result, 'unique_hits')]
|
||||
|
||||
drawGraph(source, DOMTarget, false);
|
||||
} else {
|
||||
$('#' + DOMTarget).html($T('No data found.'));
|
||||
$.ajax({
|
||||
url: build_url(PiwikPlugin.urls.data_visits, {confId: $('#confId').val()}),
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
if (handleAjaxError(data)) {
|
||||
return;
|
||||
}
|
||||
var source = [getArrayValues(data.metrics, 'total'),
|
||||
getArrayValues(data.metrics, 'unique')];
|
||||
drawGraph(source, DOMTarget, false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -295,7 +297,7 @@ $(function() {
|
||||
if (data.graphs[request.report] !== null) {
|
||||
graph_holder.attr('src', data.graphs[request.report]);
|
||||
} else {
|
||||
var error = $('<div>').text($T("No graph data Received"));
|
||||
var error = $('<div>').text($T("No graph data received"));
|
||||
graph_holder.replaceWith(error);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user