Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 882 | Rev 893 | 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
57
        AND (LOWER(c.famille) = LOWER(b.famille) OR c.famille IS NULL)
58
       );
59
-- 339
60
 
61
/* test:
62
   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
   FROM  cel_obs c, tb_eflore.bdtfx_v1_01 b, tb_eflore.bdtfx_v1_01 bLAST
64
   WHERE (
65
         bLAST.num_nom = b.num_nom_retenu
66
         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_ret_nn = bLAST.num_nom
68
         AND (LOWER(c.famille) = LOWER(b.famille) OR c.famille IS NULL)
69
         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
   );
71
*/
72
 
73
-- l'update BDTFX avec nom_sel_nn seul
74
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTFX` b, `BASESOURCE`.`TABLEBDTFX` b_nom_ret SET
75
       c.nom_ret = CONCAT(b_nom_ret.nom_sci, ' ', b_nom_ret.auteur),
752 raphael 76
       c.nom_ret_nn = b.num_nom,
77
       c.nt = b.num_taxonomique,
78
       c.famille = b.famille
79
   WHERE (
892 raphael 80
        b_nom_ret.num_nom = b.num_nom_retenu
81
        AND nom_sel_nn IS NOT NULL
882 raphael 82
        AND nom_referentiel = 'bdtfx'
892 raphael 83
        AND nom_sel_nn = b.num_nom
84
        AND (LOWER(c.famille) = LOWER(b.famille) OR c.famille IS NULL)
760 raphael 85
        AND SUBSTRING_INDEX(c.nom_sel, ' ', 1) = SUBSTRING_INDEX(b.nom_sci, ' ', 1)
752 raphael 86
       );
892 raphael 87
-- 251 avec indirection num_nom_retenu
754 raphael 88
 
760 raphael 89
 
892 raphael 90
-- l'update BDTXA avec nom_sel_nn et nom_ret_nn corrects  --
828 raphael 91
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTXA` a SET
754 raphael 92
       c.nom_ret = CONCAT(a.nom_sci, ' ', a.auteur),
892 raphael 93
       c.nt = a.num_tax,
94
       c.famille = a.famille
95
   WHERE (
96
        nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0
97
        AND nom_referentiel = 'bdtxa'
98
        AND nom_ret_nn = num_nom
99
        AND (LOWER(c.famille) = LOWER(a.famille) OR c.famille IS NULL)
100
       );
101
-- 1
102
 
103
/*TODO
104
-- l'update BDTXA avec nom_sel_nn seul
105
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEBDTXA` a SET
106
       c.nom_ret = CONCAT(a.nom_sci, ' ', a.auteur),
754 raphael 107
       c.nom_ret_nn = a.num_nom,
108
       c.nt = a.num_tax,
109
       c.famille = a.famille
110
   WHERE (
882 raphael 111
        nom_sel_nn IS NOT NULL
112
        AND nom_referentiel = 'bdtxa'
754 raphael 113
        AND nom_sel_nn = num_nom
892 raphael 114
        AND (LOWER(c.famille) = LOWER(a.famille) OR c.famille IS NULL)
760 raphael 115
        AND SUBSTRING_INDEX(c.nom_sel, ' ', 1) = SUBSTRING_INDEX(a.nom_sci, ' ', 1)
754 raphael 116
       );
760 raphael 117
-- 49 sans les restrictions sur famille et SUBSTRING_INDEX()
118
-- 47 avec les restrictions sur famille et SUBSTRING_INDEX()
892 raphael 119
*/
760 raphael 120
 
892 raphael 121
 
122
-- l'update ISFAN avec nom_sel_nn et nom_ret_nn corrects  --
882 raphael 123
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEISFAN` i SET
124
       c.nom_ret = CONCAT(i.nom_sci, ' ', i.auteur),
892 raphael 125
       c.nt = i.num_taxonomique,
126
       c.famille = i.famille
127
   WHERE (
128
        nom_sel_nn IS NOT NULL AND nom_ret_nn IS NOT NULL AND nom_ret_nn != 0
129
        AND nom_referentiel = 'isfan'
130
        AND nom_ret_nn = num_nom
131
        AND (LOWER(c.famille) = LOWER(i.famille) OR c.famille IS NULL)
132
       );
133
-- 2
134
 
135
/*TODO
136
-- l'update ISFAN avec nom_sel_nn seul
137
UPDATE `BASEEDIT`.`cel_obs` c, `BASESOURCE`.`TABLEISFAN` i SET
138
       c.nom_ret = CONCAT(i.nom_sci, ' ', i.auteur),
882 raphael 139
       c.nom_ret_nn = i.num_nom,
140
       c.nt = i.num_taxonomique,
141
       c.famille = i.famille
760 raphael 142
   WHERE (
882 raphael 143
        nom_sel_nn IS NOT NULL
144
        AND nom_referentiel = 'isfan'
760 raphael 145
        AND nom_sel_nn = num_nom
892 raphael 146
        AND (LOWER(c.famille) = LOWER(i.famille) OR c.famille IS NULL)
760 raphael 147
       );
892 raphael 148
*/
760 raphael 149
 
150
/*
151
Pour observer les différences:
152
wdiff -w '$(tput bold;tput setaf 1)' -x '$(tput sgr0)' -y '$(tput bold;tput setaf 2)' -z '$(tput sgr0)'  pre.log post.log | \
153
      ansi2html.sh --palette=solarized | \
154
      sed '/^[0-9]/{/span/!d}' > diff.html
155
 
156
# extract les familles ayant changé: sed '/^[0-9]/{/<\/span>$/!d}'
157
# lowercase toutes les familles: awk '{ NF=tolower($NF); print }'
158
 
159
 
160
# filtre sed: changements de famille "normaux"
161
/aceraceae.*sapindaceae/d
162
/scrophulariaceae.*plantaginaceae/d
163
/globulariaceae.*plantaginaceae/d
164
/Famille inconnue.*null/d
165
 
166
# changement "anormaux"
167
/rosaceae.*caprifoliaceae/d
168
/valerianaceae.*caprifoliaceae/d
169
*/