function inArray(needle, haystack) { var length = haystack.length; for(var i = 0; i < length; i++) { if(haystack[i] == needle) return true; } return false; } var statistics = (function() { 'use strict'; /* Initialize attributes */ var STAT = { page_loader: app.get_loader2('Loading...'), /*graphs to be loaded initially upon first load*/ date_range: { 'start_date': '30daysAgo', 'end_date': 'yesterday', 'filter_input_id': '#ga_date_range', }, base_url: app.get_vars().baseurl, /*actual container of graphs when generated*/ graphs: {}, //originally => the_chart /*graphs to be loaded initially upon first load*/ graph_list_per_set: { 'first': [ //1st tab 'visitors_graph', 'sessions_graph', 'session_duration_graph', 'pageviews_graph', 'unique_pageviews_graph', 'event_views_graph', 'bounce_rate_graph', 'users_and_browsers', 'users_and_device_category', 'source_mediums_graph' ], 'second': [ //3rd tab ] }, graph_configs: { 'general': { 'utypes': '1_2_3', 'data_url': app.get_vars().baseurl + 'get_ga_data/', }, /* 1st tab */ 'visitors_graph': { data_name: 'visitors', tbl_abbrev: 'vis', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'visitors-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'sessions_graph': { data_name: 'sessions', tbl_abbrev: 'sess', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'sessions-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'session_duration_graph': { data_name: 'session_duration', tbl_abbrev: 'sess', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'session_duration-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'pageviews_graph': { data_name: 'pageviews', tbl_abbrev: 'pv', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'pageviews-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'unique_pageviews_graph': { data_name: 'unique_pageviews', tbl_abbrev: 'pv', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'unique_pageviews-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'event_views_graph': { data_name: 'event_views', tbl_abbrev: 'ev', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'event_views-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'bounce_rate_graph': { data_name: 'bounceRate', tbl_abbrev: 'bcr', color_Nouveaux: ['#f5a9a9'], color_Connus: ['#9cbce6'], color_Connectés: ['#97caa7'], fill: false, container_name: 'bounceRate-chart', graph_type: 'line', options: { legend: { position: 'right', onClick: (e) => e.stopPropagation() }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label; var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips scales: { yAxes: [{ ticks: { beginAtZero:true, userCallback: function(value, index, values) { // Convert the number to a string and splite the string every 3 charaters from the end value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return value; } }}],xAxes: [{ticks: {}}] }, }, }, /* 1st tab */ 'users_and_browsers': { data_name: 'users_browsers', tbl_abbrev: 'br', container_name: 'browsers-chart', graph_type: 'pie', options: { legend: { display: false, }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.labels[tooltipItem.index]; var value = data.datasets[0].data[tooltipItem.index]; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips }, colors: [ 'rgb(255, 139, 3)', 'rgb(255, 230, 3)', 'rgb(167, 255, 3)', 'rgb(27, 163, 0)', 'rgb(3, 255, 187)', 'rgb(3, 217, 255)', 'rgb(3, 126, 255)', 'rgb(4, 48, 161)', 'rgb(114, 3, 255)', 'rgb(255, 3, 33)', 'rgb(220, 3, 255)', 'rgb(125, 0, 0)', ] }, /* 1st tab */ 'users_and_device_category': { data_name: 'users_and_device_category', tbl_abbrev: 'dv', container_name: 'device-categories-chart', graph_type: 'pie', options: { legend: { display: false, }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.labels[tooltipItem.index]; var value = data.datasets[0].data[tooltipItem.index]; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips }, colors: [ 'rgb(255, 139, 3)', 'rgb(255, 230, 3)', 'rgb(167, 255, 3)', 'rgb(27, 163, 0)', 'rgb(3, 255, 187)', 'rgb(3, 217, 255)', 'rgb(3, 126, 255)', 'rgb(4, 48, 161)', 'rgb(114, 3, 255)', 'rgb(255, 3, 33)', 'rgb(220, 3, 255)', 'rgb(125, 0, 0)', ] }, /* 3rd tab */ 'source_mediums_graph': { data_name: 'source_mediums_graph', tbl_abbrev: 'gsm', container_name: 'source_mediums_graph-chart', graph_type: 'pie', options: { legend: { display: false, }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.labels[tooltipItem.index]; var value = data.datasets[0].data[tooltipItem.index]; value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(' '); return `${label}: `+value; } } // end callbacks: }, //end tooltips }, colors: [ 'rgb(255, 139, 3)', 'rgb(255, 230, 3)', 'rgb(167, 255, 3)', 'rgb(27, 163, 0)', 'rgb(3, 255, 187)', 'rgb(3, 217, 255)', 'rgb(3, 126, 255)', 'rgb(4, 48, 161)', 'rgb(114, 3, 255)', 'rgb(255, 3, 33)', 'rgb(220, 3, 255)', 'rgb(125, 0, 0)', ] }, }, /* * TABLES */ table_list_per_set: { 'first': [ //first tab 'f_url_clicks_table', 'f_contact_email_category_table', 'y_contact_emails_table', ], 'second': [ //second tab 'y_registrations_table', 'f_subscribers_table', 'y_events_table', 'f30days_events_table', 'f_events_per_status_table', 'y_reservations_per_subs_table', 'f30days_reservations_per_subs_table', 'y_reservations_table', 'f30days_reservations_table', 'y_cancellations_table', 'f30days_cancellations_table', 'faq_stat_table' ], 'third': [ //third tab 'f_searches_table', 'faq_searches_table', // 'source_mediums_table', ] }, table_configs: { 'general': { /* Where the data is fetched from*/ 'data_url': app.get_vars().baseurl + 'get_dashboard_table_data/', }, /* * general tab - liens cliques * url clicks */ 'f_url_clicks_table': { data_name: 'url_clicks', data_cat: 'filtered', data_containers: [], }, /* * general tab - liens cliques * contact email category data */ 'f_contact_email_category_table': { data_name: 'contact_cat', data_cat: 'filtered', data_containers: [], }, /* * general tab - liens cliques * yearly contact emails */ 'y_contact_emails_table': { data_name: 'y_contact', data_cat: 'yearly', data_containers: ['y_contact_cur_year', 'y_contact_prev_year'], }, /* * abonnes tab first row - Nombre d'inscriptions (Nouveau qui a confirmé son formulaire de première inscription) * yearly registrations */ 'y_registrations_table': { data_name: 'y0', data_cat: 'yearly', data_containers: ['y0_cur_year', 'y0_prev_year'], }, /* * abonnes tab first row - Nombre d'inscriptions (Nouveau qui a confirmé son formulaire de première inscription) * subscribers per interval based on filter */ 'f_subscribers_table': { data_name: 'fsubs', data_cat: 'filtered', data_containers: ['fsubs_interval'], }, /* * abonnes tab 2nd row - Nombre d'événements par statuts (prochainement, en cours, complets, terminés, passés, archivés) total + /année * yearly event count */ 'y_events_table': { data_name: 'y1', data_cat: 'yearly', data_containers: ['y1_cur_year', 'y1_prev_year'], }, /* * abonnes tab 2nd row - events last 30 days */ 'f30days_events_table': { data_name: 'f_y1', data_cat: 'filtered', data_containers: ['f_y1_interval'], }, /* * abonnes tab 2nd row - Nombre d'événements par statuts (prochainement, en cours, complets, terminés, passés, archivés) total + /année * number of events per backoffice status */ 'f_events_per_status_table': { data_name: 'fevents', data_cat: 'filtered', data_containers: ['fevents_proc', 'fevents_en', 'fevents_com', 'fevents_ter', 'fevents_pas', 'fevents_arc'], }, /* * abonnes tab 3rd row - Nombre de réservations effectuées (par abonnés) * yearly reservations per subscriber */ 'y_reservations_per_subs_table': { data_name: 'y2', data_cat: 'yearly', data_containers: ['y2_cur_year', 'y2_prev_year'], }, /* * abonnes tab 2nd row - subscribers last 30 days */ 'f30days_reservations_per_subs_table': { data_name: 'f_y2', data_cat: 'filtered', data_containers: ['f_y2_interval'], }, /* * abonnes tab 4th row - Nombre de places réservées * yearly reservations */ 'y_reservations_table': { data_name: 'y3', data_cat: 'yearly', data_containers: ['y3_cur_year', 'y3_prev_year'], }, /* * reservations last 30 days */ 'f30days_reservations_table': { data_name: 'f_y3', data_cat: 'filtered', data_containers: ['f_y3_interval'], }, /* * abonnes tab 5th row - Nombre d'annulations effectuées (annulation totale de réservation) * yearly cancellations */ 'y_cancellations_table': { data_name: 'y4', data_cat: 'yearly', data_containers: ['y4_cur_year', 'y4_prev_year'], }, 'f30days_cancellations_table': { data_name: 'f_y4', data_cat: 'filtered', data_containers: ['f_y4_interval'], }, /* * recherches tab * faq searches */ 'f_searches_table': { data_name: 's', data_cat: 'filtered', data_containers: [], }, 'faq_searches_table': { data_name: 'faq_search', data_cat: 'filtered', data_containers: [], }, 'source_mediums_table': { data_name: 'source_mediums', data_cat: 'filtered', data_containers: [], }, 'faq_stat_table': { data_name: 'faq_stat', data_cat: 'filtered', data_containers: [], }, }, total_search: 0, } /***************************************************************************** * * Event listeners for UI elements * ****************************************************************************/ $('button#filter_dashboard_data').on('click', function(event) { event.preventDefault(); STAT.toggleLoader('tab', 'show'); STAT.toggleLoader('filter', 'show'); setTimeout(function(){ STAT.generateGraphs(STAT.graph_list_per_set['first']) statistics.generateTables(statistics.table_list_per_set['first']) statistics.generateTables(statistics.table_list_per_set['second']) statistics.generateTables(statistics.table_list_per_set['third']) }, 100); }); // set data triggers for each graph $('.chart-btn-holder').on('click', 'button:not(.total_u_data)', function() { // remove users to get chart data name var chart_data_name = ((this.id).split('___'))[0]; var chart_user_type = ((this.id).split('___'))[1]; $(this).toggleClass('disable-btn'); // do not disable all, at least 1 trigger should remain active var len = ($('#'+chart_data_name+'_triggers .disable-btn').toArray()).length; if (len == 3) { $(this).removeClass('disable-btn'); } else { STAT.graphs[chart_data_name+'-chart'].data.datasets.forEach(function(ds) { if(ds.label == chart_user_type){ ds.hidden = !ds.hidden; } }); STAT.graphs[chart_data_name+'-chart'].update(); } }); /* Load tab data on click */ $('.statistics-tabs').on('click', function(event) { event.preventDefault(); if (!$(this).hasClass('tab_data_loaded')) { /* Load tab data */ // switch (this.id) { // case 'general-tabb': // STAT.generateGraphs(STAT.graph_list_per_set['first']) // break; // case 'abonnes-tabb': // break; // case 'recherches-tabb': // STAT.generateGraphs(STAT.graph_list_per_set['second']) // break; // default: // } /* Indicate that the tab data has been loaded*/ $(this).addClass('tab_data_loaded'); } else { } }); $('a#export_dashboard_data').on('click', function(event) { STAT.toggleLoader('tab', 'show'); app.btn_loader('#export_dashboard_data'); STAT.exportDashboardData(); setTimeout(function(){ app.rmbtn_loader('#export_dashboard_data'); STAT.toggleLoader('export', 'remove'); }, 1000); }); /***************************************************************************** * * Methods for dealing with statistics page * ****************************************************************************/ /** * @method * initializes the status of buttons (onload) base on the main buttons */ STAT.initConfigs = function() { Chart.defaults.global.animation.duration = 900; Chart.defaults.global.responsive = true; Chart.defaults.global.maintainAspectRatio = false; // load a locale for numbers numeral.register('locale', 'fr', { delimiters: { thousands: ' ', decimal: ',' }, abbreviations: { thousand: 'k', million: 'm', billion: 'b', trillion: 't' }, ordinal : function (number) { return number === 1 ? 'er' : 'ème'; }, currency: { symbol: 'MGA' } }); numeral.locale('fr'); /* * initialize the daterangepicker, set the default date range to 30 days ago from current date */ $('.datetimepicker').daterangepicker({ autoApply: true, locale: { format: 'DD/MM/YYYY', // cancelLabel : dashboard_data.cancel, // applyLabel : 'Appliquer le filtre', "daysOfWeek": 'di_lu_ma_me_je_ce_sa'.split('_'), "monthNames": 'janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre'.split('_') }, defaultDate : moment().subtract(30, 'days'), startDate: moment().subtract(30, 'days'), endDate: moment().subtract(1, 'days'), maxDate: moment().subtract(1, 'days'), }); }; /** ** @method formats number to french */ STAT.formatNumToFr = function(number){ return (number - Math.floor(number))? numeral(number).format('0,0.00') : numeral(number).format('0,0'); }; STAT.formatNumToFrNoDec = function(number){ return numeral(number).format('0,0'); }; /** ** @method sets the start and end date when filtering graph ** @param string date range : from date filter input */ STAT.setDateFilter = function(){ var date_range = $('#ga_date_range').val(); if (date_range) { date_range = date_range.split(' - '); STAT.date_range.start_date = date_range[0].replace(/\//g, '-');; STAT.date_range.end_date = date_range[1].replace(/\//g, '-');; } }; /** ** @method sets user filter, depends on what is checked in the filter */ STAT.setUserFilter = function(){ var checked_utypes = $('.user-filter:checked').toArray(); if (0 != checked_utypes.length || checked_utypes.length < 3) { var utypes = []; for (var i = 0; i < checked_utypes.length; i++) { utypes.push(checked_utypes[i].value); } STAT.graph_configs.general.utypes = utypes.join('_'); } }; /** ** @method reset box values to zero for the active tab */ STAT.resetGraphBoxValues = function(){ $('li.active>a.statistics-tabs span.box_values').html(0); $('span.box_values_total').html(0); }; /** ** @method reset box values to zero */ STAT.disableEmptyBoxValues = function(graph_category){ var stat_btn = ($('#'+graph_category+'_triggers .stat_btn').toArray()); for (var i = 0; i < stat_btn.length; i++) { var box_val = parseInt($('#'+stat_btn[i].id + ' .box_values').html()); if (box_val == 0) { $('#'+stat_btn[i].id).attr('disabled', 'disabled'); $('#'+stat_btn[i].id).addClass('disable-btn'); } else { $('#'+stat_btn[i].id).removeAttr('disabled'); $('#'+stat_btn[i].id).removeClass('disable-btn'); } } }; /** ** @method set loader */ STAT.toggleLoader = function(item, action){ switch (item) { case 'tab': if (action == 'remove') { app.remove_loader(); return; } /* Set tab loader */ $('.tab-pane.active').prepend(STAT.page_loader); break; case 'export': if (action == 'remove') { app.remove_loader(); return; } /* Set tab loader */ $('.tab-pane.active').prepend(app.get_loader2('Exporting...')); break; case 'filter': if (action == 'remove') { app.rmbtn_loader('#filter_dashboard_data'); return; } app.btn_loader('#filter_dashboard_data'); break; default: } }; /** ** @method plot graph data, per graph type have specific ways of data manipulation */ STAT.prepAndPlot = { /* GRAPHS */ 'prepare_visitors_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total' : 0, 'Nouveaux' : 0, 'Connus' : 0, 'Connectés' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type']] += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Sum up all values for all users => accu box values total*/ accu_box_values.Total += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values[key]/days_count)); $('#'+g_info['data_name']+'___'+key+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values[key])); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values.Total/days_count)); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values.Total)); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_sessions_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total' : 0, 'Nouveaux' : 0, 'Connus' : 0, 'Connectés' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type']] += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Sum up all values for all users => accu box values total*/ accu_box_values.Total += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values[key]/days_count)); $('#'+g_info['data_name']+'___'+key+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values[key])); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values.Total/days_count)); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values.Total)); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_session_duration_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total' : 0, 'Nouveaux' : 0, 'Connus' : 0, 'Connectés' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type']] += parseInt(row[g_info['tbl_abbrev']+'_rdata']?row[g_info['tbl_abbrev']+'_rdata']:0); /* Sum up all values for all users => accu box values total*/ accu_box_values.Total += parseInt(row[g_info['tbl_abbrev']+'_rdata']?row[g_info['tbl_abbrev']+'_rdata']:0); /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values[key]/days_count)); $('#'+g_info['data_name']+'___'+key+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values[key])); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values.Total/days_count)); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values.Total)); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_pageviews_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total' : 0, 'Nouveaux' : 0, 'Connus' : 0, 'Connectés' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type']] += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Sum up all values for all users => accu box values total*/ accu_box_values.Total += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values[key]/days_count)); $('#'+g_info['data_name']+'___'+key+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values[key])); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values.Total/days_count)); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values.Total)); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_unique_pageviews_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total' : 0, 'Nouveaux' : 0, 'Connus' : 0, 'Connectés' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type']] += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Sum up all values for all users => accu box values total*/ accu_box_values.Total += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values[key]/days_count)); $('#'+g_info['data_name']+'___'+key+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values[key])); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values.Total/days_count)); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values.Total)); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_event_views_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total' : 0, 'Nouveaux' : 0, 'Connus' : 0, 'Connectés' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type']] += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Sum up all values for all users => accu box values total*/ accu_box_values.Total += parseInt(row[g_info['tbl_abbrev']+'_rdata']); /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values[key]/days_count)); $('#'+g_info['data_name']+'___'+key+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values[key])); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html(STAT.formatNumToFrNoDec(accu_box_values.Total/days_count)); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values_total').html(STAT.formatNumToFrNoDec(accu_box_values.Total)); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_bounce_rate_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* x axis: the labels per value */ }, datasets_data = { 'Nouveaux' : [], 'Connus' : [], 'Connectés' : [], }, /* contains the x and y values for each dataset (per user type) */ // tbl_abbrev = g_info['tbl_abbrev'], accu_box_values = { 'Total_sess_rdata' : 0, 'Total_sess_br' : 0, 'Nouveaux_sess_rdata' : 0, 'Nouveaux_sess_br' : 0, 'Connus_sess_rdata' : 0, 'Connus_sess_br' : 0, 'Connectés_sess_rdata' : 0, 'Connectés_sess_br' : 0, }, /* box values, accumulated*/ days_count = data.length/(STAT.graph_configs.general.utypes.split('_').length); /*number of days covered by the fetched data*/ data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row[g_info['tbl_abbrev']+'_rdate']); } /* Sum up all values for each users => accu box values*/ accu_box_values[row['user_type'] + '_sess_rdata'] += parseInt(row['sess_rdata']); accu_box_values[row['user_type'] + '_sess_br'] += parseInt(row['sess_br']); if (row['user_type'] != 'Connectés') { /* Sum up all values for all users => accu box values total (except connected user)*/ // total sessions accu_box_values.Total_sess_rdata += parseInt(row['sess_rdata']); // total bounce rate per session accu_box_values.Total_sess_br += parseInt(row['sess_br']); } /* Collect dataset data per user */ datasets_data[row['user_type']].push({ t : row[g_info['tbl_abbrev']+'_rdate'], y : parseInt((row[g_info['tbl_abbrev']+'_rdata'])?(row[g_info['tbl_abbrev']+'_rdata']):0) });; }); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['color_'+key], backgroundColor: g_info['color_'+key] }); /* SET THE BOX VALUES */ $('#'+g_info['data_name']+'___'+key+' span.box_values').html( STAT.formatNumToFr( Math.round( (accu_box_values[key + '_sess_br']/accu_box_values[key + '_sess_rdata']) * 100 ) )); $('#'+g_info['data_name']+'___Total_u_data'+' span.box_values').html( STAT.formatNumToFr( Math.round( (accu_box_values.Total_sess_br/accu_box_values.Total_sess_rdata) * 100 ) )); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_users_and_browsers': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* labels of each slice */ }, datasets_data = { 'all' : [], }, /* all data for the pie graph */ table_data = ''; var color_index = 0; data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row['rtype']); } /* Collect dataset data per slice */ datasets_data['all'].push(row['vis_rdata']);; /* Set table data */ table_data += `` + ` ` + `${row['rtype']}` + `` + STAT.formatNumToFr(row['vis_rdata']) + ` (` + parseFloat(row['percentage']).toFixed(2) + `%)` +`` + '' }); /* Plot the table */ $('.nav_web tbody').html(table_data); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { /* Prepare the pie graph data*/ dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['colors'], backgroundColor: g_info['colors'] }); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_users_and_device_category': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* labels of each slice */ }, datasets_data = { 'all' : [], }, /* all data for the pie graph */ table_data = ''; var color_index = 0; data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row['rtype']); } /* Collect dataset data per slice */ datasets_data['all'].push(row['vis_rdata']);; /* Set table data */ table_data += `` + ` ` + `${row['rtype']}` + `` + STAT.formatNumToFr(row['vis_rdata']) + ` (` + parseFloat(row['percentage']).toFixed(2) + `%)` +`` + '' }); /* Plot the table */ $('.type_dev tbody').html(table_data); // $('.source_meds tbody').html(table_data); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { /* Prepare the pie graph data*/ dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['colors'], backgroundColor: g_info['colors'] }); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, 'prepare_source_mediums_graph': function (g_info, data){ /* Initialize variables */ var dataset_graph_data = { 'datasets': [], /* dataset to be plotted including the configuration */ 'labels':[] /* labels of each slice */ }, datasets_data = { 'all' : [], }, /* all data for the pie graph */ table_data = ''; var color_index = 0; data.forEach(function(row){ /* 3 datasets = one date, avoid duplicating date ranges*/ if (!inArray(row[g_info['tbl_abbrev']+'_rdate'], dataset_graph_data.labels)) { dataset_graph_data.labels.push(row['rtype']); } /* Collect dataset data per slice */ datasets_data['all'].push(row['vis_rdata']);; /* Set table data */ table_data += `` + ` ` + `${row['rtype']}` + `` + STAT.formatNumToFr(row['vis_rdata']) + ` (` + parseFloat(row['percentage']).toFixed(2) + `%)` +`` + ''; }); /* Plot the table */ $('.source_meds tbody').html(table_data); /* Prepare the dataset data per user */ for (var key in datasets_data) { if (datasets_data.hasOwnProperty(key)) { /* Prepare the pie graph data*/ dataset_graph_data.datasets.push({ label: key, fill: g_info['fill'], data: datasets_data[key], borderColor: g_info['colors'], backgroundColor: g_info['colors'] }); } } /* Disable click on empty box value */ STAT.disableEmptyBoxValues(g_info['data_name']); STAT.plotGraph(g_info, dataset_graph_data); }, /* TABLES */ 'prepare_f_url_clicks_table': function (t_info, data){ /* Initialize variables */ var table_data = '', total_data = 0, url = ''; data.forEach(function(row){ url = (row.gev_raction).replace('https://preprod.wylog.com/lemonde-res', ''); url = url.replace('https://preprod.wylog.com/lemonde-dev/', ''); url = url.replace('https://preprod.wylog.com/lemonde-client/', ''); url = url.replace('localhost/', ''); url = url.replace('https://evenements-abonnes.lemonde.fr/', ''); total_data += parseInt(row['gev_rdata']); /* Set table data */ table_data += '' +''+url+'' +''+ STAT.formatNumToFr(row.gev_rdata)+'' +''; }); $('.url-clicks-body').html(table_data); $('.url-clicks-body').append( '' +'Total' +''+ STAT.formatNumToFr(total_data) + '' +'' ); }, 'prepare_f_contact_email_category_table': function (t_info, data){ /* Initialize variables */ var table_data = '', total_data = 0; data.forEach(function(row){ total_data += parseInt(row['value']); /* Set table data */ table_data += `` + `` + `${row['c_category']}` + `` + `` + `` + STAT.formatNumToFr(row['value']) + `` + `` + ''; }); $('.total_cat_filtered .value').html(STAT.formatNumToFr(total_data)); $('.formulai_table tbody').html(table_data); }, 'prepare_y_contact_emails_table': function (t_info, data){ /* Initialize variables */ var yearly_data = { 'current_year': parseInt($('.'+t_info['data_containers'][0]+' .data_year').html()), 'previous_year': parseInt($('.'+t_info['data_containers'][1]+' .data_year').html()), 'current_year_data': 0, 'previous_year_data': 0, }; data.forEach(function(row){ // console.log(yearly_data.current_year); // console.log(row.data_year); if (yearly_data.current_year == row.data_year) { yearly_data.current_year_data = parseFloat(row.value? row.value : 0); $('.'+t_info['data_containers'][0]+' .value').html( STAT.formatNumToFr(yearly_data.current_year_data) ); } if (yearly_data.previous_year == row.data_year) { yearly_data.previous_year_data = parseFloat(row.value ? row.value : 0); $('.'+t_info['data_containers'][1]+' .value').html( STAT.formatNumToFr(yearly_data.previous_year_data) ); } }); /* Calculate the percentage increase*/ var percent_inc_dec = yearly_data.previous_year_data != 0? Math.abs( ((yearly_data.current_year_data - yearly_data.previous_year_data)/yearly_data.previous_year_data)*100 ) : 0; var stats_class = "year_value_zero"; if (percent_inc_dec) { /* Set the increased/decreased indicator */ stats_class = "year_value_up"; var arrow_type = "fa fa-arrow-up"; } if ( yearly_data.current_year_data < yearly_data.previous_year_data ) { /* Calculate the percentage decrease */ percent_inc_dec = yearly_data.previous_year_data != 0? Math.abs( ((yearly_data.previous_year_data - yearly_data.current_year_data)/yearly_data.previous_year_data)*100 ) : 0; if (percent_inc_dec) { stats_class = "year_value_down"; arrow_type = "fa fa-arrow-down"; } } if (!$('.'+t_info['data_containers'][0]+' span.value span').hasClass('stats')) { $('.'+t_info['data_containers'][0]+' .value').append( `
` +`(` +` ` + STAT.formatNumToFr(percent_inc_dec) + `%` +`)` ); } else { $('.'+t_info['data_containers'][0]+' .value span').html( `(` +` ` + STAT.formatNumToFr(percent_inc_dec) + `%` +`)` ); } }, /* Nombre d'inscription */ 'prepare_y_registrations_table': function (t_info, data){ /* Initialize variables */ var yearly_data = { 'current_year': parseInt($('.'+t_info['data_containers'][0]+' .data_year').html()), 'previous_year': parseInt($('.'+t_info['data_containers'][1]+' .data_year').html()), 'current_year_data': 0, 'previous_year_data': 0, }; data.forEach(function(row){ if (row.value != null) { if (yearly_data.current_year == row.data_year) { yearly_data.current_year_data = parseFloat(row.value? row.value : 0); $('.'+t_info['data_containers'][0]+' .value').html( STAT.formatNumToFr(yearly_data.current_year_data) ); } if (yearly_data.previous_year == row.data_year) { yearly_data.previous_year_data = parseFloat(row.value ? row.value : 0); $('.'+t_info['data_containers'][1]+' .value').html( STAT.formatNumToFr(yearly_data.previous_year_data) ); } } }); /* Calculate the percentage increase*/ var percent_inc_dec = yearly_data.previous_year_data != 0? Math.abs( ((yearly_data.current_year_data - yearly_data.previous_year_data)/yearly_data.previous_year_data)*100 ) : 0; var stats_class = "year_value_zero"; if (percent_inc_dec) { /* Set the increased/decreased indicator */ stats_class = "year_value_up"; var arrow_type = "fa fa-arrow-up"; } if ( yearly_data.current_year_data < yearly_data.previous_year_data ) { /* Calculate the percentage decrease */ percent_inc_dec = yearly_data.previous_year_data != 0? Math.abs( ((yearly_data.previous_year_data - yearly_data.current_year_data)/yearly_data.previous_year_data)*100 ) : 0; if (percent_inc_dec) { stats_class = "year_value_down"; arrow_type = "fa fa-arrow-down"; } } if (!$('.'+t_info['data_containers'][0]+' span.value span').hasClass('stats')) { $('.'+t_info['data_containers'][0]+' .value').append( `
` +`(` +` ` + STAT.formatNumToFr(percent_inc_dec) + `%` +`)` ); } else { $('.'+t_info['data_containers'][0]+' .value span').html( `(` +` ` + STAT.formatNumToFr(percent_inc_dec) + `%` +`)` ); } }, 'prepare_f_subscribers_table': function (t_info, data){ /* Initialize variables */ var total_data; data.forEach(function(row){ if (row.value != null) { $('.' + t_info['data_containers'][0] + ' .value').html(STAT.formatNumToFr(row.value)); } }); }, /* /Nombre d'inscription */ /* Nombre d'événements par statuts */ 'prepare_y_events_table': function (t_info, data){ /* Initialize variables */ var yearly_data = { 'current_year': parseInt($('.'+t_info['data_containers'][0]+' .data_year').html()), 'previous_year': parseInt($('.'+t_info['data_containers'][1]+' .data_year').html()), 'current_year_data': 0, 'previous_year_data': 0, }; data.forEach(function(row){ if (row.value != null) { if (yearly_data.current_year == row.data_year) { yearly_data.current_year_data = parseFloat(row.value? row.value : 0); $('.'+t_info['data_containers'][0]+' .value').html( STAT.formatNumToFr(yearly_data.current_year_data) ); } if (yearly_data.previous_year == row.data_year) { yearly_data.previous_year_data = parseFloat(row.value ? row.value : 0); $('.'+t_info['data_containers'][1]+' .value').html( STAT.formatNumToFr(yearly_data.previous_year_data) ); } } }); /* Calculate the percentage increase*/ var percent_inc_dec = yearly_data.previous_year_data != 0? Math.abs( ((yearly_data.current_year_data - yearly_data.previous_year_data)/yearly_data.previous_year_data)*100 ) : 0; var stats_class = "year_value_zero"; if (percent_inc_dec) { /* Set the increased/decreased indicator */ stats_class = "year_value_up"; var arrow_type = "fa fa-arrow-up"; } if ( yearly_data.current_year_data < yearly_data.previous_year_data ) { /* Calculate the percentage decrease */ percent_inc_dec = yearly_data.previous_year_data != 0? Math.abs( ((yearly_data.previous_year_data - yearly_data.current_year_data)/yearly_data.previous_year_data)*100 ) : 0; if (percent_inc_dec) { stats_class = "year_value_down"; arrow_type = "fa fa-arrow-down"; } } if (!$('.'+t_info['data_containers'][0]+' span.value span').hasClass('stats')) { $('.'+t_info['data_containers'][0]+' .value').append( `
` +`(` +` ` + STAT.formatNumToFr(percent_inc_dec) + `%` +`)` ); } else { $('.'+t_info['data_containers'][0]+' .value span').html( `(` +` ` + STAT.formatNumToFr(percent_inc_dec) + `%` +`)` ); } }, 'prepare_f30days_events_table': function (t_info, data){ /* Initialize variables */ var total_data; data.forEach(function(row){ if (row.value != null) { $('.' + t_info['data_containers'][0] + ' .value').html(STAT.formatNumToFr(parseInt(row.value))); } }); }, 'prepare_f_events_per_status_table': function (t_info, data){ /* Initialize variables */ var total_data; data.forEach(function(row){ if (row.value != null) { $('.fevents_'+ row.bostat +' .value').html(STAT.formatNumToFr(parseInt(row.value))); } }); }, /* /Nombre d'événements par statuts */ /* Nombre de réservations effectuées */ 'prepare_y_reservations_per_subs_table': function (t_info, data){ /* Initialize variables */ var yearly_data = { 'current_year': parseInt($('.'+t_info['data_containers'][0]+' .data_year').html()), 'previous_year': parseInt($('.'+t_info['data_containers'][1]+' .data_year').html()), 'current_year_data': 0, 'previous_year_data': 0, }; data.forEach(function(row){ if (row.value != null) { if (yearly_data.current_year == row.data_year) { yearly_data.current_year_data = parseFloat(row.value? row.value : 0); $('.'+t_info['data_containers'][0]+' .value').html( STAT.formatNumToFr(yearly_data.current_year_data) ); } if (yearly_data.previous_year == row.data_year) { yearly_data.previous_year_data = parseFloat(row.value ? row.value : 0); $('.'+t_info['data_containers'][1]+' .value').html( STAT.formatNumToFr(yearly_data.previous_year_data) ); } } }); /* Calculate the percentage increase*/ var percent_inc_dec = yearly_data.previous_year_data != 0? Math.abs( ((yearly_data.current_year_data - yearly_data.previous_year_data)/yearly_data.previous_year_data)*100 ) : 0; var stats_class = "year_value_zero"; if (percent_inc_dec) { /* Set the increased/decreased indicator */ stats_class = "year_value_up"; var arrow_type = "fa fa-arrow-up"; } if ( yearly_data.current_year_data < yearly_data.previous_year_data ) { /* Calculate the percentage decrease */ percent_inc_dec = yearly_data.previous_year_data != 0? Math.abs( ((yearly_data.previous_year_data - yearly_data.current_year_data)/yearly_data.previous_year_data)*100 ) : 0; if (percent_inc_dec) { stats_class = "year_value_down"; arrow_type = "fa fa-arrow-down"; } } if (!$('.'+t_info['data_containers'][0]+' span.value span').hasClass('stats')) { $('.'+t_info['data_containers'][0]+' .value').append( `
` +`(` +` ` + STAT.formatNumToFr(percent_inc_dec) + `%` +`)` ); } else { $('.'+t_info['data_containers'][0]+' .value span').html( `(` +` ` + STAT.formatNumToFr(percent_inc_dec) + `%` +`)` ); } }, 'prepare_f30days_reservations_per_subs_table': function (t_info, data){ /* Initialize variables */ var total_data; data.forEach(function(row){ if (row.value != null) { $('.' + t_info['data_containers'][0] + ' .value').html(STAT.formatNumToFr(parseFloat(row.value))); } }); }, /* /Nombre de réservations effectuées */ /* Nombre de places réservées */ 'prepare_y_reservations_table': function (t_info, data){ /* Initialize variables */ var yearly_data = { 'current_year': parseInt($('.'+t_info['data_containers'][0]+' .data_year').html()), 'previous_year': parseInt($('.'+t_info['data_containers'][1]+' .data_year').html()), 'current_year_data': 0, 'previous_year_data': 0, }; data.forEach(function(row){ if (row.value != null) { if (yearly_data.current_year == row.data_year) { yearly_data.current_year_data = parseFloat(row.value? row.value : 0); $('.'+t_info['data_containers'][0]+' .value').html( STAT.formatNumToFr(yearly_data.current_year_data) ); } if (yearly_data.previous_year == row.data_year) { yearly_data.previous_year_data = parseFloat(row.value ? row.value : 0); $('.'+t_info['data_containers'][1]+' .value').html( STAT.formatNumToFr(yearly_data.previous_year_data) ); } } }); /* Calculate the percentage increase*/ var percent_inc_dec = yearly_data.previous_year_data != 0 ? Math.abs( ((yearly_data.current_year_data - yearly_data.previous_year_data)/yearly_data.previous_year_data)*100 ) : 0; var stats_class = "year_value_zero"; if (percent_inc_dec) { /* Set the increased/decreased indicator */ stats_class = "year_value_up"; var arrow_type = "fa fa-arrow-up"; } if ( yearly_data.current_year_data < yearly_data.previous_year_data ) { /* Calculate the percentage decrease */ percent_inc_dec = yearly_data.previous_year_data != 0? Math.abs( ((yearly_data.previous_year_data - yearly_data.current_year_data)/yearly_data.previous_year_data)*100 ) : 0; if (percent_inc_dec) { stats_class = "year_value_down"; arrow_type = "fa fa-arrow-down"; } } if (!$('.'+t_info['data_containers'][0]+' span.value span').hasClass('stats')) { $('.'+t_info['data_containers'][0]+' .value').append( `
` +`(` +` ` + STAT.formatNumToFr(percent_inc_dec) + `%` +`)` ); } else { $('.'+t_info['data_containers'][0]+' .value span').html( `(` +` ` + STAT.formatNumToFr(percent_inc_dec) + `%` +`)` ); } }, 'prepare_f30days_reservations_table': function (t_info, data){ /* Initialize variables */ var total_data; data.forEach(function(row){ if (row.value != null) { $('.' + t_info['data_containers'][0] + ' .value').html(STAT.formatNumToFr(parseFloat(row.value))); } }); }, /* /Nombre de places réservées */ /* Nombre d'annulations effectuées */ 'prepare_y_cancellations_table': function (t_info, data){ /* Initialize variables */ var yearly_data = { 'current_year': parseInt($('.'+t_info['data_containers'][0]+' .data_year').html()), 'previous_year': parseInt($('.'+t_info['data_containers'][1]+' .data_year').html()), 'current_year_data': 0, 'previous_year_data': 0, }; data.forEach(function(row){ if (row.value != null) { if (yearly_data.current_year == row.data_year) { yearly_data.current_year_data = parseFloat(row.value? row.value : 0); $('.'+t_info['data_containers'][0]+' .value').html( STAT.formatNumToFr(yearly_data.current_year_data) ); } if (yearly_data.previous_year == row.data_year) { yearly_data.previous_year_data = parseFloat(row.value ? row.value : 0); $('.'+t_info['data_containers'][1]+' .value').html( STAT.formatNumToFr(yearly_data.previous_year_data) ); } } }); /* Calculate the percentage increase*/ var percent_inc_dec = yearly_data.previous_year_data != 0? Math.abs( ((yearly_data.current_year_data - yearly_data.previous_year_data)/yearly_data.previous_year_data)*100 ) : 0; var stats_class = "year_value_zero"; if (percent_inc_dec) { /* Set the increased/decreased indicator */ stats_class = "year_value_up"; var arrow_type = "fa fa-arrow-up"; } if ( yearly_data.current_year_data < yearly_data.previous_year_data ) { /* Calculate the percentage decrease */ percent_inc_dec = yearly_data.previous_year_data != 0? Math.abs( ((yearly_data.previous_year_data - yearly_data.current_year_data)/yearly_data.previous_year_data)*100 ) : 0; if (percent_inc_dec) { stats_class = "year_value_down"; arrow_type = "fa fa-arrow-down"; } } if (!$('.'+t_info['data_containers'][0]+' span.value span').hasClass('stats')) { $('.'+t_info['data_containers'][0]+' .value').append( `
` +`(` +` ` + STAT.formatNumToFr(percent_inc_dec) + `%` +`)` ); } else { $('.'+t_info['data_containers'][0]+' .value span').html( `(` +` ` + STAT.formatNumToFr(percent_inc_dec) + `%` +`)` ); } }, 'prepare_f30days_cancellations_table': function (t_info, data){ /* Initialize variables */ var total_data; data.forEach(function(row){ if (row.value != null) { $('.' + t_info['data_containers'][0] + ' .value').html(STAT.formatNumToFr(parseFloat(row.value))); } }); }, /* /Nombre d'annulations effectuées */ 'prepare_f_searches_table': function (t_info, data){ /* Initialize variables */ var months = [ 'Tous les mois', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre' ], filter_data = { 'monthly' : '', 'type' : '', 'city' : '', }, month_index; STAT.total_search = 0; data.forEach(function(row){ switch (row.gev_rdatalabel) { case 'filter-month': month_index = parseInt(row.gev_raction); if (month_index > 0 && month_index < months.length) { filter_data.monthly += '' +'' + months[month_index] + '' +'' + row.gev_rdata + '' +''; STAT.total_search += parseInt(row.gev_rdata); } break; case 'filter-type': filter_data.type += '' +''+ row.label +'' +''+row.gev_rdata+'' +''; STAT.total_search += parseInt(row.gev_rdata); break; case 'filter-city': filter_data.city += '' +''+ row.label +'' +''+row.gev_rdata+'' +''; STAT.total_search += parseInt(row.gev_rdata); break; } }); if (!filter_data.monthly) { filter_data.monthly = 'Pas de données'; } if (!filter_data.type) { filter_data.type = 'Pas de données'; } if (!filter_data.city) { filter_data.city = 'Pas de données'; } $('.filter-month tbody').html(filter_data.monthly); $('.filter-type tbody').html(filter_data.type); $('.filter-city tbody').html(filter_data.city); $('.total-search .value').html(STAT.total_search? STAT.total_search : 0); }, 'prepare_faq_searches_table': function (t_info, data){ /* Initialize variables */ var faq_search_data = ''; data.forEach(function(row){ faq_search_data += '' + ''+row.gev_rdata+'' + ''+row.gev_raction+'' + ''; STAT.total_search += parseInt(row.gev_rdata); }); if (!faq_search_data) { faq_search_data = 'Pas de données';; } $('.faq_search tbody').html(faq_search_data); }, 'prepare_faq_stat_table': function (t_info, data){ console.log(data); /* Initialize variables */ let faq_stat_data = ''; let subject = []; let subject_counter = STAT.groupQuestionBySubject(data); let counter = 0, rowspan = 0; data.forEach(function(row, key){ // Checks if subject is already taken let subject_name = ''; if (!subject.includes(row.subject_id)) { rowspan = subject_counter[counter]; subject_name = row.subject; subject.push(row.subject_id); ++counter; } faq_stat_data += ''; if(subject_name) { faq_stat_data += ''+subject_name+''; } faq_stat_data += ''+row.question+'' + ''+row.helpful+'' + ''+((row.vol_helpful)?row.vol_helpful:0)+'%' + ''+row.not_helpful+'' + ''+((row.vol_not_helpful)?row.vol_not_helpful:0)+'%' + ''; }); if (!faq_stat_data) { faq_stat_data = 'Pas de données';; } $('.faq_stat tbody').append(faq_stat_data); }, }; /** * @method Count the number of question by subject * @param object data subjects with questions * @return object counted questions per subject */ STAT.groupQuestionBySubject = function(data) { let subject = []; let subject_counter = []; let question_counter = 0; data.forEach(function(row, key){ // Checks if subject is already taken let subject_name = ''; if (!subject.includes(row.subject_id)) { if(key > 0 && (key+1) != data.length) { subject_counter.push(question_counter); } question_counter = 0; subject.push(row.subject_id); } question_counter++; if ((key+1) == data.length) { subject_counter.push(question_counter); } }); return subject_counter; } /** ** @method generate graphs per set ** @param array graphs to be generated */ STAT.plotGraph = function(g_info, graph_data){ // reset the graph container $('#'+g_info['container_name']).remove(); $('#'+g_info['container_name']+'-container').html(''); // prepare graph details var ctx = document.getElementById(g_info['container_name']).getContext('2d'); // graph it! STAT.graphs[g_info['container_name']] = new Chart(ctx,{ type: g_info['graph_type'], options: g_info['options'], data: graph_data, }); }; /** ** @method generate graphs per set ** @param array graphs to be generated */ STAT.generateGraphs = function(graph_category_list){ STAT.setDateFilter(); STAT.setUserFilter(); STAT.resetGraphBoxValues(); STAT.toggleLoader('tab', 'show'); graph_category_list.forEach(function(graph_category){ var g_info = '', utypes; /* Set graph info defined in graph configs*/ g_info = STAT.graph_configs[graph_category]; utypes = g_info.graph_type == 'pie'? 'none' : STAT.graph_configs.general.utypes; $.ajax({ type: 'GET', url: STAT.graph_configs.general.data_url +g_info['data_name']+'/'+g_info['tbl_abbrev']+'/'+utypes+'/'+ STAT.date_range.start_date +'/'+STAT.date_range.end_date, async: false, dataType : 'json', data : {type : "statistics"}, }) .done(function(data) { /*Plot data*/ try { STAT.prepAndPlot[`prepare_${graph_category}`](g_info, data); } catch (e) { $('#'+g_info['container_name']).remove(); $('#'+g_info['container_name']+'-container').append('

Pas de données

'); } finally { } }) .fail(function() { $('#'+g_info['container_name']).remove(); $('#'+g_info['container_name']+'-container').append('

Pas de données

'); }) .always(function() { }); }); }; /** ** @method generate tables per set ** @param array graphs to be generated */ STAT.generateTables = function(table_category_list){ STAT.setDateFilter(); STAT.toggleLoader('tab', 'show'); table_category_list.forEach(function(table_category){ var t_info = '', utypes; /* Set table info defined in table configs*/ t_info = STAT.table_configs[table_category]; $.ajax({ type: 'GET', url: STAT.table_configs.general.data_url + t_info['data_name'] + '/' + STAT.date_range.start_date +'/'+STAT.date_range.end_date, async: false, dataType : 'json', data : {type : "statistics"}, }) .done(function(data) { /*Plot data*/ try { STAT.prepAndPlot[`prepare_${table_category}`](t_info, data); } catch (e) { } finally { } }) .fail(function() { }) .always(function() { }); if (table_category == 'faq_searches_table') { STAT.toggleLoader('tab', 'remove'); STAT.toggleLoader('filter', 'remove'); } }); }; /** ** @method export dashboard data to excel ** @param array graphs to be generated */ STAT.exportDashboardData = function(){ STAT.setDateFilter(); $('a#export_dashboard_data').attr('href', STAT.base_url + 'export_dashboard/'+ STAT.date_range['start_date'] +'/'+ STAT.date_range['end_date']); }; return STAT; })(jQuery, this);; /***************************************************************************** * * Main execution * ****************************************************************************/ statistics.initConfigs(); statistics.generateGraphs(statistics.graph_list_per_set['first']); statistics.generateTables(statistics.table_list_per_set['first']); statistics.generateTables(statistics.table_list_per_set['second']); statistics.generateTables(statistics.table_list_per_set['third']);