Project

General

Profile

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