diff --git a/CHANGELOG b/CHANGELOG index 651b2f4..d28cb6f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -631,7 +631,8 @@ Ne pas autoriser la commande via url si le bouton order est désactivé dans la ======= CHANGES ======= ------- -25/11/2021 v5.3.9-3.7.9 +25/11/2021 v5.3.10-3.7.9 + - (i) refactorisation des statistiques sur les matériels + ajout tests - (b) Bugfix page statistique sur les matériels (conditions limites, division par zéro quand année précédente nulle) ------- diff --git a/README.md b/README.md index 30a8bc2..0fde91d 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Logiciel testé et validé sur les configurations suivantes : -------------------------------------------------------------------------------------------- Date: 25/11/2021 -Version: v5.3.9-3.7.9 +Version: v5.3.10-3.7.9 HISTORIQUE DES CHANGEMENTS DE VERSION : voir le fichier CHANGES.txt (ou la page web /pages/changes) diff --git a/src/Controller/PagesController.php b/src/Controller/PagesController.php index d4038d7..8547889 100755 --- a/src/Controller/PagesController.php +++ b/src/Controller/PagesController.php @@ -335,6 +335,10 @@ class PagesController extends AppController private function page_stats_set_variables() { + // créer des FAKE DATA pour tester la fonctionnalité ? + $TEST = true; + $TEST = false; + // Nb années demandées par l'utilisateur $nbyears = $this->request->getQuery('nbyears'); @@ -396,8 +400,7 @@ class PagesController extends AppController // - Année min //$year_min = $materiels->find()->min(['year(date_acquisition)']); //$matos_year_min = $materiels->find()->where(['year(date_acquisition) >' => 0]) - $matos_year_min = $all_matos->cleanCopy() - ->min(function($matos) { + $matos_year_min = $all_matos->cleanCopy()->min(function($matos) { return $matos->date_acquisition->format('Y'); }); $year_min = (int) $matos_year_min->date_acquisition->format('Y'); @@ -618,6 +621,96 @@ class PagesController extends AppController // Set all variables pour la vue //$this->set(compact('current_year', 'year_min', 'tot', 'avg', 'years', 'suivis', 'prets')); //$this->set(compact('current_year', 'year_min', 'nbyears', 'tot', 'tot2', 'avg', 'years')); + + // FAKE DATA POUR TEST LOCAL + if ($TEST) { + + $current_year = 2021; + + $test_nb_years = 0; + $test_nb_years = 1; + $test_nb_years = 2; + $test_nb_years = 3; + + $i_year = $current_year; + $i_nbyears = 0; + + $years = []; + /* + $years[2019] = [ + 'CREATED' => (int) 27, + 'VALIDATED' => (int) 8, + 'TOBEARCHIVED' => (int) 1, + 'ARCHIVED' => (int) 1, + 'suivis' => (int) 2, + 'prets' => (int) 2 + ]; + */ + // 1 year + if ($test_nb_years > $i_nbyears) + $years[$i_year] = [ + 'CREATED' => (int) 27, + 'VALIDATED' => (int) 8, + 'TOBEARCHIVED' => (int) 1, + 'ARCHIVED' => (int) 1, + 'suivis' => (int) 2, + 'prets' => (int) 2 + ]; + // 2 years + if ($test_nb_years > $i_nbyears++) + $years[--$i_year] = [ + 'CREATED' => (int) 0, + 'VALIDATED' => (int) 0, + 'TOBEARCHIVED' => (int) 0, + 'ARCHIVED' => (int) 0, + 'suivis' => (int) 0, + 'prets' => (int) 0 + ]; + // 3 years + if ($test_nb_years > $i_nbyears++) + $years[--$i_year] = [ + 'CREATED' => (int) 27, + 'VALIDATED' => (int) 8, + 'TOBEARCHIVED' => (int) 1, + 'ARCHIVED' => (int) 1, + 'suivis' => (int) 2, + 'prets' => (int) 2 + ]; + if ($test_nb_years > $i_nbyears++) + $years[--$i_year] = [ + 'CREATED' => (int) 27, + 'VALIDATED' => (int) 8, + 'TOBEARCHIVED' => (int) 1, + 'ARCHIVED' => (int) 1, + 'suivis' => (int) 2, + 'prets' => (int) 2 + ]; + + $nbyears = count($years); + $year_min = $nbyears>0 ? min(array_keys($years)) : $current_year; + + $tot = [ + 'CREATED' => (int) 27, + 'VALIDATED' => (int) 8, + 'TOBEARCHIVED' => (int) 1, + 'ARCHIVED' => (int) 1, + 'suivis' => (int) 2, + 'prets' => (int) 2 + ]; + $avg = [ + 'CREATED' => (float) 27, + 'VALIDATED' => (float) 8, + 'TOBEARCHIVED' => (float) 1, + 'ARCHIVED' => (float) 1, + 'suivis' => (float) 2, + 'prets' => (float) 2 + ]; + + debug($current_year); + debug($year_min); + debug($years); + } // TEST DATA + $this->set(compact('current_year', 'year_min', 'nbyears', 'tot', 'avg', 'years')); /* debug($tot); diff --git a/src/Template/Pages/stats.ctp b/src/Template/Pages/stats.ctp index a86d243..8c775b9 100644 --- a/src/Template/Pages/stats.ctp +++ b/src/Template/Pages/stats.ctp @@ -40,7 +40,10 @@ $avg = $avg; $tot = $tot; //$tot2 = $tot2; $years = $years; -//debug($suivis); +//debug($years); +//debug($tot); + + @@ -54,8 +57,7 @@ function echoAsPctAndBold($nbelem, $total=null, $is_bold=false) { $nbelem = "$pct% ($nbelem)"; //$nbelem = "$nbelem ($pct%)"; //$nbelem = "$pct%"; - } - echo $nbelem; + } echo $nbelem; if ($is_bold) echo ''; } @@ -78,6 +80,9 @@ function displayEmptyLine() { // 100 * (current - prev) / prev function computeEvolutionFromPrevToCurrent($prev,$current) { + // On ne fait pas le calcul si l'un des 2 paramètres est nul (ou n'existe pas), car inutile de comparer qqch à un nul (ou inexistant) + //if ($year_curr_tot==0 || $year_prev_tot==0) return '/'; + if ($prev<=0 || $current<=0) return '/'; $evol_from_year_prev = round ( 100 * ($current-$prev) / $prev ); if ($evol_from_year_prev >= 0) $evol_from_year_prev = '+'.$evol_from_year_prev; return $evol_from_year_prev.'%'; @@ -98,7 +103,8 @@ function displayStatsLine($title, $line, $is_bold=false, $year_prev_tot=-1, $avg 0 ? computeEvolutionFromPrevToCurrent($year_prev_tot, $year_curr_tot) : '/'; + $evol_from_year_prev = computeEvolutionFromPrevToCurrent($year_prev_tot, $year_curr_tot); + //$evol_from_year_prev = ($year_curr_tot>0 && $year_prev_tot>0) ? computeEvolutionFromPrevToCurrent($year_prev_tot, $year_curr_tot) : '/'; /* inutile, on fait pas des maths ici // - Si prev = 0 => éviter division par zéro, résultat = +/- INFINI if ($year_prev_tot==0) { @@ -117,7 +123,7 @@ function displayStatsLine($title, $line, $is_bold=false, $year_prev_tot=-1, $avg 0 ? computeEvolutionFromPrevToCurrent($avg, $year_curr_tot) : '/'; + $evol_from_avg = computeEvolutionFromPrevToCurrent($avg, $year_curr_tot); /* if ($avg) { $evol_from_avg = round (($year_curr_tot-$avg['CREATED'])/$avg['CREATED'] * 100); @@ -298,6 +304,7 @@ echo $this->Form->end(); displayStatsLine($year_title, $val); } */ + if ($nbyears>0) for ($y=$current_year ; $y>=$year_min ; $y--) { $val = $years[$y]; $year_title = $y; -- libgit2 0.21.2