Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 893 | Rev 895 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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