1
|
#!/bin/bash -e
|
2
|
. "$(dirname "${BASH_SOURCE[0]}")"/../table.run
|
3
|
|
4
|
if self_not_included; then
|
5
|
|
6
|
herbaria_filter.ih.csv_/make()
|
7
|
{
|
8
|
echo_func; set_make_vars; check_target_exists
|
9
|
|
10
|
use_local
|
11
|
limit= query='SELECT DISTINCT acronym FROM herbaria.ih ORDER BY acronym' \
|
12
|
to_target pg_export
|
13
|
}
|
14
|
|
15
|
plant_fraction/make() # runtime: 1 hr ("10603 rows affected (53 min 44.68 sec)")
|
16
|
{
|
17
|
echo_func; set_make_vars; mk_table_esc
|
18
|
|
19
|
use_local_remote
|
20
|
if remaking; then table=plant_fraction table_esc= mk_drop|mysql_ANSI; fi
|
21
|
(benign_error=1 mysql <<'EOF'
|
22
|
CREATE TABLE `plant_fraction` (
|
23
|
`institution_code` varchar(255) NOT NULL PRIMARY KEY,
|
24
|
`plant_fraction` float NOT NULL,
|
25
|
KEY `plant_fraction` (`plant_fraction`)
|
26
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8
|
27
|
EOF
|
28
|
) || table=plant_fraction skip_table || return 0
|
29
|
mysql_ANSI <<EOF
|
30
|
INSERT INTO "plant_fraction"
|
31
|
SELECT
|
32
|
institution_code
|
33
|
, COUNT(NULLIF(
|
34
|
family LIKE '%aceae%' OR family IN ('Compositae','Gramineae','Palmae','Guttiferae','Cruciferae','Labiatae','Umbelliferae','Leguminosae')
|
35
|
, false))/COUNT(*)
|
36
|
AS plant_fraction
|
37
|
FROM ${limit:+(SELECT * FROM }$table_esc ${limit:+$(prefix= limit)) s}
|
38
|
GROUP BY institution_code
|
39
|
ORDER BY institution_code
|
40
|
EOF
|
41
|
}
|
42
|
|
43
|
plant_fraction/seal()
|
44
|
{
|
45
|
echo_func; set_make_vars
|
46
|
|
47
|
use_local_remote
|
48
|
table=plant_fraction table_esc= mysql_seal_table
|
49
|
}
|
50
|
|
51
|
plant_fraction_for_herbaria_filter/make()
|
52
|
{
|
53
|
echo_func; set_make_vars; mk_table_esc
|
54
|
|
55
|
plant_fraction/make
|
56
|
use_local_remote
|
57
|
if remaking; then
|
58
|
table=plant_fraction_for_herbaria_filter table_esc= mk_drop|mysql_ANSI
|
59
|
fi
|
60
|
(benign_error=1 mysql <<'EOF'
|
61
|
CREATE VIEW `plant_fraction_for_herbaria_filter` AS
|
62
|
SELECT * FROM `plant_fraction`
|
63
|
WHERE plant_fraction >= 0.8
|
64
|
EOF
|
65
|
) || table=plant_fraction_for_herbaria_filter skip_table || return 0
|
66
|
}
|
67
|
|
68
|
herbaria_filter/make() # runtime: ~0 ("0m2.235s"): CSV import, index scans only
|
69
|
{
|
70
|
echo_func; set_make_vars
|
71
|
|
72
|
use_local_remote
|
73
|
local table="$target_stem"
|
74
|
if remaking; then mk_drop|mysql_ANSI; fi
|
75
|
|
76
|
herbaria_filter.ih.csv_/make
|
77
|
plant_fraction_for_herbaria_filter/make
|
78
|
|
79
|
(benign_error=1 mysql <<'EOF'
|
80
|
CREATE TABLE `herbaria_filter` (
|
81
|
`institution_code` varchar(255) NOT NULL PRIMARY KEY
|
82
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='contains all of IH.vegpath.org?&Index+Herbariorum'
|
83
|
EOF
|
84
|
) || skip_table || return 0
|
85
|
|
86
|
time (
|
87
|
mysql_ANSI <<EOF
|
88
|
INSERT INTO "herbaria_filter"
|
89
|
SELECT institution_code FROM plant_fraction_for_herbaria_filter
|
90
|
EOF
|
91
|
append=1 mysql_import <"$top_dir"/herbaria_filter.ih.csv_
|
92
|
) || return
|
93
|
}
|
94
|
|
95
|
herbaria_filter/seal()
|
96
|
{
|
97
|
echo_func; set_make_vars
|
98
|
|
99
|
use_local_remote
|
100
|
table=herbaria_filter table_esc= mysql_seal_table
|
101
|
}
|
102
|
|
103
|
# table.tsv.gz/make() runtime: 35 min ("34m55.802s")
|
104
|
|
105
|
func_override table.tsv/make__src_table_run
|
106
|
table.tsv/make() # usage: [remake=1] [limit=...] .../run table.tsv/make
|
107
|
{
|
108
|
echo_func; set_make_vars; check_target_exists
|
109
|
|
110
|
herbaria_filter/make
|
111
|
filter="
|
112
|
deleted IS NULL
|
113
|
AND institution_code IN (SELECT * FROM herbaria_filter)" \
|
114
|
self_make table.tsv/make__src_table_run
|
115
|
}
|
116
|
|
117
|
fi
|