Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev Author Line No. Line
752 raphael 1
/*
2
Objectif: prendre les observations dont nom_sel_nn est défini
3
(et donc dans laquelles les informations générées sont correctes)
4
et mettre à jour ces dernières à partir de la dernière version du référentiel
882 raphael 5
(bdtfx, bdtxa et isfan).
6
 
7
Pour éviter un maximum de faux-positifs, nous vérifions aussi que la famille
8
est conservée (même dans certains cas celle-ci a légitimement changé) et que
9
la première partie du nom_sel correspond toujours à la première partie du nouveau nom_sci
10
qui serait attribué.
752 raphael 11
 
892 raphael 12
-- la requête --
752 raphael 13
-- SELECT id_observation, b.num_nom, CONCAT(b.nom_sci, ' ', b.auteur), b.num_taxonomique, b.famille
14
SELECT id_observation, nom_ret, nom_ret_nn, nt, c.famille
828 raphael 15
   FROM `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTFX` b
752 raphael 16
   WHERE (
882 raphael 17
        nom_sel_nn IS NOT NULL
752 raphael 18
        AND nom_referentiel like 'bdtfx%'
19
        AND nom_sel_nn = num_nom
20
       )
21
   ORDER BY id_observation asc;
892 raphael 22
 
23
 
24
Cependant le nom_sel_nn n'est pas directement le num_num du taxon dont le nom est
25
retenu. Pour cela, une jointure en bdtfx sur num_nom_retenu est nécessaire et c'est
26
ce dernier taxon dont le num_nom est utilisé pour nom_ret_nn.
27
Cependant il peut aussi être vide (si aucun nom_retenu "officiel" n'existe).
28
 
29
Attention, les nom_sel_nn = 0 doivent avoir disparus de cel_obs *AU PRÉALABLE*
30
cf: maj-cleanup-201307.sql
752 raphael 31
*/
32
 
892 raphael 33
 
34
 
35
/* test:
36
   SELECT c.nom_ret_nn, c.nom_ret, b.nom_sci, b.auteur, c.famille, b.famille, c.nt, b.num_taxonomique
37
   FROM  cel_obs c, tb_eflore.bdtfx_v1_01 b
38
   WHERE (
39
        nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0
40
        AND nom_referentiel = 'bdtfx'
41
        AND nom_ret_nn = num_nom
42
        AND (LOWER(c.famille) = LOWER(b.famille) OR c.famille IS NULL)
43
        AND (c.famille != b.famille OR c.nom_ret != CONCAT(b.nom_sci, ' ', b.auteur) OR c.nt != b.num_taxonomique)
44
       );
45
   = 2 taxons: 75134 et 75468 (changement de nt)
46
*/
47
 
48
-- l'update BDTFX avec nom_sel_nn et nom_ret_nn corrects
828 raphael 49
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTFX` b SET
752 raphael 50
       c.nom_ret = CONCAT(b.nom_sci, ' ', b.auteur),
892 raphael 51
       c.nt = b.num_taxonomique,
52
       c.famille = b.famille
53
   WHERE (
54
        nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0
55
        AND nom_referentiel = 'bdtfx'
56
        AND nom_ret_nn = num_nom
893 raphael 57
        /* AND (LOWER(c.famille) = LOWER(b.famille) OR c.famille IS NULL) */
892 raphael 58
       );
893 raphael 59
-- 339 + 41373
60
SELECT ROW_COUNT() AS "BDTFX upd après correction sur nom_ret_nn + nom_sel_nn";
892 raphael 61
 
62
/* test:
63
   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
64
   FROM  cel_obs c, tb_eflore.bdtfx_v1_01 b, tb_eflore.bdtfx_v1_01 bLAST
65
   WHERE (
66
         bLAST.num_nom = b.num_nom_retenu
67
         AND nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0 AND nom_referentiel = 'bdtfx'
68
         AND nom_ret_nn = bLAST.num_nom
69
         AND (LOWER(c.famille) = LOWER(b.famille) OR c.famille IS NULL)
70
         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)
71
   );
72
*/
73
 
74
-- l'update BDTFX avec nom_sel_nn seul
75
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTFX` b, `BASESOURCE`.`TABLEBDTFX` b_nom_ret SET
76
       c.nom_ret = CONCAT(b_nom_ret.nom_sci, ' ', b_nom_ret.auteur),
752 raphael 77
       c.nom_ret_nn = b.num_nom,
78
       c.nt = b.num_taxonomique,
79
       c.famille = b.famille
80
   WHERE (
892 raphael 81
        b_nom_ret.num_nom = b.num_nom_retenu
82
        AND nom_sel_nn IS NOT NULL
882 raphael 83
        AND nom_referentiel = 'bdtfx'
892 raphael 84
        AND nom_sel_nn = b.num_nom
85
        AND (LOWER(c.famille) = LOWER(b.famille) OR c.famille IS NULL)
760 raphael 86
        AND SUBSTRING_INDEX(c.nom_sel, ' ', 1) = SUBSTRING_INDEX(b.nom_sci, ' ', 1)
752 raphael 87
       );
893 raphael 88
-- 251 + 45649 avec indirection num_nom_retenu
89
SELECT ROW_COUNT() AS "BDTFX upd après correction sur nom_sel_nn";
754 raphael 90
 
760 raphael 91
 
892 raphael 92
-- l'update BDTXA avec nom_sel_nn et nom_ret_nn corrects  --
828 raphael 93
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTXA` a SET
754 raphael 94
       c.nom_ret = CONCAT(a.nom_sci, ' ', a.auteur),
892 raphael 95
       c.nt = a.num_tax,
96
       c.famille = a.famille
97
   WHERE (
98
        nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0
99
        AND nom_referentiel = 'bdtxa'
100
        AND nom_ret_nn = num_nom
101
        AND (LOWER(c.famille) = LOWER(a.famille) OR c.famille IS NULL)
102
       );
893 raphael 103
-- 1 + 49
104
SELECT ROW_COUNT() AS "BDTXA upd après correction sur nom_ret_nn + nom_sel_nn";
892 raphael 105
 
106
-- l'update BDTXA avec nom_sel_nn seul
893 raphael 107
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTXA` a, `BASESOURCE`.`TABLEBDTXA` a_nom_ret SET
108
       c.nom_ret = CONCAT(a_nom_ret.nom_sci, ' ', a_nom_ret.auteur),
754 raphael 109
       c.nom_ret_nn = a.num_nom,
110
       c.nt = a.num_tax,
111
       c.famille = a.famille
112
   WHERE (
893 raphael 113
        a_nom_ret.num_nom = a.num_nom_retenu
114
        AND nom_sel_nn IS NOT NULL
882 raphael 115
        AND nom_referentiel = 'bdtxa'
893 raphael 116
        AND nom_sel_nn = a.num_nom
892 raphael 117
        AND (LOWER(c.famille) = LOWER(a.famille) OR c.famille IS NULL)
760 raphael 118
        AND SUBSTRING_INDEX(c.nom_sel, ' ', 1) = SUBSTRING_INDEX(a.nom_sci, ' ', 1)
754 raphael 119
       );
893 raphael 120
-- 47 + 49 avec les restrictions sur famille et SUBSTRING_INDEX()
121
-- 48 sans les restrictions sur famille et SUBSTRING_INDEX()
122
SELECT ROW_COUNT() AS "BDTXA upd après correction sur nom_sel_nn";
760 raphael 123
 
892 raphael 124
-- l'update ISFAN avec nom_sel_nn et nom_ret_nn corrects  --
882 raphael 125
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEISFAN` i SET
126
       c.nom_ret = CONCAT(i.nom_sci, ' ', i.auteur),
892 raphael 127
       c.nt = i.num_taxonomique,
128
       c.famille = i.famille
129
   WHERE (
130
        nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0
131
        AND nom_referentiel = 'isfan'
132
        AND nom_ret_nn = num_nom
133
        AND (LOWER(c.famille) = LOWER(i.famille) OR c.famille IS NULL)
134
       );
135
-- 2
893 raphael 136
SELECT ROW_COUNT() AS "ISFAN upd après correction sur nom_ret_nn + nom_sel_nn";
892 raphael 137
 
138
-- l'update ISFAN avec nom_sel_nn seul
893 raphael 139
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEISFAN` i, `BASESOURCE`.`TABLEISFAN` i_nom_ret SET
140
       c.nom_ret = CONCAT(i_nom_ret.nom_sci, ' ', i_nom_ret.auteur),
882 raphael 141
       c.nom_ret_nn = i.num_nom,
142
       c.nt = i.num_taxonomique,
143
       c.famille = i.famille
760 raphael 144
   WHERE (
893 raphael 145
        i_nom_ret.num_nom = i.num_nom_retenu
146
        AND nom_sel_nn IS NOT NULL
882 raphael 147
        AND nom_referentiel = 'isfan'
893 raphael 148
        AND nom_sel_nn = i.num_nom
892 raphael 149
        AND (LOWER(c.famille) = LOWER(i.famille) OR c.famille IS NULL)
760 raphael 150
       );
893 raphael 151
-- 0
152
SELECT ROW_COUNT() AS "ISFAN upd après correction sur nom_sel_nn";
760 raphael 153
 
154
/*
155
Pour observer les différences:
156
wdiff -w '$(tput bold;tput setaf 1)' -x '$(tput sgr0)' -y '$(tput bold;tput setaf 2)' -z '$(tput sgr0)'  pre.log post.log | \
157
      ansi2html.sh --palette=solarized | \
158
      sed '/^[0-9]/{/span/!d}' > diff.html
159
 
160
# extract les familles ayant changé: sed '/^[0-9]/{/<\/span>$/!d}'
161
# lowercase toutes les familles: awk '{ NF=tolower($NF); print }'
162
 
163
 
164
# filtre sed: changements de famille "normaux"
165
/aceraceae.*sapindaceae/d
166
/scrophulariaceae.*plantaginaceae/d
167
/globulariaceae.*plantaginaceae/d
168
/Famille inconnue.*null/d
169
 
170
# changement "anormaux"
171
/rosaceae.*caprifoliaceae/d
172
/valerianaceae.*caprifoliaceae/d
173
*/