Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

/*
Objectif: prendre les observations dont nom_sel_nn est défini
(et donc dans laquelles les informations générées sont correctes)
et mettre à jour ces dernières à partir de la dernière version du référentiel
(bdtfx, bdtxa et isfan).

Pour éviter un maximum de faux-positifs, nous vérifions aussi que la famille
est conservée (même dans certains cas celle-ci a légitimement changé) et que
la première partie du nom_sel correspond toujours à la première partie du nouveau nom_sci
qui serait attribué.

-- la requête --
-- SELECT id_observation, b.num_nom, CONCAT(b.nom_sci, ' ', b.auteur), b.num_taxonomique, b.famille
SELECT id_observation, nom_ret, nom_ret_nn, nt, c.famille
   FROM `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTFX` b
   WHERE (
        nom_sel_nn IS NOT NULL
        AND nom_referentiel like 'bdtfx%'
        AND nom_sel_nn = num_nom
       )
   ORDER BY id_observation asc;


Cependant le nom_sel_nn n'est pas directement le num_num du taxon dont le nom est
retenu. Pour cela, une jointure en bdtfx sur num_nom_retenu est nécessaire et c'est
ce dernier taxon dont le num_nom est utilisé pour nom_ret_nn.
Cependant il peut aussi être vide (si aucun nom_retenu "officiel" n'existe).

Attention, les nom_sel_nn = 0 doivent avoir disparus de cel_obs *AU PRÉALABLE*
cf: maj-cleanup-201307.sql
*/



/* test:
   SELECT c.nom_ret_nn, c.nom_ret, b.nom_sci, b.auteur, c.famille, b.famille, c.nt, b.num_taxonomique
   FROM  cel_obs c, tb_eflore.bdtfx_v1_01 b
   WHERE (
        nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0
        AND nom_referentiel = 'bdtfx'
        AND nom_ret_nn = num_nom
        AND (LOWER(c.famille) = LOWER(b.famille) OR c.famille IS NULL)
        AND (c.famille != b.famille OR c.nom_ret != CONCAT(b.nom_sci, ' ', b.auteur) OR c.nt != b.num_taxonomique)
       );
   = 2 taxons: 75134 et 75468 (changement de nt)
*/

-- l'update BDTFX avec nom_sel_nn et nom_ret_nn corrects
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTFX` b SET
       c.nom_ret = CONCAT(b.nom_sci, ' ', b.auteur),
       c.nt = b.num_taxonomique,
       c.famille = b.famille
   WHERE (
        nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0
        AND nom_referentiel = 'bdtfx'
        AND nom_ret_nn = num_nom
        AND (c.mots_cles_texte IS NULL OR c.mots_cles_texte NOT LIKE '%WidgetFlorileges Sauvages%') -- TODO: bug transferts multiples + mobile.js
        AND (LOWER(c.famille) = LOWER(b.famille) OR c.famille IS NULL)
       );
-- 25584
SELECT ROW_COUNT() AS "BDTFX upd après correction sur nom_ret_nn + nom_sel_nn";

/* test:
   SELECT c.nom_ret_nn, c.nom_ret, bLAST.num_nom, bLAST.nom_sci, bLAST.auteur, c.famille, bLAST.famille, c.nt, bLAST.num_taxonomique
   FROM  cel_obs c, tb_eflore.bdtfx_v1_01 b, tb_eflore.bdtfx_v1_01 bLAST
   WHERE (
         bLAST.num_nom = b.num_nom_retenu
         AND nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0 AND nom_referentiel = 'bdtfx'
         AND nom_ret_nn = bLAST.num_nom
         AND (LOWER(c.famille) = LOWER(b.famille) OR c.famille IS NULL)
         AND (c.famille != b.famille OR c.nom_ret != CONCAT(bLAST.nom_sci, ' ', bLAST.auteur) OR c.nt != b.num_taxonomique OR c.nom_ret_nn != bLAST.num_nom)
   );
*/

-- l'update BDTFX avec nom_sel_nn seul
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTFX` b, `BASESOURCE`.`TABLEBDTFX` b_nom_ret SET
       c.nom_ret = CONCAT(b_nom_ret.nom_sci, ' ', b_nom_ret.auteur),
       c.nom_ret_nn = b_nom_ret.num_nom,
       c.nt = b.num_taxonomique,
       c.famille = b.famille,
       c.date_modification = NOW
   WHERE (
        b_nom_ret.num_nom = b.num_nom_retenu
        AND nom_sel_nn IS NOT NULL
        AND nom_referentiel = 'bdtfx'
        AND nom_sel_nn = b.num_nom
        AND (c.mots_cles_texte IS NULL OR c.mots_cles_texte NOT LIKE '%WidgetFlorileges Sauvages%') -- TODO: bug transferts multiples + mobile.js
        AND (LOWER(c.famille) = LOWER(b.famille) OR c.famille IS NULL)
        AND SUBSTRING_INDEX(c.nom_sel, ' ', 1) = SUBSTRING_INDEX(b.nom_sci, ' ', 1)
       );
-- 26369 avec indirection num_nom_retenu
SELECT ROW_COUNT() AS "BDTFX upd après correction sur nom_sel_nn";








-- l'update BDTXA avec nom_sel_nn et nom_ret_nn corrects
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTXA` a SET
       c.nom_ret = CONCAT(a.nom_sci, ' ', a.auteur),
       c.nt = a.num_tax,
       c.famille = a.famille
   WHERE (
        nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0
        AND nom_referentiel = 'bdtxa'
        AND nom_ret_nn = num_nom
        AND (LOWER(c.famille) = LOWER(a.famille) OR c.famille IS NULL)
       );
-- 2
SELECT ROW_COUNT() AS "BDTXA upd après correction sur nom_ret_nn + nom_sel_nn";

-- l'update BDTXA avec nom_sel_nn seul
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTXA` a, `BASESOURCE`.`TABLEBDTXA` a_nom_ret SET
       c.nom_ret = CONCAT(a_nom_ret.nom_sci, ' ', a_nom_ret.auteur),
       c.nom_ret_nn = a_nom_ret.num_nom,
       c.nt = a.num_tax,
       c.famille = a.famille,
       c.date_modification = NOW
   WHERE (
        a_nom_ret.num_nom = a.num_nom_retenu
        AND nom_sel_nn IS NOT NULL
        AND nom_referentiel = 'bdtxa'
        AND nom_sel_nn = a.num_nom
        AND (LOWER(c.famille) = LOWER(a.famille) OR c.famille IS NULL)
        AND SUBSTRING_INDEX(c.nom_sel, ' ', 1) = SUBSTRING_INDEX(a.nom_sci, ' ', 1)
       );
-- 49 avec les restrictions sur famille et SUBSTRING_INDEX()
-- 48 sans les restrictions sur famille et SUBSTRING_INDEX()
SELECT ROW_COUNT() AS "BDTXA upd après correction sur nom_sel_nn";







-- l'update ISFAN avec nom_sel_nn et nom_ret_nn corrects  --
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEISFAN` i SET
       c.nom_ret = CONCAT(i.nom_sci, ' ', i.auteur),
       c.nt = i.num_taxonomique,
       c.famille = i.famille
   WHERE (
        nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0
        AND nom_referentiel = 'isfan'
        AND nom_ret_nn = num_nom
        AND (LOWER(c.famille) = LOWER(i.famille) OR c.famille IS NULL)
       );
-- 2 ou 0
SELECT ROW_COUNT() AS "ISFAN upd après correction sur nom_ret_nn + nom_sel_nn";

-- l'update ISFAN avec nom_sel_nn seul
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEISFAN` i, `BASESOURCE`.`TABLEISFAN` i_nom_ret SET
       c.nom_ret = CONCAT(i_nom_ret.nom_sci, ' ', i_nom_ret.auteur),
       c.nom_ret_nn = IF(i_nom_ret.num_nom=0,NULL,i_nom_ret.num_nom),
       c.nt = i.num_taxonomique,
       c.famille = i.famille,
       c.date_modification = NOW
   WHERE (
        i_nom_ret.num_nom = i.num_nom_retenu
        AND nom_sel_nn IS NOT NULL
        AND nom_referentiel = 'isfan'
        AND nom_sel_nn = i.num_nom
        AND (LOWER(c.famille) = LOWER(i.famille) OR c.famille IS NULL)
       );
-- 0
SELECT ROW_COUNT() AS "ISFAN upd après correction sur nom_sel_nn";

/*
Pour observer les différences:
wdiff -w '$(tput bold;tput setaf 1)' -x '$(tput sgr0)' -y '$(tput bold;tput setaf 2)' -z '$(tput sgr0)'  pre.log post.log | \
      ansi2html.sh --palette=solarized | \
      sed '/^[0-9]/{/span/!d}' > diff.html

# extract les familles ayant changé: sed '/^[0-9]/{/<\/span>$/!d}'
# lowercase toutes les familles: awk '{ NF=tolower($NF); print }'


# filtre sed: changements de famille "normaux"
/aceraceae.*sapindaceae/d
/scrophulariaceae.*plantaginaceae/d
/globulariaceae.*plantaginaceae/d
/Famille inconnue.*null/d

# changement "anormaux"
/rosaceae.*caprifoliaceae/d
/valerianaceae.*caprifoliaceae/d
*/