85ee0549df87d54c9621bc22631c10d3007b70aa
2 /***************************************************************************
3 * Copyright (C) 2003-2009 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
66 "SELECT IF( date_ins>DATE_SUB(NOW(),INTERVAL $jours DAY),
67 TO_DAYS(date_ins)-TO_DAYS(NOW()),
68 ".(-($jours+
1)).") AS jour,
71 WHERE perms IN ('admin','user') AND deces = 0
74 //genere des donnees compatibles avec GNUPLOT
77 // la première ligne contient le total des inscrits avant la date de départ (J - $jours)
78 list(,$init_nb) = $res->next();
80 $numjour = - $jours - 1;
82 for ($i = -$jours; $i<=0; $i++
) {
84 if(!list($numjour, $nb) = $res->next()) {
89 if ($numjour==$i) $total+
=$nb;
90 $inscrits .= date('d/m/y',$i*DUREEJOUR+
time())." ".$total."\n";
93 //Genere le graphique à la volée avec GNUPLOT
94 pl_cached_dynamic_content_headers("image/png");
96 $delt = ($total - $init_nb)/10;
97 $delt = $delt ?
$delt : 5;
98 $ymin = round($init_nb - $delt,0);
99 $ymax = round($total +
$delt,0);
104 set term png small color
107 set timefmt
"%d/%m/%y"
112 set title
"Nombre d'inscrits"
114 plot
"-" using
1:2 title
'inscrits' with lines
;
123 function handler_graph(&$page, $promo = null
)
125 if ($promo == 'all') {
129 //recupere le nombre d'inscriptions par jour sur la plage concernée
131 "SELECT promo, SUM(perms IN ('admin', 'user')) / COUNT(*) * 100
133 WHERE promo >= $depart AND deces = 0
136 //genere des donnees compatibles avec GNUPLOT
139 // la première ligne contient le total des inscrits avant la date de départ
140 list($annee, $nb) = $res->next();
142 for ($i = $depart; $i <= date("Y"); $i++
) {
144 if(!list($annee, $nb) = $res->next()) {
149 if ($nb > 0 ||
$i < date('Y'))
150 $inscrits .= $i.' '.$nb."\n";
153 //Genere le graphique à la volée avec GNUPLOT
159 set term png small color
161 set timefmt
"%d/%m/%y"
163 set xr
[$depart:$fin]
166 set title
"Proportion d'inscrits par promotion depuis $depart, en %."
168 plot
"-" using
1:2 title
'inscrits' with boxes
;
174 //nombre de jours sur le graph
176 define('DUREEJOUR',24*3600);
178 "SELECT min(TO_DAYS(date_ins)-TO_DAYS(now()))
180 WHERE promo = {?} AND perms IN ('admin', 'user') AND deces = 0",
182 $jours = -$res->fetchOneCell();
184 //recupere le nombre d'inscriptions par jour sur la plage concernée
186 "SELECT IF( date_ins>DATE_SUB(NOW(),INTERVAL $jours DAY),
187 TO_DAYS(date_ins)-TO_DAYS(NOW()),
188 ".(-($jours+
1)).") AS jour,
191 WHERE promo = {?} AND perms IN ('admin','user') AND deces = 0
192 GROUP BY jour", $promo);
194 //genere des donnees compatibles avec GNUPLOT
197 // la première ligne contient le total des inscrits avant la date de départ (J - $jours)
198 list(,$init_nb) = $res->next();
201 list($numjour, $nb) = $res->next();
203 for ($i = -$jours;$i<=0;$i++
) {
205 if(!list($numjour, $nb) = $res->next()) {
210 if ($numjour==$i) $total+
=$nb;
211 $inscrits .= date('d/m/y',$i*DUREEJOUR+
time())." ".$total."\n";
214 //Genere le graphique à la volée avec GNUPLOT
215 $delt = ($total - $init_nb) / 10;
216 $delt +
= ($delt < 1);
217 $ymin = round($init_nb - $delt,0);
218 $ymax = round($total +
$delt,0);
223 set term png small color
226 set timefmt
"%d/%m/%y"
231 set title
"Nombre d'inscrits de la promotion $promo."
233 plot
"-" using
1:2 title
'inscrits' with lines
;
239 pl_cached_dynamic_content_headers("image/png");
244 function handler_promos(&$page, $promo = null
)
246 $page->changeTpl('stats/nb_by_promo.tpl');
249 "SELECT promo,COUNT(*)
251 WHERE promo > 1900 AND perms IN ('admin','user') AND deces = 0
256 while (list($p,$nb) = $res->next()) {
258 if(!isset($nbpromo[$p/10])) {
259 $nbpromo[$p/10] = Array('','','','','','','','','',''); // tableau de 10 cases vides
261 $nbpromo[$p/10][$p%10
]=Array('promo' => $p, 'nb' => $nb);
264 $page->assign_by_ref('nbs', $nbpromo);
265 $page->assign('min', $min-$min %
10);
266 $page->assign('max', $max+
10-$max%10
);
267 $page->assign('promo', $promo);
270 function handler_coupures(&$page, $cp_id = null
)
272 $page->changeTpl('stats/coupure.tpl');
274 if (!is_null($cp_id)) {
275 $res = XDB
::query("SELECT debut,
276 TIME_FORMAT(duree,'%kh%i') AS duree,
277 resume, description, services
279 WHERE id = {?}", $cp_id);
280 $cp = $res->fetchOneAssoc();
284 $cp['lg_services'] = serv_to_str($cp['services']);
285 $page->assign_by_ref('cp',$cp);
287 $beginning_date = date("Ymd", time() - 3600*24*21) . "000000";
288 $sql = "SELECT id, debut, resume, services
289 FROM coupures where debut > '$beginning_date' order by debut desc";
290 $page->assign('coupures', XDB
::iterator($sql));
291 $res = XDB
::iterator("SELECT host, text
293 WHERE state != 'ok'");
294 $page->assign('mxs', $res);
299 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: