Commit 3cc2a789ae2947b5552d8cec3a3b882e184429d8
1 parent
5f149ade
Exists in
master
and in
1 other branch
Refactorisation des statistiques sur les matériels
v5.3.10-3.7.9
Showing
4 changed files
with
110 additions
and
9 deletions
Show diff stats
CHANGELOG
... | ... | @@ -631,7 +631,8 @@ Ne pas autoriser la commande via url si le bouton order est désactivé dans la |
631 | 631 | ======= CHANGES ======= |
632 | 632 | |
633 | 633 | ------- |
634 | -25/11/2021 v5.3.9-3.7.9 | |
634 | +25/11/2021 v5.3.10-3.7.9 | |
635 | + - (i) refactorisation des statistiques sur les matériels + ajout tests | |
635 | 636 | - (b) Bugfix page statistique sur les matériels (conditions limites, division par zéro quand année précédente nulle) |
636 | 637 | |
637 | 638 | ------- | ... | ... |
README.md
... | ... | @@ -53,7 +53,7 @@ Logiciel testé et validé sur les configurations suivantes : |
53 | 53 | -------------------------------------------------------------------------------------------- |
54 | 54 | |
55 | 55 | Date: 25/11/2021 |
56 | -Version: v5.3.9-3.7.9 | |
56 | +Version: v5.3.10-3.7.9 | |
57 | 57 | |
58 | 58 | |
59 | 59 | HISTORIQUE DES CHANGEMENTS DE VERSION : voir le fichier CHANGES.txt (ou la page web /pages/changes) | ... | ... |
src/Controller/PagesController.php
... | ... | @@ -335,6 +335,10 @@ class PagesController extends AppController |
335 | 335 | |
336 | 336 | private function page_stats_set_variables() { |
337 | 337 | |
338 | + // créer des FAKE DATA pour tester la fonctionnalité ? | |
339 | + $TEST = true; | |
340 | + $TEST = false; | |
341 | + | |
338 | 342 | // Nb années demandées par l'utilisateur |
339 | 343 | $nbyears = $this->request->getQuery('nbyears'); |
340 | 344 | |
... | ... | @@ -396,8 +400,7 @@ class PagesController extends AppController |
396 | 400 | // - Année min |
397 | 401 | //$year_min = $materiels->find()->min(['year(date_acquisition)']); |
398 | 402 | //$matos_year_min = $materiels->find()->where(['year(date_acquisition) >' => 0]) |
399 | - $matos_year_min = $all_matos->cleanCopy() | |
400 | - ->min(function($matos) { | |
403 | + $matos_year_min = $all_matos->cleanCopy()->min(function($matos) { | |
401 | 404 | return $matos->date_acquisition->format('Y'); |
402 | 405 | }); |
403 | 406 | $year_min = (int) $matos_year_min->date_acquisition->format('Y'); |
... | ... | @@ -618,6 +621,96 @@ class PagesController extends AppController |
618 | 621 | // Set all variables pour la vue |
619 | 622 | //$this->set(compact('current_year', 'year_min', 'tot', 'avg', 'years', 'suivis', 'prets')); |
620 | 623 | //$this->set(compact('current_year', 'year_min', 'nbyears', 'tot', 'tot2', 'avg', 'years')); |
624 | + | |
625 | + // FAKE DATA POUR TEST LOCAL | |
626 | + if ($TEST) { | |
627 | + | |
628 | + $current_year = 2021; | |
629 | + | |
630 | + $test_nb_years = 0; | |
631 | + $test_nb_years = 1; | |
632 | + $test_nb_years = 2; | |
633 | + $test_nb_years = 3; | |
634 | + | |
635 | + $i_year = $current_year; | |
636 | + $i_nbyears = 0; | |
637 | + | |
638 | + $years = []; | |
639 | + /* | |
640 | + $years[2019] = [ | |
641 | + 'CREATED' => (int) 27, | |
642 | + 'VALIDATED' => (int) 8, | |
643 | + 'TOBEARCHIVED' => (int) 1, | |
644 | + 'ARCHIVED' => (int) 1, | |
645 | + 'suivis' => (int) 2, | |
646 | + 'prets' => (int) 2 | |
647 | + ]; | |
648 | + */ | |
649 | + // 1 year | |
650 | + if ($test_nb_years > $i_nbyears) | |
651 | + $years[$i_year] = [ | |
652 | + 'CREATED' => (int) 27, | |
653 | + 'VALIDATED' => (int) 8, | |
654 | + 'TOBEARCHIVED' => (int) 1, | |
655 | + 'ARCHIVED' => (int) 1, | |
656 | + 'suivis' => (int) 2, | |
657 | + 'prets' => (int) 2 | |
658 | + ]; | |
659 | + // 2 years | |
660 | + if ($test_nb_years > $i_nbyears++) | |
661 | + $years[--$i_year] = [ | |
662 | + 'CREATED' => (int) 0, | |
663 | + 'VALIDATED' => (int) 0, | |
664 | + 'TOBEARCHIVED' => (int) 0, | |
665 | + 'ARCHIVED' => (int) 0, | |
666 | + 'suivis' => (int) 0, | |
667 | + 'prets' => (int) 0 | |
668 | + ]; | |
669 | + // 3 years | |
670 | + if ($test_nb_years > $i_nbyears++) | |
671 | + $years[--$i_year] = [ | |
672 | + 'CREATED' => (int) 27, | |
673 | + 'VALIDATED' => (int) 8, | |
674 | + 'TOBEARCHIVED' => (int) 1, | |
675 | + 'ARCHIVED' => (int) 1, | |
676 | + 'suivis' => (int) 2, | |
677 | + 'prets' => (int) 2 | |
678 | + ]; | |
679 | + if ($test_nb_years > $i_nbyears++) | |
680 | + $years[--$i_year] = [ | |
681 | + 'CREATED' => (int) 27, | |
682 | + 'VALIDATED' => (int) 8, | |
683 | + 'TOBEARCHIVED' => (int) 1, | |
684 | + 'ARCHIVED' => (int) 1, | |
685 | + 'suivis' => (int) 2, | |
686 | + 'prets' => (int) 2 | |
687 | + ]; | |
688 | + | |
689 | + $nbyears = count($years); | |
690 | + $year_min = $nbyears>0 ? min(array_keys($years)) : $current_year; | |
691 | + | |
692 | + $tot = [ | |
693 | + 'CREATED' => (int) 27, | |
694 | + 'VALIDATED' => (int) 8, | |
695 | + 'TOBEARCHIVED' => (int) 1, | |
696 | + 'ARCHIVED' => (int) 1, | |
697 | + 'suivis' => (int) 2, | |
698 | + 'prets' => (int) 2 | |
699 | + ]; | |
700 | + $avg = [ | |
701 | + 'CREATED' => (float) 27, | |
702 | + 'VALIDATED' => (float) 8, | |
703 | + 'TOBEARCHIVED' => (float) 1, | |
704 | + 'ARCHIVED' => (float) 1, | |
705 | + 'suivis' => (float) 2, | |
706 | + 'prets' => (float) 2 | |
707 | + ]; | |
708 | + | |
709 | + debug($current_year); | |
710 | + debug($year_min); | |
711 | + debug($years); | |
712 | + } // TEST DATA | |
713 | + | |
621 | 714 | $this->set(compact('current_year', 'year_min', 'nbyears', 'tot', 'avg', 'years')); |
622 | 715 | /* |
623 | 716 | debug($tot); | ... | ... |
src/Template/Pages/stats.ctp
... | ... | @@ -40,7 +40,10 @@ $avg = $avg; |
40 | 40 | $tot = $tot; |
41 | 41 | //$tot2 = $tot2; |
42 | 42 | $years = $years; |
43 | -//debug($suivis); | |
43 | +//debug($years); | |
44 | +//debug($tot); | |
45 | + | |
46 | + | |
44 | 47 | |
45 | 48 | |
46 | 49 | |
... | ... | @@ -54,8 +57,7 @@ function echoAsPctAndBold($nbelem, $total=null, $is_bold=false) { |
54 | 57 | $nbelem = "$pct% ($nbelem)"; |
55 | 58 | //$nbelem = "$nbelem ($pct%)"; |
56 | 59 | //$nbelem = "$pct%"; |
57 | - } | |
58 | - echo $nbelem; | |
60 | + } echo $nbelem; | |
59 | 61 | if ($is_bold) echo '</b>'; |
60 | 62 | } |
61 | 63 | |
... | ... | @@ -78,6 +80,9 @@ function displayEmptyLine() { |
78 | 80 | |
79 | 81 | // 100 * (current - prev) / prev |
80 | 82 | function computeEvolutionFromPrevToCurrent($prev,$current) { |
83 | + // 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) | |
84 | + //if ($year_curr_tot==0 || $year_prev_tot==0) return '/'; | |
85 | + if ($prev<=0 || $current<=0) return '/'; | |
81 | 86 | $evol_from_year_prev = round ( 100 * ($current-$prev) / $prev ); |
82 | 87 | if ($evol_from_year_prev >= 0) $evol_from_year_prev = '+'.$evol_from_year_prev; |
83 | 88 | return $evol_from_year_prev.'%'; |
... | ... | @@ -98,7 +103,8 @@ function displayStatsLine($title, $line, $is_bold=false, $year_prev_tot=-1, $avg |
98 | 103 | <!-- Evolution \ N-1 --> |
99 | 104 | <?php |
100 | 105 | //$evol_from_year_prev = '/'; |
101 | - $evol_from_year_prev = $year_prev_tot>0 ? computeEvolutionFromPrevToCurrent($year_prev_tot, $year_curr_tot) : '/'; | |
106 | + $evol_from_year_prev = computeEvolutionFromPrevToCurrent($year_prev_tot, $year_curr_tot); | |
107 | + //$evol_from_year_prev = ($year_curr_tot>0 && $year_prev_tot>0) ? computeEvolutionFromPrevToCurrent($year_prev_tot, $year_curr_tot) : '/'; | |
102 | 108 | /* inutile, on fait pas des maths ici |
103 | 109 | // - Si prev = 0 => éviter division par zéro, résultat = +/- INFINI |
104 | 110 | if ($year_prev_tot==0) { |
... | ... | @@ -117,7 +123,7 @@ function displayStatsLine($title, $line, $is_bold=false, $year_prev_tot=-1, $avg |
117 | 123 | <!-- Evolution \ moyenne --> |
118 | 124 | <?php |
119 | 125 | //$evol_from_avg = '/'; |
120 | - $evol_from_avg = $avg>0 ? computeEvolutionFromPrevToCurrent($avg, $year_curr_tot) : '/'; | |
126 | + $evol_from_avg = computeEvolutionFromPrevToCurrent($avg, $year_curr_tot); | |
121 | 127 | /* |
122 | 128 | if ($avg) { |
123 | 129 | $evol_from_avg = round (($year_curr_tot-$avg['CREATED'])/$avg['CREATED'] * 100); |
... | ... | @@ -298,6 +304,7 @@ echo $this->Form->end(); |
298 | 304 | displayStatsLine($year_title, $val); |
299 | 305 | } |
300 | 306 | */ |
307 | + if ($nbyears>0) | |
301 | 308 | for ($y=$current_year ; $y>=$year_min ; $y--) { |
302 | 309 | $val = $years[$y]; |
303 | 310 | $year_title = $y; | ... | ... |