From: x2000habouzit Date: Sun, 9 Jul 2006 22:09:46 +0000 (+0000) Subject: move stats into new URI's X-Git-Tag: xorg/0.9.11~486 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=bf2692e365d5f0297ff06b118cb7e070961ea7be;p=platal.git move stats into new URI's git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@410 839d8a87-29fc-0310-9880-83ba4fa771e5 --- diff --git a/htdocs/stats/coupure.php b/htdocs/stats/coupure.php deleted file mode 100644 index 4702978..0000000 --- a/htdocs/stats/coupure.php +++ /dev/null @@ -1,56 +0,0 @@ - 'site web', 'mail'=> 'redirection mail', - 'smtp' => 'serveur sécurisé d\'envoi de mails', - 'nntp' => 'serveur des forums de discussion'); - $ret = Array(); - foreach ($flags as $flag) { - $ret[] = $trad[$flag]; - } - return implode(', ',$ret); -} - -if (Env::has('cp_id')) { - $res = $globals->xdb->query("SELECT UNIX_TIMESTAMP(debut) AS debut, - TIME_FORMAT(duree,'%kh%i') AS duree, - resume, description, services - FROM coupures - WHERE id = {?}", Env::getInt('cp_id')); - $cp = $res->fetchOneAssoc(); -} - -if($cp) { - $cp['lg_services'] = serv_to_str($cp['services']); - $page->assign_by_ref('cp',$cp); -} else { - $beginning_date = date("Ymd", time() - 3600*24*21) . "000000"; - $sql = "select id, UNIX_TIMESTAMP(debut) as debut, resume, services from coupures where debut > '$beginning_date' order by debut desc"; - $page->assign('coupures', $globals->xdb->iterator($sql)); -} - -$page->run(); -?> diff --git a/htdocs/stats/evolution_inscrits.php b/htdocs/stats/evolution_inscrits.php deleted file mode 100644 index 499e6ce..0000000 --- a/htdocs/stats/evolution_inscrits.php +++ /dev/null @@ -1,27 +0,0 @@ -run(); - -?> diff --git a/htdocs/stats/graph_by_promo.php b/htdocs/stats/graph_by_promo.php deleted file mode 100644 index 97665b8..0000000 --- a/htdocs/stats/graph_by_promo.php +++ /dev/null @@ -1,80 +0,0 @@ -xdb->iterRow( - "SELECT promo, SUM(perms IN ('admin', 'user')) / COUNT(*) * 100 - FROM auth_user_md5 - WHERE promo >= $depart AND deces = 0 - GROUP BY promo"); - -//genere des donnees compatibles avec GNUPLOT -$inscrits=''; - -// la première ligne contient le total des inscrits avant la date de départ -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 > 0 || $i < date("Y")) - $inscrits .= $i." ".$nb."\n"; -} - -//Genere le graphique à la volée avec GNUPLOT -header( "Content-type: image/png"); - -$ymin = 0; -$ymax = 100; - -$fin = $i+10; - -$gnuplot = << diff --git a/htdocs/stats/graph_evolution.php b/htdocs/stats/graph_evolution.php deleted file mode 100644 index 4ab9645..0000000 --- a/htdocs/stats/graph_evolution.php +++ /dev/null @@ -1,86 +0,0 @@ -xdb->iterRow( - "SELECT IF( date_ins>DATE_SUB(NOW(),INTERVAL $JOURS DAY), - TO_DAYS(date_ins)-TO_DAYS(NOW()), - ".(-($JOURS+1)).") AS jour, - COUNT(user_id) AS nb - FROM auth_user_md5 - WHERE perms IN ('admin','user') - GROUP BY jour"); - -//genere des donnees compatibles avec GNUPLOT -$inscrits=''; - -// la première ligne contient le total des inscrits avant la date de départ (J - $JOURS) -list(,$init_nb) = $res->next(); -$total = $init_nb; - -list($numjour, $nb) = $res->next(); - -for ($i=-$JOURS;$i<=0;$i++) { - if ($numjour<$i) { - if(!list($numjour, $nb) = $res->next()) { - $numjour = 0; - $nb = 0; - } - } - if ($numjour==$i) $total+=$nb; - $inscrits .= date('d/m/y',$i*DUREEJOUR+time())." ".$total."\n"; -} - -//Genere le graphique à la volée avec GNUPLOT -header( "Content-type: image/png"); - -$delt = ($total - $init_nb)/10; -$ymin = round($init_nb - $delt,0); -$ymax = round($total + $delt,0); - -$gnuplot = << diff --git a/htdocs/stats/graph_promo.php b/htdocs/stats/graph_promo.php deleted file mode 100644 index e953a2a..0000000 --- a/htdocs/stats/graph_promo.php +++ /dev/null @@ -1,90 +0,0 @@ -xdb->query("SELECT min(TO_DAYS(date_ins)-TO_DAYS(now())) FROM auth_user_md5 WHERE promo = {?} AND perms IN ('admin', 'user')", $promo); -$JOURS = -$res->fetchOneCell(); - -//recupere le nombre d'inscriptions par jour sur la plage concernée -$res = $globals->xdb->iterRow( - "SELECT IF( date_ins>DATE_SUB(NOW(),INTERVAL $JOURS DAY), - TO_DAYS(date_ins)-TO_DAYS(NOW()), - ".(-($JOURS+1)).") AS jour, - COUNT(user_id) AS nb - FROM auth_user_md5 - WHERE promo = {?} AND perms IN ('admin','user') - GROUP BY jour", $promo); - -//genere des donnees compatibles avec GNUPLOT -$inscrits=''; - -// la première ligne contient le total des inscrits avant la date de départ (J - $JOURS) -list(,$init_nb) = $res->next(); -$total = $init_nb; - -list($numjour, $nb) = $res->next(); - -for ($i=-$JOURS;$i<=0;$i++) { - if ($numjour<$i) { - if(!list($numjour, $nb) = $res->next()) { - $numjour = 0; - $nb = 0; - } - } - if ($numjour==$i) $total+=$nb; - $inscrits .= date('d/m/y',$i*DUREEJOUR+time())." ".$total."\n"; -} - -//Genere le graphique à la volée avec GNUPLOT -header( "Content-type: image/png"); - -$delt = ($total - $init_nb) / 10; -$delt += ($delt < 1); -$ymin = round($init_nb - $delt,0); -$ymax = round($total + $delt,0); - -$gnuplot = << diff --git a/htdocs/stats/index.php b/htdocs/stats/index.php deleted file mode 100644 index fd8d431..0000000 --- a/htdocs/stats/index.php +++ /dev/null @@ -1,25 +0,0 @@ -run(); -?> diff --git a/htdocs/stats/nb_by_promo.php b/htdocs/stats/nb_by_promo.php deleted file mode 100644 index 40d383b..0000000 --- a/htdocs/stats/nb_by_promo.php +++ /dev/null @@ -1,46 +0,0 @@ -xdb->iterRow( - "SELECT promo,COUNT(*) - FROM auth_user_md5 - WHERE promo > 1900 AND perms IN ('admin','user') - GROUP BY promo - ORDER BY promo"); -$max=0; $min=3000; - -while (list($promo,$nb) = $res->next()) { - $promo = intval($promo); - if(!isset($nbpromo[$promo/10])) { - $nbpromo[$promo/10] = Array('','','','','','','','','',''); // tableau de 10 cases vides - } - $nbpromo[$promo/10][$promo%10]=Array('promo' => $promo, 'nb' => $nb); -} - -$page->assign_by_ref('nbs', $nbpromo); -$page->assign('min', $min-$min % 10); -$page->assign('max', $max+10-$max%10); - -$page->run(); -?> diff --git a/htdocs/stats/stats_promo.php b/htdocs/stats/stats_promo.php deleted file mode 100644 index fb71b87..0000000 --- a/htdocs/stats/stats_promo.php +++ /dev/null @@ -1,29 +0,0 @@ -assign('promo',$promo); -$page->run(); - -?> diff --git a/install.d/stats.files b/install.d/stats.files deleted file mode 100644 index 514e038..0000000 --- a/install.d/stats.files +++ /dev/null @@ -1,10 +0,0 @@ -htdocs/admin/gerer_coupure.php -htdocs/stats/coupure.php -htdocs/stats/graph_promo.php -htdocs/stats/index.php -htdocs/stats/nb_by_promo.php -htdocs/stats/stats_promo.php -templates/stats/coupure.tpl -templates/stats/index.tpl -templates/stats/nb_by_promo.tpl -templates/stats/stats_promo.tpl diff --git a/modules/platal.php b/modules/platal.php index d6057b0..9faee9f 100644 --- a/modules/platal.php +++ b/modules/platal.php @@ -101,14 +101,14 @@ class PlatalModule extends PLModule if (Env::get('submit') == 'Valider' and Env::has('url')) { $globals->xdb->execute('UPDATE auth_user_quick SET redirecturl = {?} WHERE user_id = {?}', - $url, Session::getInt('uid'))) + $url, Session::getInt('uid')); $log->log('carva_add', 'http://'.Env::get('url')); $page->trig("Redirection activée vers $url"); } elseif (Env::get('submit') == "Supprimer") { $globals->xdb->execute("UPDATE auth_user_quick SET redirecturl = '' WHERE user_id = {?}", - Session::getInt('uid'))) + Session::getInt('uid')); $log->log("carva_del", $url); Post::kill('url'); $page->trig('Redirection supprimée'); diff --git a/modules/stats.php b/modules/stats.php new file mode 100644 index 0000000..fbfb2b4 --- /dev/null +++ b/modules/stats.php @@ -0,0 +1,310 @@ + 'site web', 'mail'=> 'redirection mail', + 'smtp' => 'serveur sécurisé d\'envoi de mails', + 'nntp' => 'serveur des forums de discussion'); + $ret = Array(); + foreach ($flags as $flag) { + $ret[] = $trad[$flag]; + } + return implode(', ',$ret); +} + +class StatsModule extends PLModule +{ + function handlers() + { + return array( + 'stats' => $this->make_hook('stats', AUTH_COOKIE), + 'stats/evolution' => $this->make_hook('evolution', AUTH_COOKIE), + 'stats/graph' => $this->make_hook('graph', AUTH_COOKIE), + 'stats/graph/evolution' + => $this->make_hook('graph_evo', AUTH_COOKIE), + 'stats/promos' => $this->make_hook('promos', AUTH_COOKIE), + + 'stats/coupures' => $this->make_hook('coupures', AUTH_PUBLIC), + ); + } + + function handler_stats(&$page) + { + $page->changeTpl('stats/index.tpl'); + return PL_OK; + } + + function handler_evolution(&$page, $jours = 365) + { + $page->changeTpl('stats/evolution_inscrits.tpl'); + $page->assign('jours', $jours); + return PL_OK; + } + + function handler_graph_evo(&$page, $jours = 365) + { + global $globals; + + define('DUREEJOUR',24*3600); + + //recupere le nombre d'inscriptions par jour sur la plage concernée + $res = $globals->xdb->iterRow( + "SELECT IF( date_ins>DATE_SUB(NOW(),INTERVAL $jours DAY), + TO_DAYS(date_ins)-TO_DAYS(NOW()), + ".(-($jours+1)).") AS jour, + COUNT(user_id) AS nb + FROM auth_user_md5 + WHERE perms IN ('admin','user') + GROUP BY jour"); + + //genere des donnees compatibles avec GNUPLOT + $inscrits=''; + + // la première ligne contient le total des inscrits avant la date de départ (J - $jours) + list(,$init_nb) = $res->next(); + $total = $init_nb; + + list($numjour, $nb) = $res->next(); + + for ($i = -$jours; $i<=0; $i++) { + if ($numjour<$i) { + if(!list($numjour, $nb) = $res->next()) { + $numjour = 0; + $nb = 0; + } + } + if ($numjour==$i) $total+=$nb; + $inscrits .= date('d/m/y',$i*DUREEJOUR+time())." ".$total."\n"; + } + + //Genere le graphique à la volée avec GNUPLOT + header( "Content-type: image/png"); + + $delt = ($total - $init_nb)/10; + $ymin = round($init_nb - $delt,0); + $ymax = round($total + $delt,0); + + $gnuplot = <<xdb->iterRow( + "SELECT promo, SUM(perms IN ('admin', 'user')) / COUNT(*) * 100 + FROM auth_user_md5 + WHERE promo >= $depart AND deces = 0 + GROUP BY promo"); + + //genere des donnees compatibles avec GNUPLOT + $inscrits=''; + + // la première ligne contient le total des inscrits avant la date de départ + 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 > 0 || $i < date('Y')) + $inscrits .= $i.' '.$nb."\n"; + } + + //Genere le graphique à la volée avec GNUPLOT + $fin = $i+2; + + $gnuplot = <<xdb->query("SELECT min(TO_DAYS(date_ins)-TO_DAYS(now())) + FROM auth_user_md5 + WHERE promo = {?} + AND perms IN ('admin', 'user')", + $promo); + $jours = -$res->fetchOneCell(); + + //recupere le nombre d'inscriptions par jour sur la plage concernée + $res = $globals->xdb->iterRow( + "SELECT IF( date_ins>DATE_SUB(NOW(),INTERVAL $jours DAY), + TO_DAYS(date_ins)-TO_DAYS(NOW()), + ".(-($jours+1)).") AS jour, + COUNT(user_id) AS nb + FROM auth_user_md5 + WHERE promo = {?} AND perms IN ('admin','user') + GROUP BY jour", $promo); + + //genere des donnees compatibles avec GNUPLOT + $inscrits=''; + + // la première ligne contient le total des inscrits avant la date de départ (J - $jours) + list(,$init_nb) = $res->next(); + $total = $init_nb; + + list($numjour, $nb) = $res->next(); + + for ($i = -$jours;$i<=0;$i++) { + if ($numjour<$i) { + if(!list($numjour, $nb) = $res->next()) { + $numjour = 0; + $nb = 0; + } + } + if ($numjour==$i) $total+=$nb; + $inscrits .= date('d/m/y',$i*DUREEJOUR+time())." ".$total."\n"; + } + + //Genere le graphique à la volée avec GNUPLOT + $delt = ($total - $init_nb) / 10; + $delt += ($delt < 1); + $ymin = round($init_nb - $delt,0); + $ymax = round($total + $delt,0); + + $gnuplot = <<changeTpl('stats/nb_by_promo.tpl'); + + $res = $globals->xdb->iterRow( + "SELECT promo,COUNT(*) + FROM auth_user_md5 + WHERE promo > 1900 AND perms IN ('admin','user') + GROUP BY promo + ORDER BY promo"); + $max=0; $min=3000; + + while (list($p,$nb) = $res->next()) { + $p = intval($p); + if(!isset($nbpromo[$p/10])) { + $nbpromo[$p/10] = Array('','','','','','','','','',''); // tableau de 10 cases vides + } + $nbpromo[$p/10][$p%10]=Array('promo' => $p, 'nb' => $nb); + } + + $page->assign_by_ref('nbs', $nbpromo); + $page->assign('min', $min-$min % 10); + $page->assign('max', $max+10-$max%10); + $page->assign('promo', $promo); + + return PL_OK; + } + + function handler_coupures(&$page, $cp_id = null) + { + global $globals; + + $page->changeTpl('stats/coupure.tpl'); + + if (!is_null($cp_id)) { + $res = $globals->xdb->query("SELECT UNIX_TIMESTAMP(debut) AS debut, + TIME_FORMAT(duree,'%kh%i') AS duree, + resume, description, services + FROM coupures + WHERE id = {?}", $cp_id); + $cp = $res->fetchOneAssoc(); + } + + if($cp) { + $cp['lg_services'] = serv_to_str($cp['services']); + $page->assign_by_ref('cp',$cp); + } else { + $beginning_date = date("Ymd", time() - 3600*24*21) . "000000"; + $sql = "SELECT id, UNIX_TIMESTAMP(debut) AS debut, resume, services + FROM coupures where debut > '$beginning_date' order by debut desc"; + $page->assign('coupures', $globals->xdb->iterator($sql)); + } + + return PL_OK; + } +} + +?> diff --git a/templates/skin/common.footer.tpl b/templates/skin/common.footer.tpl index 97315b0..b58942c 100644 --- a/templates/skin/common.footer.tpl +++ b/templates/skin/common.footer.tpl @@ -31,8 +31,8 @@ Services et Ethique | Charte {min_auth level=cookie} - | Disponibilité - | Statistiques + | Disponibilité + | Statistiques {/min_auth} diff --git a/templates/stats/coupure.tpl b/templates/stats/coupure.tpl index 73da9f7..9cdf7d4 100644 --- a/templates/stats/coupure.tpl +++ b/templates/stats/coupure.tpl @@ -20,7 +20,6 @@ {* *} {**************************************************************************} - {if $cp} @@ -51,7 +50,7 @@

-retour à la liste +retour à la liste

{else} @@ -82,7 +81,7 @@ - {$cp.resume} + {$cp.resume} diff --git a/templates/stats/evolution_inscrits.tpl b/templates/stats/evolution_inscrits.tpl index 0c9cbff..9f300b8 100644 --- a/templates/stats/evolution_inscrits.tpl +++ b/templates/stats/evolution_inscrits.tpl @@ -20,35 +20,32 @@ {* *} {**************************************************************************} - -

- Evolution du nombre d'inscrits au site polytechnique.org -

+

Evolution du nombre d'inscrits au site polytechnique.org

-{if $smarty.request.jours eq 1826} +{if $jours eq 1825} [depuis 5 ans] {else} -[depuis 5 ans] +[depuis 5 ans] {/if} -{if $smarty.request.jours eq 731} +{if $jours eq 730} [depuis 2 ans] {else} -[depuis 2 ans] +[depuis 2 ans] {/if} -{if (!$smarty.request.jours) or ($smarty.request.jours eq 364)} +{if $jours eq 365} [depuis un an] {else} -[depuis un an] +[depuis un an] {/if} -{if $smarty.request.jours eq 30} +{if $jours eq 30} [depuis un mois] {else} -[depuis 1 mois] +[depuis 1 mois] {/if}
-  [ INSCRITS ] +  [ INSCRITS ]
{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/templates/stats/index.tpl b/templates/stats/index.tpl index ea24271..cf2de05 100644 --- a/templates/stats/index.tpl +++ b/templates/stats/index.tpl @@ -30,9 +30,9 @@ Quelques statistiques sur l'utilisation des services de Polytechnique.org ainsi

{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/templates/stats/nb_by_promo.tpl b/templates/stats/nb_by_promo.tpl index e95e816..8319e4e 100644 --- a/templates/stats/nb_by_promo.tpl +++ b/templates/stats/nb_by_promo.tpl @@ -20,10 +20,7 @@ {* *} {**************************************************************************} - -

- Inscrits par promo -

+

Inscrits par promo

Voici le nombre d'inscrits par promo : @@ -40,10 +37,10 @@ Voici le nombre d'inscrits par promo : {$lustre}- {foreach item=nb from=$nb10} - {if $nb && $nb.promo eq $smarty.request.promo} + {if $nb && $nb.promo eq $promo} {$nb.nb} {elseif $nb} - {$nb.nb} + {$nb.nb} {else} - {/if} @@ -53,16 +50,16 @@ Voici le nombre d'inscrits par promo : {/foreach} -{if $smarty.request.promo} +{if $promo}

-[répartition des inscrits par promo] +[répartition des inscrits par promo]

-

Courbe d'inscription de la promo {$smarty.request.promo}

+

Courbe d'inscription de la promo {$promo}

-  [ INSCRITS ] +  [ INSCRITS ]
{else} @@ -70,7 +67,7 @@ Voici le nombre d'inscrits par promo :

Inscrits par promo en (%)

- [graphe du nombre d'inscrits par promo] + [graphe du nombre d'inscrits par promo]
{/if}