#14; Gestion du graphique de répartition des jours de la semaine (séparation entre 'appels' et 'sms')
This commit is contained in:
parent
f8b8d0aded
commit
ee055569f2
|
@ -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();
|
||||
|
||||
|
|
|
@ -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" }
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
@ -260,7 +262,8 @@
|
|||
'colorByPoint' => true,
|
||||
'data' => array(
|
||||
array( 'name' => 'Homme', 'y' => $H ),
|
||||
array( 'name' => 'Femme', 'y' => $F )
|
||||
array( 'name' => 'Femme', 'y' => $F ),
|
||||
array( 'name' => 'Indéterminé', 'y' => $I )
|
||||
)
|
||||
))
|
||||
);
|
||||
|
@ -364,13 +367,14 @@
|
|||
'ModuleError' => ManagerError::Success,
|
||||
'xlabels' => $labels,
|
||||
'title' => 'Répartition des ages',
|
||||
'pointFormat' => '{series.name}: <b>{point.y:.1f}%</b>',
|
||||
'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}: <b>{point.y:.1f}%</b>',
|
||||
'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}: <b>{point.y:1f} communications</b>',
|
||||
'series' => array(
|
||||
array( // En fonction des appels
|
||||
'name' => 'appels',
|
||||
'data' => $weekdays['phone']
|
||||
),
|
||||
array( // En fonction des sms
|
||||
'name' => 'sms',
|
||||
'data' => $weekdays['sms']
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<charts.length;c++){var request={path:"chart/"+charts[c],subject:subject};api.send(request,function(a,b){console.log(api.buffer);var e=b[0];if(0!=a.ModuleError)return!1;var d={chart:{renderTo:canvas[e],defaultSeriesType:types[e]},series:a.series,plotOptions:{pie:{allowPointSelect:!0,cursor:"pointer",dataLabels:{enabled:!0,format:"<b>{point.name}</b>: {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:"<b>{point.name}</b>: {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<charts.length;c++){var request={path:"chart/"+charts[c],subject:subject};api.send(request,function(a,d){console.log(api.buffer);var e=d[0];if(0!=a.ModuleError)return!1;var b={chart:{renderTo:canvas[e],type:types[e]},series:a.series,plotOptions:plotOptions[e]};null!=a.xlabels&&(b.xAxis={categories:a.xlabels});null!=a.ylabels&&(b.yAxis={categories:a.ylabels});null!=a.title&&(b.title={text:a.title});null!=a.pointFormat&&(b.tooltip={pointFormat:a.pointFormat});console.log(b);instances[e]=new Highcharts.Chart(b)},
|
||||
null,c)};
|
||||
|
|
|
@ -22,11 +22,37 @@ Chart.defaults.global.onClick = function(e, c){
|
|||
subject = 273;
|
||||
|
||||
|
||||
var charts = ['sexe', 'direction', 'type', 'ages', 'relations'];
|
||||
var types = ['pie', 'pie', 'pie', 'column', 'bar'];
|
||||
var charts = ['sexe','direction', 'type', 'ages', 'relations', 'weekdays'];
|
||||
var types = ['pie', 'pie', 'pie', 'column', 'bar', 'column'];
|
||||
var canvas = []; // Contiendra les canvas
|
||||
var instances = []; // Contiendra les charts
|
||||
|
||||
var plotOptions = [ { pie: { // pie
|
||||
innerSize: '50%',
|
||||
allowPointSelect: true,
|
||||
cursor: 'pointer',
|
||||
startAngle: -90,
|
||||
endAngle: 90,
|
||||
dataLabels: {
|
||||
enabled: true,
|
||||
distance: -45,
|
||||
format: '<b>{point.name}</b>: {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: '<b>{point.name}</b>: {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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue