2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 function serv_to_str($params) {
23 $flags = explode(',',$params);
24 $trad = Array('web' => 'site web', 'mail'=> 'redirection mail',
25 'smtp' => 'serveur sécurisé d\'envoi de mails',
26 'nntp' => 'serveur des forums de discussion');
28 foreach ($flags as $flag) {
29 $ret[] = $trad[$flag];
31 return implode(', ',$ret);
34 class StatsModule
extends PLModule
39 'stats' => $this->make_hook('stats', AUTH_COOKIE
),
40 'stats/evolution' => $this->make_hook('evolution', AUTH_COOKIE
),
41 'stats/graph' => $this->make_hook('graph', AUTH_COOKIE
),
42 'stats/graph/evolution' => $this->make_hook('graph_evo', AUTH_COOKIE
),
43 'stats/promos' => $this->make_hook('promos', AUTH_COOKIE
),
45 'stats/coupures' => $this->make_hook('coupures', AUTH_PUBLIC
),
49 function handler_stats(&$page)
51 $page->changeTpl('stats/index.tpl');
54 function handler_evolution(&$page, $jours = 365)
56 $page->changeTpl('stats/evolution_inscrits.tpl');
57 $page->assign('jours', $jours);
60 function handler_graph_evo(&$page, $jours = 365)
62 define('DUREEJOUR', 24 * 3600);
64 //recupere le nombre d'inscriptions par jour sur la plage concernée
65 $res = XDB
::iterRow('SELECT IF(registration_date > DATE_SUB(NOW(), INTERVAL {?} DAY),
66 TO_DAYS(registration_date) - TO_DAYS(NOW()),
70 LEFT JOIN account_profiles AS ap ON(ap.uid = a.uid AND FIND_IN_SET(\'owner\', ap.flags))
71 LEFT JOIN profiles AS p ON (ap.pid = p.pid)
72 WHERE state = \'active\' AND p.deathdate IS NULL
73 GROUP BY jour', (int)$jours, 1 +
(int)$jours);
75 //genere des donnees compatibles avec GNUPLOT
78 // la première ligne contient le total des inscrits avant la date de départ (J - $jours)
79 list(,$init_nb) = $res->next();
81 $numjour = - $jours - 1;
83 for ($i = -$jours; $i<=0; $i++
) {
85 if(!list($numjour, $nb) = $res->next()) {
90 if ($numjour==$i) $total+
=$nb;
91 $inscrits .= date('d/m/y',$i*DUREEJOUR+
time())." ".$total."\n";
94 //Genere le graphique à la volée avec GNUPLOT
95 pl_cached_dynamic_content_headers("image/png");
97 $delt = ($total - $init_nb)/10;
98 $delt = $delt ?
$delt : 5;
99 $ymin = round($init_nb - $delt,0);
100 $ymax = round($total +
$delt,0);
105 set term png small color
108 set timefmt
"%d/%m/%y"
113 set title
"Nombre d'inscrits"
115 plot
"-" using
1:2 title
'inscrits' with lines
;
124 function handler_graph(&$page, $promo = null
)
126 if ($promo == 'all') {
130 //recupere le nombre d'inscriptions par jour sur la plage concernée
131 $res = XDB
::iterRow("SELECT pe.entry_year AS promo, SUM(state = 'active') / COUNT(*) * 100
133 INNER JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET('owner', ap.perms))
134 INNER JOIN profiles AS p ON (p.pid = ap.pid)
135 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET('primary', pe.flags))
136 WHERE pe.entry_year >= {?} AND p.deathdate IS NULL
137 GROUP BY promo", $depart);
139 //genere des donnees compatibles avec GNUPLOT
142 // la première ligne contient le total des inscrits avant la date de départ
143 list($annee, $nb) = $res->next();
145 for ($i = $depart; $i <= date("Y"); $i++
) {
147 if(!list($annee, $nb) = $res->next()) {
152 if ($nb > 0 ||
$i < date('Y'))
153 $inscrits .= $i.' '.$nb."\n";
156 //Genere le graphique à la volée avec GNUPLOT
162 set term png small color
164 set timefmt
"%d/%m/%y"
166 set xr
[$depart:$fin]
169 set title
"Proportion d'inscrits par promotion depuis $depart, en %."
171 plot
"-" using
1:2 title
'inscrits' with boxes
;
177 //nombre de jours sur le graph
179 define('DUREEJOUR', 24 * 3600);
181 $res = XDB
::query("SELECT MIN(TO_DAYS(a.registration_date) - TO_DAYS(NOW()))
183 INNER JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET('owner', ap.perms))
184 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET('primary', pe.flags))
185 WHERE pe.entry_year = {?} AND a.state = 'active'", (int)$promo);
186 $jours = -$res->fetchOneCell();
188 //recupere le nombre d'inscriptions par jour sur la plage concernée
189 $res = XDB
::iterRow("SELECT IF(a.registration_date > DATE_SUB(NOW(), INTERVAL {?} DAY),
190 TO_DAYS(a.registration_date) - TO_DAYS(NOW()),
194 INNER JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET('owner', ap.perms))
195 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET('primary', pe.flags))
196 WHERE pe.entry_year = {?} AND a.state = 'active'
197 GROUP BY jour", (int)$jours, 1 +
(int)$jours, (int)$promo);
199 //genere des donnees compatibles avec GNUPLOT
202 // la première ligne contient le total des inscrits avant la date de départ (J - $jours)
203 list(,$init_nb) = $res->next();
206 list($numjour, $nb) = $res->next();
208 for ($i = -$jours;$i<=0;$i++
) {
210 if(!list($numjour, $nb) = $res->next()) {
215 if ($numjour==$i) $total+
=$nb;
216 $inscrits .= date('d/m/y',$i*DUREEJOUR+
time())." ".$total."\n";
219 //Genere le graphique à la volée avec GNUPLOT
220 $delt = ($total - $init_nb) / 10;
221 $delt +
= ($delt < 1);
222 $ymin = round($init_nb - $delt,0);
223 $ymax = round($total +
$delt,0);
228 set term png small color
231 set timefmt
"%d/%m/%y"
236 set title
"Nombre d'inscrits de la promotion $promo."
238 plot
"-" using
1:2 title
'inscrits' with lines
;
244 pl_cached_dynamic_content_headers("image/png");
249 function handler_promos(&$page, $promo = null
)
251 $page->changeTpl('stats/nb_by_promo.tpl');
253 $res = XDB
::iterRow('SELECT pe.entry_year AS promo, COUNT(*)
255 INNER JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET(\'owner\', ap.perms))
256 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'primary\', pe.flags))
257 WHERE pe.entry_year >= 1900 AND a.state = \'active\'
262 while (list($p,$nb) = $res->next()) {
264 if(!isset($nbpromo[$p/10])) {
265 $nbpromo[$p/10] = Array('','','','','','','','','',''); // tableau de 10 cases vides
267 $nbpromo[$p/10][$p%10
]=Array('promo' => $p, 'nb' => $nb);
270 $page->assign_by_ref('nbs', $nbpromo);
271 $page->assign('min', $min-$min %
10);
272 $page->assign('max', $max+
10-$max%10
);
273 $page->assign('promo', $promo);
276 function handler_coupures(&$page, $cp_id = null
)
278 $page->changeTpl('stats/coupure.tpl');
280 if (!is_null($cp_id)) {
281 $res = XDB
::query("SELECT debut,
282 TIME_FORMAT(duree,'%kh%i') AS duree,
283 resume, description, services
285 WHERE id = {?}", $cp_id);
286 $cp = $res->fetchOneAssoc();
290 $cp['lg_services'] = serv_to_str($cp['services']);
291 $page->assign_by_ref('cp',$cp);
293 $beginning_date = date("Ymd", time() - 3600*24*21) . "000000";
294 $sql = "SELECT id, debut, resume, services
295 FROM downtimes where debut > '$beginning_date' order by debut desc";
296 $page->assign('coupures', XDB
::iterator($sql));
297 $res = XDB
::iterator("SELECT host, text
299 WHERE state != 'ok'");
300 $page->assign('mxs', $res);
305 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: