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