Rev 894 | Rev 896 | 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 familleest conservée (même dans certains cas celle-ci a légitimement changé) et quela première partie du nom_sel correspond toujours à la première partie du nouveau nom_sciqui serait attribué.-- la requête ---- SELECT id_observation, b.num_nom, CONCAT(b.nom_sci, ' ', b.auteur), b.num_taxonomique, b.familleSELECT id_observation, nom_ret, nom_ret_nn, nt, c.familleFROM `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTFX` bWHERE (nom_sel_nn IS NOT NULLAND 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 estretenu. Pour cela, une jointure en bdtfx sur num_nom_retenu est nécessaire et c'estce 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_taxonomiqueFROM cel_obs c, tb_eflore.bdtfx_v1_01 bWHERE (nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0AND nom_referentiel = 'bdtfx'AND nom_ret_nn = num_nomAND (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 correctsUPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTFX` b SETc.nom_ret = CONCAT(b.nom_sci, ' ', b.auteur),c.nt = b.num_taxonomique,c.famille = b.familleWHERE (nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0AND nom_referentiel = 'bdtfx'AND nom_ret_nn = num_nomAND (c.mots_cles_texte IS NULL OR c.mots_cles_texte NOT LIKE '%WidgetFlorileges Sauvages%') -- TODO: bug transferts multiples + mobile.jsAND (LOWER(c.famille) = LOWER(b.famille) OR c.famille IS NULL));-- 25584SELECT 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_taxonomiqueFROM cel_obs c, tb_eflore.bdtfx_v1_01 b, tb_eflore.bdtfx_v1_01 bLASTWHERE (bLAST.num_nom = b.num_nom_retenuAND 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_nomAND (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 seulUPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTFX` b, `BASESOURCE`.`TABLEBDTFX` b_nom_ret SETc.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 = NOWWHERE (b_nom_ret.num_nom = b.num_nom_retenuAND nom_sel_nn IS NOT NULLAND nom_referentiel = 'bdtfx'AND nom_sel_nn = b.num_nomAND (c.mots_cles_texte IS NULL OR c.mots_cles_texte NOT LIKE '%WidgetFlorileges Sauvages%') -- TODO: bug transferts multiples + mobile.jsAND (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_retenuSELECT ROW_COUNT() AS "BDTFX upd après correction sur nom_sel_nn";-- l'update BDTXA avec nom_sel_nn et nom_ret_nn correctsUPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTXA` a SETc.nom_ret = CONCAT(a.nom_sci, ' ', a.auteur),c.nt = a.num_tax,c.famille = a.familleWHERE (nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0AND nom_referentiel = 'bdtxa'AND nom_ret_nn = num_nomAND (LOWER(c.famille) = LOWER(a.famille) OR c.famille IS NULL));-- 2SELECT ROW_COUNT() AS "BDTXA upd après correction sur nom_ret_nn + nom_sel_nn";-- l'update BDTXA avec nom_sel_nn seulUPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTXA` a, `BASESOURCE`.`TABLEBDTXA` a_nom_ret SETc.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 = NOWWHERE (a_nom_ret.num_nom = a.num_nom_retenuAND nom_sel_nn IS NOT NULLAND nom_referentiel = 'bdtxa'AND nom_sel_nn = a.num_nomAND (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 SETc.nom_ret = CONCAT(i.nom_sci, ' ', i.auteur),c.nt = i.num_taxonomique,c.famille = i.familleWHERE (nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0AND nom_referentiel = 'isfan'AND nom_ret_nn = num_nomAND (LOWER(c.famille) = LOWER(i.famille) OR c.famille IS NULL));-- 2 ou 0SELECT ROW_COUNT() AS "ISFAN upd après correction sur nom_ret_nn + nom_sel_nn";-- l'update ISFAN avec nom_sel_nn seulUPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEISFAN` i, `BASESOURCE`.`TABLEISFAN` i_nom_ret SETc.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 = NOWWHERE (i_nom_ret.num_nom = i.num_nom_retenuAND nom_sel_nn IS NOT NULLAND nom_referentiel = 'isfan'AND nom_sel_nn = i.num_nomAND (LOWER(c.famille) = LOWER(i.famille) OR c.famille IS NULL));-- 0SELECT 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*/