2018-03-21 17:10:12 +00:00
|
|
|
|
|
|
|
/* (1) Load statistics
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Initialize list */
|
2018-04-07 10:40:40 +00:00
|
|
|
gstore.add('stats', null);
|
2018-03-21 17:10:12 +00:00
|
|
|
gstore.add('dimensions', null);
|
|
|
|
|
|
|
|
/* (2) Get statistics */
|
|
|
|
api.call('GET department/stats', {}, function(rs) {
|
|
|
|
|
|
|
|
// {1} If error -> abort //
|
|
|
|
if (rs.error !== 0) {
|
|
|
|
return console.log('No formation found, error: ' + rs.error);
|
|
|
|
}
|
|
|
|
|
2018-03-31 11:36:32 +00:00
|
|
|
let maxValue = null; // plus haute valeur des stats
|
|
|
|
let maxLabelLength = null; // plus longues chaîne de caractères pour les stats
|
|
|
|
let data = {}; // ensemble des statistiques à transmettre à VueJS
|
2018-03-21 17:10:12 +00:00
|
|
|
let map = {
|
2018-03-31 11:33:08 +00:00
|
|
|
"potentiel" : "Heures potentielles",
|
|
|
|
"sous_service" : "Heures en sous-services",
|
2018-03-21 17:10:12 +00:00
|
|
|
"heures_comp" : "Heures comp.",
|
|
|
|
"heures_vacataire" : "Heures vacataires",
|
2018-03-31 11:33:08 +00:00
|
|
|
"heures_exterieur" : "Heures à l'extérieurs",
|
2018-03-21 17:10:12 +00:00
|
|
|
"heures_ue_desactive" : "Heures UE annulées",
|
|
|
|
"nbr_ue_desactive" : "Nombre d'UE annulées"
|
|
|
|
};
|
|
|
|
|
|
|
|
for (let stat in rs.data) {
|
2018-03-31 11:36:32 +00:00
|
|
|
// détection de la plus grande valeur statistique
|
2018-03-21 17:10:12 +00:00
|
|
|
maxValue = rs.data[stat] > maxValue ? rs.data[stat] : maxValue;
|
2018-03-31 11:36:32 +00:00
|
|
|
// détection du plus grand nom présent
|
2018-03-31 11:33:08 +00:00
|
|
|
maxLabelLength = map[stat].length > maxLabelLength ? map[stat].length : maxLabelLength;
|
2018-03-21 17:10:12 +00:00
|
|
|
|
|
|
|
data[map[stat]] = Math.round(rs.data[stat] * 100) / 100;
|
|
|
|
}
|
|
|
|
|
2018-03-31 11:36:32 +00:00
|
|
|
// légendes à afficher en plus de la valeur
|
2018-03-31 11:33:08 +00:00
|
|
|
gstore.get.titles = {};
|
|
|
|
gstore.get.titles[map['heures_ue_desactive']] = `sur ${data[map['nbr_ue_desactive']]} UE annulées`;
|
|
|
|
|
2018-03-31 11:36:32 +00:00
|
|
|
// statistiques à ne pas afficher
|
2018-03-31 11:33:08 +00:00
|
|
|
delete data[map['nbr_ue_desactive']];
|
|
|
|
|
2018-03-21 17:10:12 +00:00
|
|
|
gstore.get.stats = data;
|
|
|
|
gstore.get.dimensions = {
|
|
|
|
padding: 5,
|
|
|
|
text: {
|
2018-04-07 10:40:40 +00:00
|
|
|
size: maxLabelLength * 8.5,
|
2018-03-21 17:10:12 +00:00
|
|
|
alignH: 5,
|
|
|
|
alignV: 20,
|
|
|
|
},
|
|
|
|
bin: {
|
|
|
|
count: Object.keys(gstore.get.stats).length,
|
|
|
|
width: 30,
|
|
|
|
spacing: 15,
|
|
|
|
margin: 5
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (maxValue != null) {
|
|
|
|
let magnitude = Math.pow(10, maxValue.length-1)/2; // ordre de grandeur du nombre
|
|
|
|
maxValue = Math.round(
|
|
|
|
((gstore.get.dimensions.bin.margin/100)+1) // on rajoute la marge afin qu'un "bin" ne dépasse jamais sur la droite
|
|
|
|
* maxValue / magnitude ) * magnitude;
|
|
|
|
}
|
|
|
|
|
|
|
|
gstore.get.maxValue = maxValue;
|
|
|
|
gstore.get.dimensions.axis = {
|
|
|
|
height: (gstore.get.dimensions.bin.count*gstore.get.dimensions.bin.width) + ((gstore.get.dimensions.bin.count)*gstore.get.dimensions.bin.spacing),
|
|
|
|
width: 500,
|
|
|
|
precision: 4
|
|
|
|
};
|
2018-04-07 10:40:40 +00:00
|
|
|
|
|
|
|
gstore.get.viewBox = `0 0 ${gstore.get.dimensions.axis.width + gstore.get.dimensions.text.size + 50} ${gstore.get.dimensions.axis.height + 30}`;
|
2018-03-21 17:10:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gstore.add('colors', ["blue", "yellow", "green", "red", "purple", "lightblue", "lightred", "lightyellow", "lightgreen", "lightpurple"]);
|