summaryrefslogtreecommitdiff
path: root/archiver
blob: 1c0bc79c0a8fbbaea22b391da1561218db239872 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash

RESULTS_PATH=$1

main() {
    if [ $# -eq 0 ]; then
        help; exit 1
    fi

    case "$1" in
        -h|--help)
            help; exit ;;
    esac

    if [[ ! -d "$RESULTS_PATH" ]]; then
        echo "error: invalid results path"
        exit 1
    fi

    aggregate_files 
}

aggregate_files() {
    OUTPUT=""
    HEADER_INSERTED=false

    while IFS= read -r -d '' ENTRY
    do
        if [ $HEADER_INSERTED == true ]; then
            FILE=$(tail -n +2 "$ENTRY")
        else 
            FILE=$(cat "$ENTRY")
        fi

        OUTPUT+="$FILE\n"
        HEADER_INSERTED=true
    done <   <(find "$RESULTS_PATH" -maxdepth 1 -type f -print0)

    HEADER=$(echo -e "$OUTPUT" | head -n 1)
    ALL_ROWS=$(echo -e "$OUTPUT" | tail -n +2 | sort -t$'\t' -k6,6 -n) 
    STRATS=$(echo -e "$ALL_ROWS" | awk -F '\t' '{print $5}' | sort | uniq)

    OUTPUT=""
    while read -r STRAT; do
        [ -z "$STRAT" ] && continue
        ROWS=$(echo -e "$ALL_ROWS" | grep -P "\t$STRAT\t")
        OUTPUT+="$ROWS\n"
    done <<< "$STRATS"

    OUTPUT=$(echo -e "$HEADER\n$OUTPUT" | head -n -1)
    echo -e "$OUTPUT" > "$RESULTS_PATH/data.csv"
}

help() {
cat << EOF
usage: $0 RESULTS-DIR

Aggregate data from search stragey benchmark

Options:
  -h, --help            Show this message
EOF
}

main "$@"