From f0144b75ae0b3cdde4d9886591a4a70bf4b93ac2 Mon Sep 17 00:00:00 2001 From: "cedric@yterium.com" <> Date: Wed, 16 Mar 2011 23:37:25 +0000 Subject: [PATCH] debut de reecriture de l'affichage des stats en squelette : 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 ajax --- .gitattributes | 4 + inc/statistiques.php | 58 ++++++-- inc/stats_to_array.php | 97 +++++++++++++ prive/squelettes/contenu/stats_visites.html | 4 + .../inclure/stats-visites-data.html | 49 +++++++ .../inclure/stats-visites-data_fonctions.php | 23 +++ prive/stats/visites.html | 134 +++++++++--------- 7 files changed, 293 insertions(+), 76 deletions(-) create mode 100644 inc/stats_to_array.php create mode 100644 prive/squelettes/contenu/stats_visites.html create mode 100644 prive/squelettes/inclure/stats-visites-data.html create mode 100644 prive/squelettes/inclure/stats-visites-data_fonctions.php diff --git a/.gitattributes b/.gitattributes index 545a08f..2d37a15 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14,13 +14,17 @@ genie/popularites.php -text genie/visites.php -text inc/referenceurs.php -text inc/statistiques.php -text +inc/stats_to_array.php -text javascript/excanvas.js -text javascript/jquery.flot.js -text javascript/jquery.tflot.js -text /plugin.xml -text prive/bouton/statistiques.html -text prive/images/statistiques-48.png -text +prive/squelettes/contenu/stats_visites.html -text prive/squelettes/inclure/admin_effacer_stats.html -text +prive/squelettes/inclure/stats-visites-data.html -text +prive/squelettes/inclure/stats-visites-data_fonctions.php -text prive/stats/visites.html -text prive/style_prive_plugin_stats.html -text prive/themes/spip/images/statistique-16.png -text diff --git a/inc/statistiques.php b/inc/statistiques.php index 56beb7d..d61d752 100644 --- a/inc/statistiques.php +++ b/inc/statistiques.php @@ -119,9 +119,19 @@ function cadre_stat($stats, $table, $id_article) . statistiques_mode($table, $id_article); } -// http://doc.spip.org/@statistiques_collecte_date -function statistiques_collecte_date($count, $date, $table, $where, $serveur) -{ + +/** + * + * // http://doc.spip.org/@statistiques_collecte_date + * + * @param string $count + * @param string $date + * @param string $table + * @param string $where + * @param string $serveur + * @return array + */ +function statistiques_collecte_date($count, $date, $table, $where, $serveur){ $result = sql_select("$count AS n, $date AS d", $table, $where, 'd', 'd', '','', $serveur); $log = array(); @@ -140,7 +150,7 @@ function statistiques_tous($log, $id_article, $table, $where, $order, $serveur, $max = max($log); list($moyenne,$prec, $res) = stat_log1($log, $date_fin, $interval, $script); - $res_mois = statistiques_mensuelles($order, $table, $where, $serveur, $script); + $res_mois = statistiques_mensuelles($order, $table, $where, $serveur); $stats = "" . "" @@ -387,7 +397,7 @@ function statistiques_jour($key, $value, $moyenne, $script) return $res; } -function statistiques_mois($key, $value, $moyenne, $script) { +function statistiques_mois($key, $value, $moyenne) { $key = substr($key,0,4).'-'.substr($key,4,2); $res = "" . "" @@ -399,22 +409,50 @@ function statistiques_mois($key, $value, $moyenne, $script) { } // http://doc.spip.org/@statistiques_mensuelles -function statistiques_mensuelles($order, $table, $where, $serveur, $script) { +function statistiques_mensuelles($order, $table, $where, $serveur) { $result = sql_select("SUM(visites) AS v, DATE_FORMAT($order,'%Y%m') AS d", "$table", "$where", "d", "d", "",'',$serveur); $res_mois = ''; while ($r = sql_fetch($result,$serveur)) { moyenne_glissante_mois($r['v']); - $res_mois .= statistiques_mois($r['d'], $r['v'], moyenne_glissante_mois() , $script); + $res_mois .= statistiques_mois($r['d'], $r['v'], moyenne_glissante_mois()); } return $res_mois; } +/** + * Calculer la moyenne glissante sur un nombre d'echantillons donnes + * @param int|bool $valeur + * @param int $glisse + * @return float + */ +function moyenne_glissante($valeur = false, $glisse=0) { + static $v = array(); + // pas d'argument, raz de la moyenne + if ($valeur === false) { + $v = array(); + return 0; + } -// http://doc.spip.org/@statistiques_moyenne -function statistiques_moyenne($tab) -{ + // argument, on l'ajoute au tableau... + // surplus, on enleve... + $v[] = $valeur; + if (count($v) > $glisse) + array_shift($v); + + return round(statistiques_moyenne($v),2); +} + +/** + * Calculer la moyenne d'un tableau de valeurs + * + * http://doc.spip.org/@statistiques_moyenne + * + * @param array $tab + * @return float + */ +function statistiques_moyenne($tab){ if (!$tab) return 0; $moyenne = 0; foreach($tab as $v) $moyenne += $v; diff --git a/inc/stats_to_array.php b/inc/stats_to_array.php new file mode 100644 index 0000000..ba94970 --- /dev/null +++ b/inc/stats_to_array.php @@ -0,0 +1,97 @@ +$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; +} + + +?> \ No newline at end of file diff --git a/prive/squelettes/contenu/stats_visites.html b/prive/squelettes/contenu/stats_visites.html new file mode 100644 index 0000000..63b7acf --- /dev/null +++ b/prive/squelettes/contenu/stats_visites.html @@ -0,0 +1,4 @@ +#BOITE_OUVRIR{#CHEMIN_IMAGE{statistique-24.png}|balise_img{'',cadre-icone},'simple stats'} + +#BOITE_FERMER + \ No newline at end of file diff --git a/prive/squelettes/inclure/stats-visites-data.html b/prive/squelettes/inclure/stats-visites-data.html new file mode 100644 index 0000000..31fb311 --- /dev/null +++ b/prive/squelettes/inclure/stats-visites-data.html @@ -0,0 +1,49 @@ +

+ [(#CHEMIN_IMAGE{loupe-moins.gif}|balise_img{<:info_zoom:> -})] + [(#CHEMIN_IMAGE{loupe-plus.gif}|balise_img{<:info_zoom:> +})] +

+ +
"._T('visites_journalieres')."
" . affdate_mois_annee($key) . "
+ + + + + + + + + + + + + + + + + +
<:visites_journalieres:>
<:date|trim{':'}|trim:><:info_visites|trim{':'}|trim:><:info_moyenne|trim{':'}|trim:>
[(#COMPTEUR_BOUCLE|=={#TOTAL_BOUCLE}|?{<:info_aujourdhui:>,#CLE|affdate_jourcourt})]#VALEUR{visites}[((#VALEUR{prevision}))]#VALEUR{moyenne}
+ + + + + + + + + + + + + + + + + + + + + +
<:visites_mensuelles:>
<:date|trim{':'}|trim:><:info_visites|trim{':'}|trim:><:info_moyenne|trim{':'}|trim:>
[(#CLE|affdate_mois_annee)]#VALEUR{visites}[((#VALEUR{prevision}))][(#VALEUR{moyenne}|round)]
+
\ No newline at end of file diff --git a/prive/squelettes/inclure/stats-visites-data_fonctions.php b/prive/squelettes/inclure/stats-visites-data_fonctions.php new file mode 100644 index 0000000..75f9a25 --- /dev/null +++ b/prive/squelettes/inclure/stats-visites-data_fonctions.php @@ -0,0 +1,23 @@ + 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); +} \ No newline at end of file diff --git a/prive/stats/visites.html b/prive/stats/visites.html index 40ea41c..815fcb1 100644 --- a/prive/stats/visites.html +++ b/prive/stats/visites.html @@ -3,76 +3,78 @@ []