graphe des stats par promo a la volee avec gnuplot
authorPascal Corpet <pascal.corpet@m4x.org>
Sun, 16 Jan 2005 13:38:40 +0000 (13:38 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:41 +0000 (23:27 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-352

htdocs/stats/graph_by_promo.php [new file with mode: 0644]
templates/stats/nb_by_promo.tpl

diff --git a/htdocs/stats/graph_by_promo.php b/htdocs/stats/graph_by_promo.php
new file mode 100644 (file)
index 0000000..0595b7b
--- /dev/null
@@ -0,0 +1,82 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+require_once("xorg.inc.php");
+
+new_skinned_page('index.tpl', AUTH_COOKIE);
+$promo = Env::getInt('promo', Session::getInt('promo'));
+
+// date de départ
+$depart = 1920;
+
+//recupere le nombre d'inscriptions par jour sur la plage concernée
+$res = $globals->xdb->iterRow(
+        "SELECT  IF (promo < $depart, ".($depart-1).", promo) AS annee,COUNT(user_id)
+           FROM  auth_user_md5
+          WHERE  promo >= $depart AND perms IN ('admin','user')
+       GROUP BY  annee");
+
+//genere des donnees compatibles avec GNUPLOT
+$inscrits='';
+
+// la première ligne contient le total des inscrits avant la date de départ
+list(,$init_nb) = $res->next();
+$total = $init_nb;
+
+list($annee, $nb) = $res->next();
+
+for ($i=$depart;$i<=date("Y");$i++) {
+    if ($annee<$i) {
+        if(!list($annee, $nb) = $res->next()) {
+            $annee = 0;
+            $nb = 0;
+        }
+    }
+    if ($nb > $total) $total = $nb;
+    if ($nb > 0 || $i < date("Y"))
+       $inscrits .= $i." ".$nb."\n";
+}
+
+//Genere le graphique à la volée avec GNUPLOT
+header( "Content-type: image/png");
+
+$ymin = round($init_nb*0.95,0);
+$ymax = round($total  *1.05,0);
+
+$gnuplot = <<<EOF2
+gnuplot <<EOF
+
+set term png small color
+set size 640/480
+set timefmt "%d/%m/%y"
+
+set xr [$depart:$i]
+set yr [$ymin:$ymax]
+
+set title "Nombre d'inscrits par promotion depuis $depart."
+
+plot "-" using 1:2 title 'inscrits' with boxes;
+{$inscrits}
+EOF
+EOF2;
+
+passthru($gnuplot);
+?>
index 14cfa4d..bdf0145 100644 (file)
@@ -68,7 +68,7 @@ Voici le nombre d'inscrits par promo :
 <h1>Inscrits par promo en (%)</h1>
 
 <div class="center">
-  <img src="{"stats/graph-promo2.png"|url}" alt="[graphe du nombre d'inscrits par promo]" />
+  <img src="{"stats/graph_by_promo.php"|url}" alt="[graphe du nombre d'inscrits par promo]" />
 </div>
 
 {/if}