Project

General

Profile

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 ("49 min 36.03 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(family LIKE '%aceae%' OR family IN ('Compositae','Gramineae','Palmae','Guttiferae','Cruciferae','Labiatae','Umbelliferae','Leguminosae'))/COUNT(*)
34
	AS plant_fraction
35
FROM ${limit:+(SELECT * FROM }$table_esc ${limit:+$(prefix= limit)) s}
36
GROUP BY institution_code
37
ORDER BY institution_code
38
EOF
39
}
40

    
41
plant_fraction/seal()
42
{
43
	echo_func; set_make_vars
44
	
45
	use_local_remote
46
	table=plant_fraction table_esc= mysql_seal_table
47
}
48

    
49
plant_fraction_for_herbaria_filter/make()
50
{
51
	echo_func; set_make_vars; mk_table_esc
52
	
53
	plant_fraction/make
54
	use_local_remote
55
	if remaking; then
56
		table=plant_fraction_for_herbaria_filter table_esc= mk_drop|mysql_ANSI
57
	fi
58
	(benign_error=1 mysql <<'EOF'
59
CREATE VIEW `plant_fraction_for_herbaria_filter` AS
60
SELECT * FROM `plant_fraction`
61
WHERE plant_fraction >= 0.8
62
EOF
63
) || table=plant_fraction_for_herbaria_filter skip_table || return 0
64
}
65

    
66
herbaria_filter/make()
67
{
68
	echo_func; set_make_vars
69
	
70
	use_local_remote
71
	local table="$target_stem"
72
	if remaking; then mk_drop|mysql_ANSI; fi
73
	
74
	herbaria_filter.ih.csv_/make
75
	plant_fraction_for_herbaria_filter/make
76
	
77
	(benign_error=1 mysql <<'EOF'
78
CREATE TABLE `herbaria_filter` (
79
 `institution_code` varchar(255) NOT NULL PRIMARY KEY
80
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='contains all of IH.vegpath.org?&Index+Herbariorum'
81
EOF
82
) || skip_table || return 0
83
	mysql_ANSI <<EOF
84
INSERT INTO "herbaria_filter"
85
SELECT institution_code FROM plant_fraction_for_herbaria_filter
86
EOF
87
	append=1 mysql_import <"$top_dir"/herbaria_filter.ih.csv_
88
}
89

    
90
herbaria_filter/seal()
91
{
92
	echo_func; set_make_vars
93
	
94
	use_local_remote
95
	table=herbaria_filter table_esc= mysql_seal_table
96
}
97

    
98
# table.tsv.gz/make() runtime: 35 min ("34m55.802s")
99

    
100
func_override table.tsv/make__src_table_run
101
table.tsv/make() # usage: [remake=1] [limit=...] .../run table.tsv/make
102
{
103
	echo_func; set_make_vars; check_target_exists
104
	
105
	herbaria_filter/make
106
	filter="
107
deleted IS NULL
108
AND institution_code IN (SELECT * FROM herbaria_filter)" \
109
self_make table.tsv/make__src_table_run
110
}
111

    
112
fi
(7-7/9)