#14; Prototype du graphique du sexe (homme/femme) pour chaque communication
This commit is contained in:
parent
d5d6887a58
commit
1975587df3
|
@ -94,7 +94,7 @@
|
|||
$db = new lightdb('phone_db', __ROOT__.'/src/dynamic/');
|
||||
var_dump( array_keys($db->index()));
|
||||
$db->close();
|
||||
$req = new ModuleRequest('chart/communication_type', array( 'subject' => 273 ));
|
||||
$req = new ModuleRequest('chart/sexe', array( 'subject' => 273 ));
|
||||
|
||||
$res = $req->dispatch();
|
||||
|
||||
|
|
|
@ -120,6 +120,14 @@
|
|||
"parameters": {
|
||||
"subject": { "description": "Identifiant du sujet à étudier,", "type": "id" }
|
||||
}
|
||||
},
|
||||
|
||||
"sexe": {
|
||||
"description": "Renvoie les données pour un graphique sur le sexe des contacts",
|
||||
"permissions": ["admin"],
|
||||
"parameters": {
|
||||
"subject": { "description": "Identifiant du sujet à étudier,", "type": "id" }
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
],
|
||||
|
||||
"contacts": [
|
||||
{ "id":"0", "number":"0102030405", "name":"", "sexe":"0", "age":"1", "studies1":"1", "reltype":"1", "dist":"0" },
|
||||
{ "id":"1", "number":"0502030405", "name":"", "sexe":"0", "age":"1", "studies1":"1", "reltype":"1", "dist":"0" },
|
||||
{ "id":"2", "number":"0502030561", "name":"", "sexe":"0", "age":"2", "studies1":"2", "reltype":"2", "dist":"1" },
|
||||
{ "id":"3", "number":"0502030717", "name":"", "sexe":"0", "age":"3", "studies1":"3", "reltype":"3", "dist":"2" },
|
||||
|
|
|
@ -119,9 +119,8 @@
|
|||
}else{
|
||||
|
||||
/* (1) On initialise les compteurs */
|
||||
$MISSED = 0;
|
||||
$OUTGOING = 0;
|
||||
$INCOMING = 0;
|
||||
$H = 0;
|
||||
$F = 0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -133,6 +132,73 @@
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* RETOURNE UN JEU DE DONNEES POUR LE SEXE DES CONTACTS
|
||||
*
|
||||
*/
|
||||
public static function sexe($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] S'il a un journal d'appel, on renvoie les données
|
||||
=========================================================*/
|
||||
if( isset($data['logs']) && is_array($data['logs']) ){
|
||||
|
||||
/* (1) On initialise les compteurs */
|
||||
$H = 0;
|
||||
$F = 0;
|
||||
|
||||
/* (2) On incrémente les compteurs */
|
||||
foreach($data['logs'] as $log){
|
||||
|
||||
/* (3) On récupère le contact associé */
|
||||
$associatedContact = null;
|
||||
foreach($data['contacts'] as $contact)
|
||||
if( $log['id'] == $contact['id'] )
|
||||
$associatedContact = $contact;
|
||||
|
||||
// Si on ne trouve pas, on passe au suivant
|
||||
if( is_null($associatedContact) )
|
||||
continue;
|
||||
|
||||
/* (4) On incrémente les compteurs */
|
||||
$H += ($associatedContact['sexe']==0) ? 1 : 0;
|
||||
$F += ($associatedContact['sexe']==1) ? 1 : 0;
|
||||
|
||||
}
|
||||
|
||||
/* [3] Si aucun journal d'appel
|
||||
=========================================================*/
|
||||
}else{
|
||||
|
||||
/* (1) On initialise les compteurs */
|
||||
$H = 0;
|
||||
$F = 0;
|
||||
|
||||
}/* (1) On initialise les compteurs */
|
||||
|
||||
|
||||
return array(
|
||||
'ModuleError' => ManagerError::Success,
|
||||
'labels' => array('HOMME', 'FEMME'),
|
||||
'data' => array($H, $F)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Chart du sexe (HOMME/FEMME)</title>
|
||||
<script type='text/javascript' src='/f/js/api-min/js/lib'></script> <!-- Gestion des transactions avec le serveur -->
|
||||
<script type='text/javascript' src='/f/js/_charts-min/js/lib'></script>
|
||||
</head>
|
||||
<body style='display: flex; flex-direction: row; justify-content: space-around; flex-wrap: wrap;'>
|
||||
|
||||
<canvas id="direction" width="400" height="400"></canvas>
|
||||
<canvas id="type" width="400" height="400"></canvas>
|
||||
<canvas id="sexe" width="400" height="400"></canvas>
|
||||
|
||||
|
||||
|
||||
<script type='text/javascript'>
|
||||
var api = new APIClass('/api/');
|
||||
|
||||
var direction = document.getElementById('direction');
|
||||
var type = document.getElementById('type');
|
||||
var sexe = document.getElementById('sexe');
|
||||
|
||||
/* [0] Paramètres globaux
|
||||
=========================================================*/
|
||||
Chart.defaults.global.responsive = false;
|
||||
|
||||
|
||||
/* [1] On récupére les données SEXE
|
||||
=========================================================*/
|
||||
/* (1) On rédige la requête */
|
||||
var request = {
|
||||
path: 'chart/sexe',
|
||||
subject: 273
|
||||
}
|
||||
|
||||
/* (2) On lance la requête */
|
||||
api.send(request, function(response){
|
||||
/* (3) Si erreur, on quitte */
|
||||
if( response.ModuleError != 0 )
|
||||
return false;
|
||||
|
||||
/* [2] On construit les données
|
||||
=========================================================*/
|
||||
var data = {
|
||||
labels: response.labels,
|
||||
datasets: [{
|
||||
data: response.data,
|
||||
backgroundColor: [ "#FF6384", "#36A2EB" ],
|
||||
hoverBackgroundColor: [ "#E65977", "#3090D1" ]
|
||||
}]
|
||||
}
|
||||
|
||||
/* [3] On construit notre graphique
|
||||
=========================================================*/
|
||||
var myDoughnutChart = new Chart(sexe, {
|
||||
type: 'doughnut',
|
||||
animation: { animateScale: true },
|
||||
data: data
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* [2] On récupére les données DIRECTION
|
||||
=========================================================*/
|
||||
/* (1) On rédige la requête */
|
||||
var request = {
|
||||
path: 'chart/communication_direction',
|
||||
subject: 273
|
||||
}
|
||||
|
||||
/* (2) On lance la requête */
|
||||
api.send(request, function(response){
|
||||
/* (3) Si erreur, on quitte */
|
||||
if( response.ModuleError != 0 )
|
||||
return false;
|
||||
|
||||
/* [2] On construit les données
|
||||
=========================================================*/
|
||||
var data = {
|
||||
labels: response.labels,
|
||||
datasets: [{
|
||||
data: response.data,
|
||||
backgroundColor: [ "#FF6384", "#36A2EB", "#FFCE56" ],
|
||||
hoverBackgroundColor: [ "#E65977", "#3090D1", "#E6B94D" ]
|
||||
}]
|
||||
}
|
||||
|
||||
/* [3] On construit notre graphique
|
||||
=========================================================*/
|
||||
var myDoughnutChart = new Chart(direction, {
|
||||
type: 'doughnut',
|
||||
animation: { animateScale: true },
|
||||
data: data
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* [1] On récupére les données TYPE
|
||||
=========================================================*/
|
||||
/* (1) On rédige la requête */
|
||||
var request = {
|
||||
path: 'chart/communication_type',
|
||||
subject: 273
|
||||
}
|
||||
|
||||
/* (2) On lance la requête */
|
||||
api.send(request, function(response){
|
||||
/* (3) Si erreur, on quitte */
|
||||
if( response.ModuleError != 0 )
|
||||
return false;
|
||||
|
||||
/* [2] On construit les données
|
||||
=========================================================*/
|
||||
var data = {
|
||||
labels: response.labels,
|
||||
datasets: [{
|
||||
data: response.data,
|
||||
backgroundColor: [ "#FF6384", "#36A2EB" ],
|
||||
hoverBackgroundColor: [ "#E65977", "#3090D1" ]
|
||||
}]
|
||||
}
|
||||
|
||||
/* [3] On construit notre graphique
|
||||
=========================================================*/
|
||||
var myDoughnutChart = new Chart(type, {
|
||||
type: 'doughnut',
|
||||
animation: { animateScale: true },
|
||||
data: data
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,57 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Chart du sexe (HOMME/FEMME)</title>
|
||||
<script type='text/javascript' src='/f/js/api-min/js/lib'></script> <!-- Gestion des transactions avec le serveur -->
|
||||
<script type='text/javascript' src='/f/js/_charts-min/js/lib'></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<canvas id="container" width="400" height="400"></canvas>
|
||||
|
||||
|
||||
<script type='text/javascript'>
|
||||
var api = new APIClass('/api/');
|
||||
var ctx = document.getElementById('container').getContext('2d');
|
||||
|
||||
|
||||
|
||||
/* [1] On récupére les données
|
||||
=========================================================*/
|
||||
/* (1) On rédige la requête */
|
||||
var request = {
|
||||
path: 'chart/sexe',
|
||||
subject: 273
|
||||
}
|
||||
|
||||
/* (2) On lance la requête */
|
||||
api.send(request, function(response){
|
||||
/* (3) Si erreur, on quitte */
|
||||
if( response.ModuleError != 0 )
|
||||
return false;
|
||||
|
||||
/* [2] On construit les données
|
||||
=========================================================*/
|
||||
var data = {
|
||||
labels: response.labels,
|
||||
datasets: [{
|
||||
data: response.data,
|
||||
backgroundColor: [ "#FF6384", "#36A2EB" ],
|
||||
hoverBackgroundColor: [ "#E65977", "#3090D1" ]
|
||||
}]
|
||||
}
|
||||
|
||||
/* [3] On construit notre graphique
|
||||
=========================================================*/
|
||||
var myDoughnutChart = new Chart(ctx, {
|
||||
type: 'doughnut',
|
||||
animation: { animateScale: true },
|
||||
data: data
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue