Browse Source
on utilise une boucle (DATA){source stats,jour|mois,duree,id_article} pour recuperer le tableau de donnees qu'on met en forme dans le squelette la page offre deja le zom on/off en ajaxsvn/root/tags/plugins/statistiques/0.3.0

7 changed files with 293 additions and 76 deletions
@ -0,0 +1,97 @@
|
||||
<?php |
||||
|
||||
/***************************************************************************\ |
||||
* SPIP, Systeme de publication pour l'internet * |
||||
* * |
||||
* Copyright (c) 2001-2011 * |
||||
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
||||
* * |
||||
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
||||
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
||||
\***************************************************************************/ |
||||
|
||||
|
||||
if (!defined('_ECRIRE_INC_VERSION')) return; |
||||
|
||||
include_spip('inc/statistiques'); |
||||
// moyenne glissante sur 30 jours |
||||
define('MOYENNE_GLISSANTE_JOUR', 30); |
||||
// moyenne glissante sur 12 mois |
||||
define('MOYENNE_GLISSANTE_MOIS', 12); |
||||
|
||||
function inc_stats_to_array_dist($unite, $duree, $id_article, $options = array()) { |
||||
$args = func_get_args(); |
||||
$now = time(); |
||||
|
||||
if (!in_array($unite,array('jour','mois'))) |
||||
$unite = 'jour'; |
||||
$serveur = ''; |
||||
|
||||
$table = "spip_visites"; |
||||
$order = "date"; |
||||
$where = array(); |
||||
if ($duree) |
||||
$where[] = sql_date_proche($order,-$duree,'day',$serveur); |
||||
|
||||
if ($id_article) { |
||||
$table = "spip_visites_articles"; |
||||
$where[] = "id_article=".intval($id_article); |
||||
} |
||||
|
||||
$where = implode(" AND ",$where); |
||||
$format = ($unite=='jour'?'%Y-%m-%d':'%Y-%m-01'); |
||||
|
||||
$res = sql_select("SUM(visites) AS v, DATE_FORMAT($order,'$format') AS d", $table, $where, "d", "d", "",'',$serveur); |
||||
|
||||
$format = str_replace('%','',$format); |
||||
$periode = ($unite=='jour'?24*3600:365*24*3600/12); |
||||
$step = intval(round($periode*1.1,0)); |
||||
$glisse = constant('MOYENNE_GLISSANTE_'.strtoupper($unite)); |
||||
moyenne_glissante(); |
||||
$data = array(); |
||||
$r = sql_fetch($res,$serveur); |
||||
do { |
||||
$data[$r['d']] = array('visites'=>$r['v'],'moyenne'=>moyenne_glissante($r['v'], $glisse)); |
||||
$last = $r['d']; |
||||
|
||||
// donnee suivante |
||||
$r = sql_fetch($res,$serveur); |
||||
// si la derniere n'est pas la date courante, l'ajouter |
||||
if (!$r AND $last!=date($format,$now)) |
||||
$r = array('d'=>date($format,$now),'v'=>0); |
||||
|
||||
// completer les trous manquants si besoin |
||||
if ($r){ |
||||
$next = strtotime($last); |
||||
$current = strtotime($r['d']); |
||||
while (($next+=$step)<$current AND $d=date($format,$next)){ |
||||
if (!isset($data[$d])) |
||||
$data[$d] = array('visites'=>0,'moyenne'=>moyenne_glissante(0, $glisse)); |
||||
$last = $d; |
||||
$next = strtotime($last); |
||||
} |
||||
} |
||||
} |
||||
while ($r); |
||||
|
||||
// projection pour la derniere barre : |
||||
// mesure courante |
||||
// + moyenne au pro rata du temps qui reste |
||||
$moyenne = end($data); |
||||
$moyenne = prev($data); |
||||
$moyenne = ($moyenne AND isset($moyenne['moyenne']))?$moyenne['moyenne']:0; |
||||
$data[$last]['moyenne'] = $moyenne; |
||||
|
||||
// temps restant |
||||
$remaining = strtotime(date($format,strtotime(date($format,$now))+$step))-$now; |
||||
|
||||
$prorata = $remaining/$periode; |
||||
|
||||
// projection |
||||
$data[$last]['prevision'] = $data[$last]['visites'] + intval(round($moyenne*$prorata)); |
||||
|
||||
return $data; |
||||
} |
||||
|
||||
|
||||
?> |
@ -0,0 +1,4 @@
|
||||
#BOITE_OUVRIR{#CHEMIN_IMAGE{statistique-24.png}|balise_img{'',cadre-icone},'simple stats'} |
||||
<INCLURE{fond=prive/squelettes/inclure/stats-visites-data,ajax,env} /> |
||||
#BOITE_FERMER |
||||
<INCLURE{fond=prive/stats/visites} /> |
@ -0,0 +1,49 @@
|
||||
<p class="pagination"> |
||||
<a href="[(#SELF|parametre_url{duree,#ENV{duree,90}|duree_zoom{moins}})]" |
||||
class="ajax">[(#CHEMIN_IMAGE{loupe-moins.gif}|balise_img{<:info_zoom:> -})]</a> |
||||
<a href="[(#SELF|parametre_url{duree,#ENV{duree,90}|duree_zoom{plus}})]" |
||||
class="ajax">[(#CHEMIN_IMAGE{loupe-plus.gif}|balise_img{<:info_zoom:> +})]</a> |
||||
</p> |
||||
<B_statsj> |
||||
<table class='visites' id='visites_quotidiennes'> |
||||
<caption><:visites_journalieres:></caption> |
||||
<thead> |
||||
<tr class='row_first'> |
||||
<th><:date|trim{':'}|trim:></th> |
||||
<th class='valeur'><:info_visites|trim{':'}|trim:></th> |
||||
<th class='moyenne'><:info_moyenne|trim{':'}|trim:></th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<BOUCLE_statsj(DATA){source stats,jour,#ENV{duree,90},#ENV{id_article}}> |
||||
<tr class="c_[(#CLE|affdate{l}|substr{0,3})][(#COMPTEUR_BOUCLE|=={#TOTAL_BOUCLE}|oui)c_today]"> |
||||
<th title="[(#CLE|affdate{'Y-m-d'})]">[(#COMPTEUR_BOUCLE|=={#TOTAL_BOUCLE}|?{<:info_aujourdhui:>,#CLE|affdate_jourcourt})]</th> |
||||
<td class="val">#VALEUR{visites}[<em>(<span>(#VALEUR{prevision})</span>)</em>]</td> |
||||
<td class="mean">#VALEUR{moyenne}</td> |
||||
</tr> |
||||
</BOUCLE_statsj> |
||||
</tbody> |
||||
</table> |
||||
</B_statsj> |
||||
|
||||
<B_statsm> |
||||
<table class='visites' id='visites_mensuelles'> |
||||
<caption><:visites_mensuelles:></caption> |
||||
<thead> |
||||
<tr class='row_first'> |
||||
<th><:date|trim{':'}|trim:></th> |
||||
<th class='valeur'><:info_visites|trim{':'}|trim:></th> |
||||
<th class='moyenne'><:info_moyenne|trim{':'}|trim:></th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<BOUCLE_statsm(DATA){source stats,mois,#ENV{duree,90},#ENV{id_article}}> |
||||
<tr class="c_[(#CLE|affdate{l}|substr{0,3})][(#COMPTEUR_BOUCLE|=={#TOTAL_BOUCLE}|oui)c_today]"> |
||||
<th title="[(#CLE|affdate{'Y-m-01'})]">[(#CLE|affdate_mois_annee)]</th> |
||||
<td class="val">#VALEUR{visites}[<em>(<span>(#VALEUR{prevision})</span>)</em>]</td> |
||||
<td class="mean">[(#VALEUR{moyenne}|round)]</td> |
||||
</tr> |
||||
</BOUCLE_statsm> |
||||
</tbody> |
||||
</table> |
||||
</B_statsm> |
@ -0,0 +1,23 @@
|
||||
<?php |
||||
|
||||
|
||||
function duree_zoom($duree,$sens='plus'){ |
||||
$largeur_abs = 420/$duree; |
||||
|
||||
if ($largeur_abs > 1) { |
||||
$inc = ceil($largeur_abs / 5); |
||||
$duree_plus = round(420 / ($largeur_abs - $inc)); |
||||
$duree_moins = round(420 / ($largeur_abs + $inc)); |
||||
} |
||||
|
||||
if ($largeur_abs == 1) { |
||||
$duree_plus = 840; |
||||
$duree_moins = 210; |
||||
} |
||||
|
||||
if ($largeur_abs < 1) { |
||||
$duree_plus = round(420 * ((1/$largeur_abs) + 1)); |
||||
$duree_moins = round(420 * ((1/$largeur_abs) - 1)); |
||||
} |
||||
return ($sens=='plus'?$duree_moins:$duree_plus); |
||||
} |
Loading…
Reference in new issue