Subversion Repositories eFlore/Applications.cel

Rev

Rev 1996 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1996 aurelien 1
<?php
2
// Encodage : UTF-8
3
// +-------------------------------------------------------------------------------------------------------------------+
4
/**
5
 * Traitement des observations sauvages pour les migrer vers des champs étendus
6
 *
7
 * Description : classe permettant d'affecter des champs étendus aux observations sauvages
8
 * Utilisation : php script.php migrationsauvages -a migrerObservationsSauvages
9
 *
10
 * @category		PHP 5.3
11
 * @package		scripts
12
 //Auteur original :
13
 * @author		Aurélien PERONNET <aurelien@tela-botanica.org>
14
 * @copyright	Copyright (c) 2009, Tela Botanica (accueil@tela-botanica.org)
15
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
16
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
17
 * @version		$Id$
18
 */
19
// +-------------------------------------------------------------------------------------------------------------------+
20
class Migrationsauvages extends Script {
21
 
22
	// +-------------------------------------------------------------------------------------------------------------------+
23
	public function executer() {
24
		include_once dirname(__FILE__).'/bibliotheque/Dao.php';
25
		$this->dao = new Dao();
26
		// Récupération de paramétres
27
		// Lancement de l'action demandée
28
		$cmd = $this->getParametre('a');
29
		$this->mode_verbeux = $this->getParametre('v');
30
 
31
		$this->migrerObservationsSauvages();
32
 
33
	}
34
 
35
	private function migrerObservationsSauvages() {
36
		$liste_observations = $this->dao->obtenirObservationsSauvages();
37
		$this->traiterObservationsSauvages($liste_observations);
38
	}
39
 
40
	private function traiterObservationsSauvages($liste_observations) {
41
		$debut = microtime(true);
42
		$nb_obs_modifiees = 0;
43
		$nb_obs_ignorees = 0;
44
		$total = count($liste_observations);
45
 
46
		if($this->mode_verbeux) {
47
			echo "-------------------------------------------------------------------\n";
48
			echo " Début de la migration des observations sauvages vers les champs étendus \n";
49
			echo " ".$total." observations concernées 									\n";
50
			echo "-------------------------------------------------------------------\n";
51
		}
52
 
53
		$champs_etendus_a_inserer = array();
54
		$nb_champs_total = 0;
55
		$nb_champs = 0;
56
		echo " Insertion des champs étendus (5 par observation) par paquet de 100 \n";
57
		foreach($liste_observations as $observation) {
58
 
59
			// test si obs candidate est ok, i.e. si elle contient bien un champ station formate comme ceci
60
			// coordonnees_debut_de_rue;coordonnees_fin_de_rue;cote_de_la_rue
61
			if ($this->doitMigrerObservation($observation)) {
62
				$champs_etendus_a_inserer[] = $this->convertirChampsObsSauvagesEnChampsEtendus($observation);
63
				$nb_obs_modifiees++;
64
				$nb_champs += 5;
65
				$nb_champs_total += 5;
66
			} else {
67
				$nb_obs_ignorees++;
68
			}
69
 
70
			// insertion par paquets de 100 champs ou bien à la fin du parcours de la liste s'il y a moins de
71
			// 20 observations à traiter (20 obs * 5 champs = 100 champs)
72
			if($nb_champs >= 100 || ($nb_obs_modifiees + $nb_obs_ignorees >= count($liste_observations))) {
73
				$this->dao->ajouterChampsEtendusParLots($champs_etendus_a_inserer);
74
				$champs_etendus_a_inserer = array();
75
				$nb_champs = 0;
76
 
77
				if($this->mode_verbeux) {
78
					$this->afficherAvancement(' champs étendus insérés ', $nb_champs_total);
79
				}
80
			}
81
		}
82
 
83
		$fin = microtime(true);
84
		if($this->mode_verbeux) {
85
			echo "\n";
86
			echo "-------------------------------------------------------------------\n";
87
			echo "  Fin de la migration des observations sauvages, \n";
88
			echo "  ".($fin - $debut)." secondes écoulées \n";
89
			echo "  ".$nb_champs_total." champs étendus créées \n";
90
			echo "  ".$nb_obs_modifiees." observations modifiées \n";
91
			echo "  ".$nb_obs_ignorees." observations ignorées \n";
92
			echo "-------------------------------------------------------------------\n";
93
			echo "\n";
94
		}
95
	}
96
 
97
	private function doitMigrerObservation($observation) {
98
		return (!empty($observation['station']) && substr_count($observation['station'],";") == 2);
99
	}
100
 
101
	private function convertirChampsObsSauvagesEnChampsEtendus($observation) {
102
		list($coords_debut_rue,$coords_fin_rue,$cote_rue) = explode(';', $observation['station']);
103
		$coords_debut_rue = explode(',', $coords_debut_rue);
104
		$coords_fin_rue = explode(',', $coords_fin_rue);
105
 
106
		$lieu_dit = (trim($observation['lieudit']) == 'non renseigné(e)') ? '' : $observation['lieudit'];
107
 
108
		$id = $observation['id_observation'];
109
		$champs_etendus = array(
110
							array('id_observation' => $id,
111
										'cle' => 'latitudeDebutRue',
112
										'label' => 'Latitude du début de la rue',
113
										'valeur' => $coords_debut_rue[0]),
114
							array('id_observation' => $id,
115
										'cle' => 'longitudeDebutRue',
116
										'label' => 'Longitude du début de la rue',
117
										'valeur' => $coords_debut_rue[1]),
118
							array('id_observation' => $id,
119
										'cle' => 'latitudeFinRue',
120
										'label' => 'Latitude de fin de la rue',
121
										'valeur' => $coords_debut_rue[0]),
122
							array('id_observation' => $id,
123
										'cle' => 'longitudeFinRue',
124
										'label' => 'Longitude de fin de la rue',
125
										'valeur' => $coords_debut_rue[1]),
126
							array('id_observation' => $id,
127
										'cle' => 'adresse',
128
										'label' => 'Adresse',
129
										'valeur' => $lieu_dit)
130
						);
131
		return $champs_etendus;
132
	}
133
}
134
?>