Subversion Repositories eFlore/Applications.del

Compare Revisions

Ignore whitespace Rev 1943 → Rev 1944

/trunk/scripts/modules/maintenance/Maintenance.php
13,68 → 13,111
*/
class Maintenance extends DelScript {
 
protected $tables_referentiel = array(
'bdtfx' => 'tb_eflore_test.bdtfx_v2_01',
'bdtxa' => 'tb_eflore_test.bdtxa_v1_01',
'apd' => 'tb_eflore_test.apd_v3_4_0'
);
protected $tables_referentiel = array();
public function __construct($conteneur) {
$this->conteneur = new Conteneur($this->parametres);
$this->conteneur = new Conteneur($this->parametres);
$this->construireTableauReferentiels();
}
public function executer() {
$propositions = $this->obtenirPropositionsPotentiellementViables();
public function executer() {
$this->affecterNnsAuxPropositionsViables();
//$this->affecterPropositionsRetenues();
}
private function affecterPropositionsRetenues() {
// TODO: est ce vraiment une bonne idée ?
// mettre un filtre sur la date ?
// sur le nombre de votes ?
$requete = "UPDATE del_commentaire dc ".
"SET proposition_retenue = 1 ".
"INNER JOIN del_observation do ".
" ON do.id_observation = dc.ce_observation ".
" AND do.nom_sel_nn = dc.nom_sel_nn ".
" AND do.nom_referentiel = dc.nom_referentiel ".
"WHERE ce_observation IN ( ".
"SELECT ce_observation FROM del_commentaire WHERE proposition_retenue = 0 ".
") ".
"AND ce_observation NOT IN ( ".
"SELECT ce_observation FROM del_commentaire WHERE proposition_retenue = 1 ".
") ";
echo $requete;exit;
$modif = $this->executer($requete);
return $modif;
}
private function affecterNnsAuxPropositionsViables() {
$noms_ordonnes = array();
echo "Affectation de nn aux propositions qui le permettent \n";
$propositions = $this->obtenirPropositionsPotentiellementViables();
$noms_ordonnes = array();
$nb_propositions_traitees = 0;
$nb_prop_orphelines = count($propositions);
$nb_prop_augmentees = 0;
$nb_noms_trouves = 0;
$nb_prop_inchangees = 0;
echo $nb_prop_orphelines.' propositions sont potentiellement améliorables'."\n";
foreach($propositions as $prop) {
$referentiel = in_array($prop['referentiel_proposition'], array_keys($this->tables_referentiel)) ?
$prop['referentiel_proposition'] : $prop['referentiel_observation'];
$referentiel = in_array($referentiel, array_keys($this->tables_referentiel)) ?
$referentiel : 'tous';
$referentiel = substr($referentiel, 0, 5);
if($referentiel == 'tous') {
$noms_trouves = 0;
foreach(array_keys($this->tables_referentiel) as $ref) {
$noms_possibles[$referentiel] = $this->rechercherNomsPossibles($ref, $prop['nom_sel']);
$nb_noms_trouves += count($noms_possibles[$referentiel]);
$noms_trouves += empty($noms_possibles[$referentiel]) ? 1 : 0;
$nb_prop_inchangees = 0;
echo $nb_prop_orphelines.' propositions sont potentiellement améliorables'."\n";
foreach($propositions as $prop) {
$referentiel = in_array($prop['referentiel_proposition'], array_keys($this->tables_referentiel)) ?
$prop['referentiel_proposition'] : $prop['referentiel_observation'];
$referentiel = in_array($referentiel, array_keys($this->tables_referentiel)) ?
$referentiel : 'tous';
$referentiel = substr($referentiel, 0, 5);
if($referentiel == 'tous') {
$noms_trouves = 0;
foreach(array_keys($this->tables_referentiel) as $ref) {
$noms_possibles[$referentiel] = $this->rechercherNomsPossibles($ref, $prop['nom_sel']);
$nb_noms_trouves += count($noms_possibles[$referentiel]);
$noms_trouves += empty($noms_possibles[$referentiel]) ? 1 : 0;
}
$nb_prop_inchangees += $noms_trouves != 0 ? 1 : 0;
if($prop['nom_sel'] == "Iris germanica L.") {
echo '<pre>'.print_r($noms_possibles, true).'</pre>';exit;
}
$nb_prop_inchangees += $noms_trouves != 0 ? 1 : 0;
$nb_prop_augmentees += $noms_trouves != 0 ? 0 : 1;
// Un seul référentiel correspond (c'est déjà bon signe)
if(count($noms_possibles) == 1) {
$nom_dans_ref = reset($noms_possibles);
$nom_referentiel = key($noms_possibles);
// Un seul nom trouvé
if(count($nom_dans_ref) == 1) {
$this->mettreAjourProposition($prop['id_commentaire'], $nom_referentiel, $nom_dans_ref);
$nb_prop_augmentees ++;
}
}
} else {
$noms_possibles[$referentiel] = $this->rechercherNomsPossibles($referentiel, $prop['nom_sel']);
$noms_ordonnes[$prop['id_commentaire']]['nom_trouves'] = $noms_possibles;
$nb_noms_trouves += count($noms_possibles[$referentiel]);
$nb_prop_inchangees += empty($noms_possibles[$referentiel]) ? 1 : 0;
$nb_prop_augmentees += empty($noms_possibles[$referentiel]) ? 0 : 1;
}
$this->afficherAvancement('propositions traitées ');
}
$noms_ordonnes[$prop['id_commentaire']]['proposition'] = $prop;
//TODO: faire la mise à jour
echo "\n";
$noms_possibles = $this->rechercherNomsPossibles($referentiel, $prop['nom_sel']);
$noms_ordonnes[$prop['id_commentaire']]['nom_trouves'] = $noms_possibles;
$nb_noms_trouves += count($noms_possibles);
$nb_prop_inchangees += empty($noms_possibles) ? 1 : 0;
// On ne met à jour qu'en étant absolument sur (si l'on a trouvé un seul nom)
if(count($noms_possibles) == 1) {
$this->mettreAjourProposition($prop['id_commentaire'], $referentiel, array_pop($noms_possibles));
$nb_prop_augmentees ++;
}
}
$this->afficherAvancement('propositions traitées ', 1);
}
$noms_ordonnes[$prop['id_commentaire']]['proposition'] = $prop;
echo "\n";
echo $nb_noms_trouves.' noms ont été trouvés'."\n";
echo $nb_prop_augmentees.' propositions ont été améliorées'."\n";
echo $nb_prop_inchangees.' propositions n\'ont pas pu être améliorées'."\n";
}
private function obtenirPropositionsPotentiellementViables() {
$requete = 'SELECT dc.id_commentaire, dc.nom_sel, dc.nom_referentiel as referentiel_proposition, '.
$requete = 'SELECT DISTINCT dc.id_commentaire, dc.nom_sel, dc.nom_referentiel as referentiel_proposition, '.
'do.nom_referentiel as referentiel_observation '.
'FROM del_commentaire dc '.
'INNER JOIN del_observation do '.
96,4 → 139,19
$noms = $this->conteneur->getBdd()->recupererTous($requete);
return $noms;
}
private function mettreAjourProposition($id_proposition, $referentiel, $infos) {
$requete = "UPDATE del_commentaire ".
"SET nom_sel_nn = ".$this->conteneur->getBdd()->proteger($infos['num_nom']).", ".
" nom_referentiel = ".$this->conteneur->getBdd()->proteger($referentiel)." ".
"WHERE id_commentaire = ".$this->conteneur->getBdd()->proteger($id_proposition);
return $this->conteneur->getBdd()->requeter($requete);
}
private function construireTableauReferentiels() {
$referentiels_dispos = explode(',', $this->conteneur->getParametre('referentiels'));
foreach($referentiels_dispos as $ref) {
$this->tables_referentiel[$ref] = $this->conteneur->getParametre('table_referentiel_'.$ref);
}
}
}
/trunk/scripts/configurations/config.defaut.ini
83,4 → 83,12
 
; +------------------------------------------------------------------------------------------------------+
; Espaces de noms
cheminDelCommun = '../commun'
cheminDelCommun = '../commun'
 
; +------------------------------------------------------------------------------------------------------+
; tables et bases de données des réferentiels
referentiels = "bdtfx,bdtxa,apd,isfan";
table_referentiel_bdtfx = "tb_eflore.bdtfx_v2_01";
table_referentiel_bdtxa = "tb_eflore.bdtxa_v1_01";
table_referentiel_apd = "tb_eflore.apd_v3_4_0";
table_referentiel_isfan = "tb_eflore.isfan_v2013";