1
|
#!/bin/bash
|
2
|
# Tests map on all input/*.csv
|
3
|
# Usage: env [n=<num-rows>] self
|
4
|
|
5
|
selfDir="$(dirname -- "$0")"
|
6
|
cd "$selfDir"
|
7
|
|
8
|
shopt -s nullglob
|
9
|
|
10
|
test -n "$n" || n=2
|
11
|
let n++ # account for header row
|
12
|
|
13
|
. ../util/env_password in_password
|
14
|
|
15
|
|
16
|
# Update generated mappings
|
17
|
../../mappings/extract_plot_map
|
18
|
../../mappings/join_all_vegbank
|
19
|
|
20
|
function importCsv()
|
21
|
{
|
22
|
(set -x; head -"$n" "$in")
|
23
|
}
|
24
|
|
25
|
function exportXml()
|
26
|
{
|
27
|
out="$stem.$out_fmt.xml"
|
28
|
(set -x; ../map "../../mappings/$src-$out_fmt.$table.csv" >"output/$out"\
|
29
|
&& diff "accepted_output/$out" "output/$out")
|
30
|
}
|
31
|
|
32
|
function exportDb()
|
33
|
{
|
34
|
(set -x; ../map2vegbank "../../mappings/$src-VegBank.$table.csv")
|
35
|
}
|
36
|
|
37
|
for in in input/*.{csv,sh}; do
|
38
|
ext="${in##*.}" # after last "."
|
39
|
stem="$(basename -- "${in%.*}")" # remove extension and dir
|
40
|
src="${stem%.*}" # before last "."
|
41
|
table="${stem##*.}" # after last "."
|
42
|
|
43
|
# Test exporting to XML
|
44
|
for out_fmt in VegX VegBank; do
|
45
|
if test "$ext" == "csv"; then importCsv|exportXml
|
46
|
elif test "$ext" == "sh"; then (. "$in"; exportXml)
|
47
|
fi
|
48
|
done
|
49
|
|
50
|
# Test exporting to VegBank db
|
51
|
if test "$ext" == "csv"; then importCsv|exportDb
|
52
|
elif test "$ext" == "sh"; then (. "$in"; exportDb)
|
53
|
fi
|
54
|
done
|