From ee055569f2d6bf5bef14de4ba643734cc9a9c62a Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 25 May 2016 10:09:30 +0200 Subject: [PATCH] =?UTF-8?q?#14;=20Gestion=20du=20graphique=20de=20r=C3=A9p?= =?UTF-8?q?artition=20des=20jours=20de=20la=20semaine=20(s=C3=A9paration?= =?UTF-8?q?=20entre=20'appels'=20et=20'sms')?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- automate.php | 2 +- config/modules.json | 8 +++ manager/module/chart.php | 103 ++++++++++++++++++++++++++++++++++++--- view/js/charts-min.js | 9 ++-- view/js/charts.js | 51 +++++++++++-------- 5 files changed, 140 insertions(+), 33 deletions(-) diff --git a/automate.php b/automate.php index 0b81975..099fa54 100755 --- a/automate.php +++ b/automate.php @@ -96,7 +96,7 @@ $db = new lightdb('facebook_db', __ROOT__.'/src/dynamic/'); var_dump( array_keys($db->index())); $db->close(); - $req = new ModuleRequest('chart/direction', array( 'subject' => 273 )); + $req = new ModuleRequest('chart/weekdays', array( 'subject' => 273 )); $res = $req->dispatch(); diff --git a/config/modules.json b/config/modules.json index d8fa239..c4beb42 100755 --- a/config/modules.json +++ b/config/modules.json @@ -144,6 +144,14 @@ "parameters": { "subject": { "description": "Identifiant du sujet à étudier,", "type": "id" } } + }, + + "weekdays": { + "description": "Renvoie les données pour un graphique sur les communication parmi les jours de la semaine", + "permissions": ["admin"], + "parameters": { + "subject": { "description": "Identifiant du sujet à étudier,", "type": "id" } + } } }, diff --git a/manager/module/chart.php b/manager/module/chart.php index b682c3a..498f12b 100755 --- a/manager/module/chart.php +++ b/manager/module/chart.php @@ -225,6 +225,7 @@ =========================================================*/ $H = 0; $F = 0; + $I = 0; /* [3] S'il a un journal d'appel, on renvoie les données =========================================================*/ @@ -246,6 +247,7 @@ /* (3) On incrémente les compteurs */ $H += ($associatedContact['sexe']==0) ? 1 : 0; $F += ($associatedContact['sexe']==1) ? 1 : 0; + $I += ($associatedContact['sexe']==2) ? 1 : 0; } @@ -259,8 +261,9 @@ 'series' => array(array( 'colorByPoint' => true, 'data' => array( - array( 'name' => 'Homme', 'y' => $H ), - array( 'name' => 'Femme', 'y' => $F ) + array( 'name' => 'Homme', 'y' => $H ), + array( 'name' => 'Femme', 'y' => $F ), + array( 'name' => 'Indéterminé', 'y' => $I ) ) )) ); @@ -362,15 +365,16 @@ return array( 'ModuleError' => ManagerError::Success, - 'xlabels' => $labels, + 'xlabels' => $labels, 'title' => 'Répartition des ages', + 'pointFormat' => '{series.name}: {point.y:.1f}%', 'series' => array( array( - 'name' => 'Parmi les communications', + 'name' => 'communications', 'data' => array_values($age_classes) ), array( - 'name' => 'Parmi les contacts', + 'name' => 'contacts', 'data' => array_values($age_classesByContact) ) ) @@ -475,19 +479,102 @@ 'ModuleError' => ManagerError::Success, 'xlabels' => $labels, 'title' => 'Répartition des relations', + 'pointFormat' => '{series.name}: {point.y:.1f}%', 'series' => array( array( // En fonction du log - 'name' => 'Parmi les communications', + 'name' => 'communications', 'data' => $relations ), - array( // Parmi les contacts - 'name' => 'Parmi les contacts', + array( // contacts + 'name' => 'contacts', 'data' => $relationsByContact ) ) ); } + + + + + + /* RETOURNE UN JEU DE DONNEES POUR LES JOURS DE LA SEMAINE DES COMMUNICATIONS + * + */ + public static function weekdays($params){ + extract($params); + + $subject = intval($subject); + + + /* [1] On récupère les données de ce sujet + =========================================================*/ + $db = new lightdb('phone_db', __ROOT__.'/src/dynamic/'); + $data = $db->fetch($subject); + $db->close(); + + // Si erreur + if( $data === false ) + return array( 'ModuleError' => ManagerError::ModuleError ); + + + /* [2] On initialise les valeurs + =========================================================*/ + /* (1) On charge le dictionnaire */ + $dict = self::loadDictionary(); + if( $dict === false ) + return array( 'ModuleError' => ManagerError::ParsingFailed ); + + /* (2) On initialise les compteurs et labels */ + $weekdays = array( // jours de la semaine en fonction du log + 'phone' => array(), // pour les appels + 'sms' => array() // pour les sms + ); + $labels = array('Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'); + + for( $i = 0 ; $i < 7 ; $i++ ){ + $weekdays['phone'][$i] = 0; + $weekdays['sms'][$i] = 0; + } + + + /* [3] S'il a un journal d'appel, on renvoie les données + =========================================================*/ + if( isset($data['logs']) && is_array($data['logs']) ){ + + + /* (2) On incrémente les compteurs */ + foreach($data['logs'] as $log){ + + /* (3) On récupére le jour de la semaine */ + $weekday = date('N', $log['date']) - 1; + + /* (4) On incrémente le compteur de la classe d'age en question */ + $weekdays['phone'][ $weekday ] += ($log['type']==0) ? 1 : 0; + $weekdays['sms'][ $weekday ] += ($log['type']==1) ? 1 : 0; + + } + + } + + return array( + 'ModuleError' => ManagerError::Success, + 'xlabels' => $labels, + 'title' => 'Répartition dans la semaine', + 'pointFormat' => '{series.name}: {point.y:1f} communications', + 'series' => array( + array( // En fonction des appels + 'name' => 'appels', + 'data' => $weekdays['phone'] + ), + array( // En fonction des sms + 'name' => 'sms', + 'data' => $weekdays['sms'] + ) + ) + ); + } + } diff --git a/view/js/charts-min.js b/view/js/charts-min.js index ddb0606..3db9c9c 100644 --- a/view/js/charts-min.js +++ b/view/js/charts-min.js @@ -1,4 +1,5 @@ -var subPhone=$('section[data-sublink="phone"]');subPhone.style.display="flex";subPhone.style.flexWrap="wrap";subPhone.style.justifyContent="space-around";Chart.defaults.global.responsive=!1;Chart.defaults.global.title.display=!1;Chart.defaults.global.tooltips.footerFontSize=0;Chart.defaults.global.onClick=function(a,b){console.log(a);null!=b[0]&&console.log(b[0]._datasetIndex,b[0]._index)};subject=273; -var charts=["sexe","direction","type","ages","relations"],types=["pie","pie","pie","column","bar"],canvas=[],instances=[],c;for(c in charts)canvas[c]=document.createElement("div"),canvas[c].id=charts[c],canvas[c].style.width=canvas[c].style.height="pie"!=types[c]?"40em":"30em",canvas[c].style.margin="2em",subPhone.appendChild(canvas[c]); -for(c=0;c{point.name}: {point.percentage:.1f} %",style:{color:Highcharts.theme&&Highcharts.theme.contrastTextColor||"black"}}},bar:{allowPointSelect:!0,cursor:"pointer"}}}; -null!=a.xlabels&&(d.xAxis={categories:a.xlabels});null!=a.ylabels&&(d.yAxis={categories:a.ylabels});null!=a.title&&(d.title={text:a.title});null!=a.pointFormat&&(d.tooltip={pointFormat:a.pointFormat});instances[e]=new Highcharts.Chart(d)},null,c)}; +var subPhone=$('section[data-sublink="phone"]');subPhone.style.display="flex";subPhone.style.flexWrap="wrap";subPhone.style.justifyContent="space-around";Chart.defaults.global.responsive=!1;Chart.defaults.global.title.display=!1;Chart.defaults.global.tooltips.footerFontSize=0;Chart.defaults.global.onClick=function(a,d){console.log(a);null!=d[0]&&console.log(d[0]._datasetIndex,d[0]._index)};subject=273; +var charts="sexe direction type ages relations weekdays".split(" "),types="pie pie pie column bar column".split(" "),canvas=[],instances=[],plotOptions=[{pie:{innerSize:"50%",allowPointSelect:!0,cursor:"pointer",startAngle:-90,endAngle:90,dataLabels:{enabled:!0,distance:-45,format:"{point.name}: {point.percentage:.1f} %",style:{color:"white",textShadow:"0 0 2px black"}}}}];plotOptions[1]=plotOptions[0];plotOptions[2]=plotOptions[0];plotOptions[3]={column:{shadow:!1,borderWidth:0}}; +plotOptions[5]={column:{shadow:!1,borderWidth:0}};plotOptions[5].column.stacking="normal";plotOptions[4]={bar:{allowPointSelect:!0,cursor:"pointer"}};for(var c in charts)canvas[c]=document.createElement("div"),canvas[c].id=charts[c],canvas[c].style.width=canvas[c].style.height="pie"!=types[c]?"40em":"30em",canvas[c].style.margin="2em",subPhone.appendChild(canvas[c]); +for(c=0;c{point.name}: {point.percentage:.1f} %', + style: { color: 'white', textShadow: '0 0 2px black' } + } +} } ]; + +plotOptions[1] = plotOptions[0]; // PIE +plotOptions[2] = plotOptions[0]; // PIE + +// AGES + WEEKDAY +plotOptions[3] = { column: { shadow: false, borderWidth: 0 } }; +plotOptions[5] = { column: { shadow: false, borderWidth: 0 } }; +plotOptions[5].column.stacking = 'normal'; + +// RELATIONS +plotOptions[4] = { bar: { allowPointSelect: true, cursor: 'pointer' } }; + + /* [1] On crée les conteneurs =========================================================*/ for( var c in charts ){ @@ -72,25 +98,9 @@ for( var c = 0 ; c < charts.length ; c++ ){ =========================================================*/ /* (1) On définit les options */ var options = { - chart: { renderTo: canvas[c], defaultSeriesType: types[c] }, + chart: { renderTo: canvas[c], type: types[c] }, series: response.series, - plotOptions: { - pie: { - allowPointSelect: true, - cursor: 'pointer', - dataLabels: { - enabled: true, - format: '{point.name}: {point.percentage:.1f} %', - style: { - color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black' - } - } - }, - bar: { - allowPointSelect: true, - cursor: 'pointer' - } - } + plotOptions: plotOptions[c] }; // labels @@ -108,6 +118,7 @@ for( var c = 0 ; c < charts.length ; c++ ){ if( response.pointFormat != null ) options.tooltip = { pointFormat: response.pointFormat }; + console.log(options); /* (2) On crée le graphique */ instances[c] = new Highcharts.Chart(options);