440 |
mathilde |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
*
|
|
|
4 |
* /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php baseflor/Baseflor_rang_sup_insertion
|
|
|
5 |
* -a insererDonnees
|
|
|
6 |
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
|
|
|
7 |
*
|
|
|
8 |
*
|
|
|
9 |
*/
|
|
|
10 |
class BaseflorRangSupInsertion {
|
|
|
11 |
|
|
|
12 |
private $table = null;
|
|
|
13 |
private $donnees_initiales = array();
|
|
|
14 |
private $valeurs_insertion;
|
|
|
15 |
private $infos_taxon = array();
|
|
|
16 |
private $conteneur;
|
|
|
17 |
private $efloreCommun;
|
|
|
18 |
private $message;
|
|
|
19 |
private $outils;
|
|
|
20 |
private $nn_courant;
|
|
|
21 |
private $nn_superieur;
|
|
|
22 |
private $champs_ecologiques = array();
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
public function __construct(Conteneur $conteneur) {
|
|
|
26 |
$this->conteneur = $conteneur;
|
|
|
27 |
$this->efloreCommun = $conteneur->getEfloreCommun();
|
|
|
28 |
$this->message = $conteneur->getMessages();
|
|
|
29 |
$this->outils = $conteneur->getOutils();
|
|
|
30 |
$this->dossierBase = dirname(__FILE__).'/';
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
public function insererDonnees(){
|
|
|
34 |
echo "Chargement de la structure en cours \n" ;
|
|
|
35 |
$this->efloreCommun->chargerStructureSql('chemins.rang_sup_sql');
|
|
|
36 |
echo "Récupération des données de baseflor en cours \n";
|
|
|
37 |
$this->recupererDonneesInitiales();
|
|
|
38 |
echo "Calcul des valeurs pour les rangs supérieurs en cours \n";
|
|
|
39 |
$this->consulterInfosTaxons();
|
|
|
40 |
$this->recupererValeursInsertion();
|
|
|
41 |
$this->insererDonneesRangSup();
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
private function insererDonneesRangSup() {
|
|
|
46 |
$table = Config::get('tables.rang_sup');
|
|
|
47 |
$requete_truncate = 'TRUNCATE TABLE '.$table;
|
|
|
48 |
$this->efloreCommun->getBdd()->requeter($requete_truncate);
|
|
|
49 |
foreach ($this->valeurs_insertion as $nn => $valeurs){
|
|
|
50 |
$requete = "INSERT INTO $table VALUES($nn, 'bdtfx', '{$valeurs['ve_lumiere']['min']}', ".
|
|
|
51 |
"'{$valeurs['ve_lumiere']['max']}','{$valeurs['ve_temperature']['min']}',".
|
|
|
52 |
"'{$valeurs['ve_temperature']['max']}','{$valeurs['ve_continentalite']['min']}',".
|
|
|
53 |
"'{$valeurs['ve_continentalite']['max']}','{$valeurs['ve_humidite_atmos']['min']}',".
|
|
|
54 |
"'{$valeurs['ve_humidite_atmos']['max']}','{$valeurs['ve_humidite_edaph']['min']}',".
|
|
|
55 |
"'{$valeurs['ve_humidite_edaph']['max']}','{$valeurs['ve_reaction_sol']['min']}',".
|
|
|
56 |
"'{$valeurs['ve_reaction_sol']['max']}','{$valeurs['ve_nutriments_sol']['min']}',".
|
|
|
57 |
"'{$valeurs['ve_nutriments_sol']['max']}','{$valeurs['ve_salinite']['min']}',".
|
|
|
58 |
"'{$valeurs['ve_salinite']['max']}','{$valeurs['ve_texture_sol']['min']}',".
|
|
|
59 |
"'{$valeurs['ve_texture_sol']['max']}','{$valeurs['ve_mat_org_sol']['min']}',".
|
|
|
60 |
"'{$valeurs['ve_mat_org_sol']['max']}');";
|
|
|
61 |
$this->efloreCommun->getBdd()->requeter($requete);
|
|
|
62 |
$this->message->afficherAvancement('Insertion des valeurs pour les rangs supérieurs en cours');
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
// dans cette solution je parcours les donnees de baseflor
|
|
|
70 |
// je teste une donnée (si min max) pour récuperer les valeurs pour chaque rang superieur
|
|
|
71 |
// jusqu'à famille (180) puis je passe à la suivante jusqu'à avoir parcouru tout baseflor
|
|
|
72 |
private function recupererValeursInsertion(){
|
|
|
73 |
$this->champs_ecologiques = $this->outils->recupererTableauConfig(Config::get('Parametres.champsEcologiques'));
|
|
|
74 |
$this->valeurs_insertion = array();
|
|
|
75 |
if (empty($this->donnees_initiales)) {
|
|
|
76 |
throw new Exception("Erreur : pas de données à traiter.");
|
|
|
77 |
} else {
|
|
|
78 |
foreach ($this->donnees_initiales as $nn => $ecologie) {
|
|
|
79 |
$this->nn_courant = $nn;
|
|
|
80 |
$this->nn_superieur = isset($this->infos_taxon[$this->nn_courant]) ? $this->infos_taxon[$this->nn_courant]['nn_sup'] : null;
|
|
|
81 |
$rang = isset($this->infos_taxon[$this->nn_superieur]) ? $this->infos_taxon[$this->nn_superieur]['rang'] : 179 ;
|
|
|
82 |
while ($rang >= 180){
|
|
|
83 |
if (!isset($donnees_initiales[$this->nn_superieur])) {
|
|
|
84 |
foreach ($this->champs_ecologiques as $nom) {
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
$this->testerSiMinMax($nom, $ecologie[$nom]);
|
|
|
88 |
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
$this->nn_superieur = isset($this->infos_taxon[$this->nn_superieur]) ? $this->infos_taxon[$this->nn_superieur]['nn_sup'] : null;
|
|
|
92 |
$rang = !empty($this->nn_superieur) ? $this->infos_taxon[$this->nn_superieur]['rang'] : 179 ;
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
// ici je parcours toutes les données de baseflor et je teste et récupère les valeurs pour le rang superieur
|
|
|
99 |
//direct puis je récupère les données obtenues et je recommence jusqu'à que tous les rangs obtenus soient des familles
|
|
|
100 |
private function recupererValeursInsertion2(){
|
|
|
101 |
$this->champs_ecologiques = $this->outils->recupererTableauConfig(Config::get('Parametres.champsEcologiques'));
|
|
|
102 |
$this->valeurs_insertion = array();
|
|
|
103 |
if (empty($this->donnees_initiales)) {
|
|
|
104 |
throw new Exception("Erreur : pas de données à traiter.");
|
|
|
105 |
} else {
|
|
|
106 |
$donnees_traitees = $this->donnees_initiales;
|
|
|
107 |
$donnees_deja_traitees = array();
|
|
|
108 |
$condition_fin = true;
|
|
|
109 |
$tab_num_nom = array_keys($donnees_traitees);
|
|
|
110 |
while (!empty($donnees_traitees)) {
|
|
|
111 |
reset($donnees_traitees);
|
|
|
112 |
$this->nn_courant = array_shift($tab_num_nom);
|
|
|
113 |
$data = array_shift($donnees_traitees);
|
|
|
114 |
if (isset($this->infos_taxon[$this->nn_courant])) {
|
|
|
115 |
$this->nn_superieur = $this->infos_taxon[$this->nn_courant]['nn_sup'];
|
|
|
116 |
if (!isset($donnees_deja_traitees[$this->nn_courant])) {
|
|
|
117 |
if ($this->infos_taxon[$this->nn_superieur]['rang'] >= 180){
|
|
|
118 |
$condition_fin = false;
|
|
|
119 |
foreach ($this->champs_ecologiques as $nom) {
|
|
|
120 |
|
|
|
121 |
$this->testerSiMinMax($nom, $data[$nom]);
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
$donnees_deja_traitees[$this->nn_courant] = 1;
|
|
|
128 |
}
|
|
|
129 |
if ($condition_fin == false && empty($donnees_traitees)) {
|
|
|
130 |
$donnees_traitees = $this->valeurs_insertion;
|
|
|
131 |
$tab_num_nom = array_keys($donnees_traitees);
|
|
|
132 |
$condition_fin = true;
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
// je stocke des valeurs à insérer sous la forme : $insertion [{nn_tax_sup}][{nom_de_chps}][{max ou min}] = {valeur}
|
|
|
139 |
private function testerSiMinMax($nom, $valeur) {
|
|
|
140 |
$nn = $this->nn_superieur;
|
|
|
141 |
if ( !isset($this->valeurs_insertion[$nn][$nom]['min'])
|
|
|
142 |
|| empty($valeur['min'])
|
|
|
143 |
|| empty($this->valeurs_insertion[$nn][$nom]['min'])
|
|
|
144 |
|| $this->valeurs_insertion[$nn][$nom]['min'] > $valeur['min'] ){
|
|
|
145 |
$this->valeurs_insertion[$nn][$nom]['min'] = $valeur['min'];
|
|
|
146 |
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
if ( !isset($this->valeurs_insertion[$nn][$nom]['max'])
|
|
|
150 |
|| empty($this->valeurs_insertion[$nn][$nom]['max'])
|
|
|
151 |
|| empty($valeur['max'])
|
|
|
152 |
|| $this->valeurs_insertion[$nn][$nom]['max'] < $valeur['max'] ) {
|
|
|
153 |
$this->valeurs_insertion[$nn][$nom]['max'] = $valeur['max'];
|
|
|
154 |
}
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
// je stocke les infos taxons sous la forme : $info_taxon[{num_nomem}][{num_nomen_sup ou rang}] = {valeur}
|
|
|
158 |
private function consulterInfosTaxons() {
|
|
|
159 |
$table = Config::get('tables.taxons');
|
|
|
160 |
$requete = 'SELECT A.num_nom AS nn, B.num_tax_sup AS nn_sup, A.rang '.
|
|
|
161 |
"FROM $table A JOIN $table B ON (A.num_nom_retenu = B.num_nom) ".
|
|
|
162 |
'WHERE B.num_nom = B.num_nom_retenu ';
|
|
|
163 |
$resultat = $this->efloreCommun->getBdd()->recupererTous($requete);
|
|
|
164 |
foreach ($resultat as $res) {
|
|
|
165 |
$this->infos_taxon[$res['nn']] = array('nn_sup' => $res['nn_sup'], 'rang' => $res['rang'] );
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
// je stocke les valeurs initiales sous la forme : $initiales[{nn_nomem}][{champs ecologique}][{'min' ou 'max'}]
|
|
|
170 |
private function recupererDonneesInitiales() {
|
|
|
171 |
$table = Config::get('tables.donnees');
|
|
|
172 |
$requete = "SELECT num_nomen, ve_lumiere, ve_temperature, ve_continentalite, ve_humidite_atmos, ".
|
|
|
173 |
"ve_humidite_edaph, ve_reaction_sol, ve_nutriments_sol, ve_salinite, ve_texture_sol, ve_mat_org_sol ".
|
|
|
174 |
"FROM $table WHERE BDNT = 'BDTFX' ".
|
|
|
175 |
" AND num_nomen != 0 ".
|
|
|
176 |
" AND (ve_lumiere != '' OR ve_mat_org_sol != '' OR ve_temperature != '' ".
|
|
|
177 |
" OR ve_continentalite != '' OR ve_humidite_atmos != '' OR ve_humidite_edaph != '' ".
|
|
|
178 |
" OR ve_nutriments_sol != '' OR ve_salinite != '' OR ve_texture_sol != '' OR ve_reaction_sol != '' )";
|
|
|
179 |
$resultat = $this->efloreCommun->getBdd()->recupererTous($requete);
|
|
|
180 |
foreach ($resultat as $res) {
|
|
|
181 |
$this->donnees_initiales[$res['num_nomen']] = array(
|
|
|
182 |
've_lumiere' => array('min' => $res['ve_lumiere'], 'max' => $res['ve_lumiere']),
|
|
|
183 |
've_temperature' => array('min' => $res['ve_temperature'], 'max' => $res['ve_temperature']),
|
|
|
184 |
've_continentalite' => array('min' => $res['ve_continentalite'], 'max' => $res['ve_continentalite']),
|
|
|
185 |
've_humidite_atmos' => array('min' => $res['ve_humidite_atmos'], 'max' => $res['ve_humidite_atmos']),
|
|
|
186 |
've_humidite_edaph' => array('min' => $res['ve_humidite_edaph'], 'max' => $res['ve_humidite_edaph']),
|
|
|
187 |
've_reaction_sol' => array('min' => $res['ve_reaction_sol'], 'max' => $res['ve_reaction_sol']),
|
|
|
188 |
've_nutriments_sol' => array('min' => $res['ve_nutriments_sol'], 'max' => $res['ve_nutriments_sol']),
|
|
|
189 |
've_salinite' => array('min' => $res['ve_salinite'], 'max' => $res['ve_salinite']),
|
|
|
190 |
've_texture_sol' => array('min' => $res['ve_texture_sol'], 'max' => $res['ve_texture_sol']),
|
|
|
191 |
've_mat_org_sol' => array('min' => $res['ve_mat_org_sol'], 'max' => $res['ve_mat_org_sol']));
|
|
|
192 |
}
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
// +++ Fonctions de vérification des donnée obtenues ++++//
|
|
|
197 |
|
|
|
198 |
public function testAscendantsDeBaseflor(){
|
|
|
199 |
$this->recupererDonneesInitiales();
|
|
|
200 |
$this->consulterInfosTaxons();
|
|
|
201 |
$fichier = dirname(__FILE__).'/log/verifTaxonsSup.log';
|
|
|
202 |
$liste = array();
|
|
|
203 |
foreach ($this->donnees_initiales as $nn => $data) {
|
|
|
204 |
$nn_sup = isset($this->infos_taxon[$nn]) ? $this->infos_taxon[$nn]['nn_sup'] : '' ;
|
|
|
205 |
if (!empty($nn_sup) && !isset($donnees_initiales[$nn_sup])){
|
|
|
206 |
$rang = isset($this->infos_taxon[$nn_sup]) ? $this->infos_taxon[$nn_sup]['rang'] : 179 ;
|
|
|
207 |
while ($rang >= 180) {
|
|
|
208 |
if (!empty($nn_sup)) {
|
|
|
209 |
if (isset($liste["$nn_sup($rang)"])){
|
|
|
210 |
$liste["$nn_sup($rang)"] .= ", $nn";
|
|
|
211 |
}else {
|
|
|
212 |
$liste["$nn_sup($rang)"] = "$nn";
|
|
|
213 |
}
|
|
|
214 |
$nn_sup = isset($this->infos_taxon[$nn_sup]) ? $this->infos_taxon[$nn_sup]['nn_sup'] : '' ;
|
|
|
215 |
$rang = isset($this->infos_taxon[$nn_sup]) ? $this->infos_taxon[$nn_sup]['rang'] : 179 ;
|
|
|
216 |
}else {
|
|
|
217 |
break;
|
|
|
218 |
}
|
|
|
219 |
}
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
$log = "un ascendant (pas forcement l'ascendant directement au dessus) : les descendants contenus dans baseflor \n";
|
|
|
223 |
foreach ($liste as $cle => $inferieur){
|
|
|
224 |
$log .= "$cle : $inferieur \n";
|
|
|
225 |
}
|
|
|
226 |
file_put_contents($fichier, $log);
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
public function testEcologieAscendantsDeBaseflor(){
|
|
|
230 |
$this->recupererDonneesInitiales();
|
|
|
231 |
$this->consulterInfosTaxons();
|
|
|
232 |
$fichier = dirname(__FILE__).'/log/verifTaxonsSupEcolo.log';
|
|
|
233 |
$liste = array();
|
|
|
234 |
foreach ($this->donnees_initiales as $nn => $data) {
|
|
|
235 |
$nn_sup = isset($this->infos_taxon[$nn]) ? $this->infos_taxon[$nn]['nn_sup'] : '' ;
|
|
|
236 |
if (!empty($nn_sup) && !isset($donnees_initiales[$nn_sup])){
|
|
|
237 |
$rang = isset($this->infos_taxon[$nn_sup]) ? $this->infos_taxon[$nn_sup]['rang'] : 179 ;
|
|
|
238 |
while ($rang >= 180) {
|
|
|
239 |
if (!empty($nn_sup)) {
|
|
|
240 |
$ecolo = array_values($data);
|
|
|
241 |
list($l,$t,$c,$ha,$he,$r,$n,$s,$tx,$mo) = $ecolo;
|
|
|
242 |
if (isset($liste["$nn_sup($rang)"])){
|
|
|
243 |
$liste["$nn_sup($rang)"] .= ",[{$l['min']}, {$t['min']}, {$c['min']},"
|
|
|
244 |
."{$ha['min']}, {$he['min']}, {$r['min']}, {$n['min']}, {$s['min']},"
|
|
|
245 |
."{$tx['min']}, {$mo['min']}]";
|
|
|
246 |
}else {
|
|
|
247 |
$liste["$nn_sup($rang)"] = "[{$l['min']}, {$t['min']}, {$c['min']},"
|
|
|
248 |
."{$ha['min']}, {$he['min']}, {$r['min']}, {$n['min']}, {$s['min']},"
|
|
|
249 |
."{$tx['min']}, {$mo['min']}]";
|
|
|
250 |
}
|
|
|
251 |
$nn_sup = isset($this->infos_taxon[$nn_sup]) ? $this->infos_taxon[$nn_sup]['nn_sup'] : '' ;
|
|
|
252 |
$rang = isset($this->infos_taxon[$nn_sup]) ? $this->infos_taxon[$nn_sup]['rang'] : 179 ;
|
|
|
253 |
}else {
|
|
|
254 |
break;
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
}
|
|
|
258 |
}
|
|
|
259 |
$log = "nn ascendant (pas forcement l'ascendant directement au dessus) :"
|
|
|
260 |
." valeurs descendants contenus dans baseflor \n"
|
|
|
261 |
."Pour le calcul des valeurs min et max de gauche, les valeurs de droite sont utilisées. \n";
|
|
|
262 |
foreach ($liste as $cle => $inferieurs){
|
|
|
263 |
$log .= "$cle : $inferieurs \n";
|
|
|
264 |
}
|
|
|
265 |
file_put_contents($fichier, $log);
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
|
|
|
269 |
}
|