Project

General

Profile

« Previous | Next » 

Revision 368

input.Makefile: Added rules to verify inserted data and run tests

View differences:

inputs/SALVIAS/verify.0.plots.sql
1
SELECT '# projects';
2
SELECT count(*) FROM project;
3
SELECT '';
4

  
5
SELECT '# plot observations';
6
SELECT count(*) FROM plotevent;
7
SELECT '';
inputs/SALVIAS/test.0.plots.out
1
Inserted 0 rows
inputs/SALVIAS/verify.0.plots.ref.out
1
# projects
2
23
3

  
4
# plot observations
5
13661
6

  
inputs/SALVIAS/verify.0.plots.out
1
# projects
2
22
3

  
4
# plot observations
5
13591
6

  
inputs/SALVIAS/verify.0.plots.ref.sql
1
SELECT '# projects';
2
SELECT count(*) FROM projects;
3
SELECT '';
4

  
5
SELECT '# plot observations';
6
SELECT count(*) FROM plotMetadata;
7
SELECT '';
8

  
9
/*
10
SELECT pr.project_id, project_name, COUNT(PlotID)
11
FROM projects pr JOIN plotMetadata p
12
ON pr.project_id=p.project_id
13
GROUP BY pr.project_id, project_name;
14

  
15
SELECT DISTINCT pr.project_id, project_name, PlotMethod, m.MethodCode, m.Description
16
FROM projects pr JOIN plotMetadata p JOIN lookup_MethodCode m
17
ON pr.project_id=p.project_id AND p.MethodCode=m.MethodCode
18
LIMIT 10;
19

  
20
SELECT p.PlotID, p.SiteCode, COUNT(*)
21
FROM projects pr JOIN plotMetadata p JOIN plotObservations o
22
ON pr.project_id=p.project_id AND p.PlotID=o.PlotID
23
WHERE p.project_id=2
24
GROUP BY p.PlotID, p.SiteCode;
25

  
26
SELECT NoInd, COUNT(*) AS observations
27
FROM plotObservations o JOIN plotMetadata p 
28
ON o.PlotID=p.PlotID
29
WHERE project_id=2
30
GROUP BY NoInd;
31

  
32
SELECT p.PlotID, p.SiteCode, SUM(NoInd) AS Individuals
33
FROM projects pr JOIN plotMetadata p JOIN plotObservations o
34
ON pr.project_id=p.project_id AND p.PlotID=o.PlotID
35
WHERE p.project_id=2
36
GROUP BY p.PlotID, p.SiteCode;
37

  
38
SELECT DISTINCT pr.project_id, project_name, PlotMethod, m.MethodCode, m.Description
39
FROM projects pr JOIN plotMetadata p JOIN lookup_MethodCode m
40
ON pr.project_id=p.project_id AND p.MethodCode=m.MethodCode
41
WHERE m.MethodCode=8;
42

  
43
SELECT NoInd, COUNT(*) AS observations
44
FROM plotObservations o JOIN plotMetadata p JOIN lookup_MethodCode m
45
ON o.PlotID=p.PlotID AND p.MethodCode=m.MethodCode
46
WHERE project_id=2
47
GROUP BY NoInd;
48

  
49
SELECT p.PlotID, p.SiteCode, SUM(NoInd) AS Individuals
50
FROM projects pr JOIN plotMetadata p JOIN plotObservations o
51
ON pr.project_id=p.project_id AND p.PlotID=o.PlotID
52
WHERE p.project_id=1
53
GROUP BY p.PlotID, p.SiteCode
54
LIMIT 10;
55

  
56
SELECT PlotMethod, MethodCode, Description, COUNT(project_id) as projects
57
FROM (
58
SELECT DISTINCT p.PlotMethod, p.MethodCode, p.Description, p.project_id
59
FROM (
60
SELECT project_id, PlotID, PlotMethod, m.MethodCode, m.Description
61
FROM plotMetadata p JOIN lookup_MethodCode m
62
ON p.MethodCode=m.MethodCode
63
) p JOIN plotObservations o JOIN stems s
64
ON p.PlotID=o.PlotID AND o.PlotObsID=s.PlotObsID
65
GROUP BY project_id
66
) AS a
67
GROUP BY PlotMethod, MethodCode, Description;
68

  
69
SELECT DISTINCT pr.project_id, project_name
70
FROM projects pr JOIN plotMetadata p JOIN plotObservations o JOIN stems s
71
ON pr.project_id=p.project_id AND p.PlotID=o.PlotID AND o.PlotObsID=s.PlotObsID
72
WHERE p.MethodCode=3;
73

  
74
SELECT p.PlotID, SiteName as plot, COUNT(*) AS stems
75
FROM plotMetadata p JOIN plotObservations o JOIN stems s
76
ON p.PlotID=o.PlotID AND o.PlotObsID=s.PlotObsID
77
WHERE p.project_id=2
78
GROUP BY p.PlotID, SiteName
79
LIMIT 10;
80

  
81
SELECT p.PlotID, SiteName AS plot, COUNT(DISTINCT Family, Genus, Species) AS SpeciesCount
82
FROM plotMetadata p JOIN plotObservations o
83
ON p.PlotID=o.PlotID
84
WHERE project_id=2
85
GROUP BY p.PlotID, SiteName;
86

  
87
SELECT DISTINCT p.PlotID, SiteName AS plot, Family, CONCAT_WS(' ',IFNULL(Genus,''), IFNULL(Species,'')) AS SpeciesName
88
FROM plotMetadata p JOIN plotObservations o
89
ON p.PlotID=o.PlotID
90
WHERE p.PlotID=298;
91

  
92
SELECT name_status, count(*) FROM plotObservations GROUP BY name_status;
93

  
94
SELECT DISTINCT p.PlotID, SiteName AS plot, Family, 
95
CONCAT_WS(' ',IFNULL(Genus,''), IFNULL(Species,'')) AS SpeciesName, name_status
96
FROM plotMetadata p JOIN plotObservations o
97
ON p.PlotID=o.PlotID
98
WHERE p.PlotID=298;
99

  
100
SELECT DISTINCT p.PlotID, SiteName AS plot, Family, 
101
CONCAT_WS(' ',IFNULL(Genus,''), IFNULL(Species,'')) AS SpeciesName, name_status
102
FROM plotMetadata p JOIN plotObservations o
103
ON p.PlotID=o.PlotID
104
WHERE p.PlotID=298 AND name_status=1;
105

  
106
SELECT p.PlotID, SiteCode AS plot, o.Line as subplot, COUNT(*) AS individuals
107
FROM plotMetadata p JOIN plotObservations o
108
ON p.PlotID=o.PlotID
109
WHERE p.PlotID=298 
110
GROUP BY p.PlotID, plot, subplot;
111

  
112
SELECT p.PlotID, SiteCode AS plot, o.Line as subplot, SUM(NoInd) AS individuals
113
FROM plotMetadata p JOIN plotObservations o
114
ON p.PlotID=o.PlotID
115
WHERE p.PlotID=298
116
GROUP BY p.PlotID, plot, subplot;
117

  
118
SELECT p.PlotID, SiteCode AS plot, o.Line as subplot, SUM(NoInd) AS individuals
119
FROM plotMetadata p JOIN plotObservations o
120
ON p.PlotID=o.PlotID
121
WHERE p.PlotID=1
122
GROUP BY p.PlotID, plot, subplot;
123

  
124
SELECT COUNT(*) FROM plotMetadata WHERE MethodCode=1;
125

  
126
SELECT PlotID FROM plotMetadata WHERE MethodCode=1 LIMIT 1;
127

  
128
SELECT p.PlotID, SiteCode AS plot, Family, 
129
CONCAT_WS(' ',IFNULL(Genus,''), IFNULL(Species,'')) AS SpeciesName, cover_percent
130
FROM plotMetadata p JOIN plotObservations o
131
ON p.PlotID=o.PlotID
132
WHERE p.PlotID=24589;
133

  
134
SELECT p.PlotID, p.SiteCode as plot, Country, PolDiv1 AS stateProvince, pol2 AS countyParish, 
135
LatDec as latitude, LongDec as longitude, Elev as elevation
136
FROM projects pr JOIN plotMetadata p
137
ON pr.project_id=p.project_id
138
WHERE pr.project_id=1
139
LIMIT 20;
140

  
141
SELECT AccessCode, COUNT(*)
142
FROM plotMetadata
143
GROUP BY AccessCode;
144

  
145
SELECT pr.project_id, project_name, project_pi, allow_download_all, PlotID, SiteCode, Country
146
FROM projects pr JOIN plotMetadata p
147
ON pr.project_id=p.project_id
148
WHERE p.AccessCode=1;
149
*/
inputs/input.Makefile
1 1
selfDir_3d1bc249 := $(dir $(lastword $(MAKEFILE_LIST)))
2 2

  
3
# Make
4
addBeforeExt = $(basename $(2))$(1)$(suffix $(2))
5

  
6
# Commands
7
DIFF = diff --unified=1 $(+:_%=)
8

  
9
table = $(shell s="$(*F)"; echo "$${s\#\#*.}")# remove sort order prefix
10

  
3 11
vegxMaps := $(wildcard map.VegX.*.csv)
4 12
vegbienMaps := $(subst .VegX.,.VegBIEN.,$(vegxMaps))
13
tables := $(vegbienMaps:map.VegBIEN.%.csv=%)
5 14

  
6
table = $(shell s="$(*F)"; echo "$${s\#\#*.}")# remove sort order prefix
15
root := $(selfDir_3d1bc249)..
16
psqlAsBien := $(root)/bin/psql_vegbien
7 17

  
8
root := ../..
9
map := env out_database=vegbien $(root)/map
10

  
11 18
#####
12 19

  
13
all: _not_file # empty rule since must be first target in file
20
all: _not_file maps import verify
14 21

  
15 22
.SUFFIXES:
16 23

  
17 24
_not_file:
18 25
.PHONY: _not_file
19 26

  
20
all := $(wildcard output.*) $(vegbienMaps)
21

  
22 27
clean: _not_file
23 28
	$(RM) $(all)
24 29

  
30
rm-%: _not_file
31
	$(RM) $*
32

  
33
%.out: % _not_file
34
	./$* >$@
35
.PRECIOUS: %.out
36

  
25 37
#####
26 38

  
27 39
reinstall: _not_file uninstall install
28 40

  
29 41
#####
30 42

  
43
maps: $(vegbienMaps) _not_file
44

  
45
all += $(vegbienMaps)
46

  
31 47
map.VegBIEN.%.csv: map.VegX.%.csv
32 48
	$(root)/bin/join_sort <$< $(root)/mappings/VegX-VegBIEN.$(table).csv >$@
33 49
.PRECIOUS: map.VegBIEN.%.csv
34 50

  
51
#####
52

  
53
import: _not_file $(addprefix import-,$(tables))
54

  
55
log = $*$(if $(n),.n=$(n),).log
56

  
35 57
logs := $(wildcard *.log)
36 58

  
59
all += $(logs)
60

  
37 61
rm_logs: _not_file
38 62
	$(RM) $(logs)
39 63

  
40 64
#####
41 65

  
66
verify: _not_file $(addprefix verify-,$(tables))
67

  
68
verify-%: verify.%.ref.out verify.%.out _not_file
69
	$(DIFF)
70

  
71
all += $(wildcard verify.*.out)
72

  
73
#####
74

  
75
test: _not_file $(addprefix test-,$(tables))
76

  
77
test-%: test.%.ref.out test.%.out _not_file
78
	$(DIFF)
79

  
80
all += $(filter-out %.ref.out,$(wildcard test.*.out))
81

  
82
#####
83

  
42 84
ifdef db
43 85

  
44
ifndef dbEngine
45
$(error dbEngine variable must be set. Possible values: MySQL, PostgreSQL)
46
endif
47

  
48 86
mapEnv := in_engine=$(dbEngine) in_database=$(db)
49 87

  
50
all: _not_file $(vegbienMaps:map.VegBIEN.%.csv=import-%)
88
####
51 89

  
52
log = $*$(if $(n),.n=$(n),).log
90
ifeq ($(dbEngine),MySQL)
53 91

  
92
bienPassword := $(shell cat $(root)/config/bien_password)
93
mysqlAs = mysql --user=$(1) --password='$(bienPassword)'
94
mysqlAsRoot := $(call mysqlAs,root)
95
mysqlAsBien := $(call mysqlAs,bien)
96

  
54 97
import-%: map.VegBIEN.%.csv _not_file
55 98
	$(importCmd)
56
importCmd = (set -x; "time" env commit=1 $(mapEnv) $(map) $<) \
57
$(if $(n),,>>$(log)) 2>&1 $(if $(n),| tee -a $(log))
99
importCmd = (set -x; "time" env commit=1 $(map) $<) \
100
$(if $(n),,>>$(log)) 2>&1$(if $(n),|tee -a $(log))
58 101

  
59
##
102
all += $(wildcard *.out)
60 103

  
104
%.ref.out: %.ref.sql
105
	$(mysqlAsBien) --skip-column-names $(db) <$< >$@
106
.PRECIOUS: %.ref.out
107

  
108
###
109

  
61 110
install: _not_file db
62 111

  
63 112
uninstall: _not_file rm_db
64 113

  
65
bienPassword := $(shell cat $(root)/config/bien_password)
66
mysql := mysql --user=root --password='$(bienPassword)'
67

  
68 114
db: $(db).sql _not_file
69
	-$(mysql) <$<
70
	echo "GRANT SELECT ON $(db).* TO 'bien'@'localhost';"|$(mysql)
115
	-$(mysqlAsRoot) <$<
116
	echo "GRANT SELECT ON $(db).* TO 'bien'@'localhost';"|$(mysqlAsRoot)
71 117
# ignore errors in db import so that GRANT will still be run
72 118

  
73 119
rm_db: _not_file
74
	-echo "REVOKE ALL ON $(db).* FROM 'bien'@'localhost';"|$(mysql)
75
	echo "DROP DATABASE IF EXISTS $(db);"|$(mysql)
120
	-echo "REVOKE ALL ON $(db).* FROM 'bien'@'localhost';"|$(mysqlAsRoot)
121
	echo "DROP DATABASE IF EXISTS $(db);"|$(mysqlAsRoot)
76 122
# ignore errors if grant not defined
77 123

  
124
###
125

  
126
else
127
$(error dbEngine variable must be one of the following: MySQL, PostgreSQL)
128
endif
129

  
130
####
131

  
132
test.%.out: map.VegBIEN.%.csv _not_file
133
	env n=2 $(map) $< >$@ 2>&1
134
.PRECIOUS: test.%.out
135

  
78 136
#####
79 137

  
80 138
else
81 139
$(error db variable must be set)
82 140
endif
141

  
142
#####
143

  
144
# Must come after mapEnv is set
145
map := env $(mapEnv) out_database=vegbien $(root)/map
146

  
147
# Must come after %.ref.out and test.%.out so they get checked first
148
%.out: %.sql _not_file
149
	$(psqlAsBien) --no-align --tuples-only <$< >$@
150
.PRECIOUS: %.out

Also available in: Unified diff