summaryrefslogtreecommitdiffstats
path: root/mkballots.sh
blob: bee283663806cde82d5d5b5ad68538188cb1f245 (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
#!/bin/bash -x
export PATH=$(realpath -s $(dirname "$0"))/bin:"$PATH"
if [ -z "$1" -o -z "$2" ]; then
    set +x
    echo "Usage: $0 prefix numballots [batches [scoresheets]]" 1>&2
    exit 1
fi
nbatch="${3:-1}"
perbatch="${2:-100}"
scoresheets="${4:-1}"
prefix="$1"
proj="${proj:-tab2016}"
shuf='shuf --random-source=/dev/urandom'
if [ -z "$proj" ]; then
    proj=tab2016
fi
sdaps="sdaps $proj"
rm -rf "$proj"
sed -e "s:%%CANDIDATES%%:$shuf < '$proj'.cand:e" \
    -e 'T' -e 's/^\(.*\)$/\\choiceline{\1}/mg' \
    "$proj".tex > "$proj".pp.tex
$sdaps setup_tex "$proj".pp.tex
rm "$proj".pp.tex
# Produce a tiebreakers file for csvconv.pl so we can reproduce the output
seq 1 $(wc -l < "$proj".cand) | $shuf | tr '\n' ',' | \
    sed -e 's/,$/\n/' > "$proj"/tiebreakers.csv
# Generate score sheets (one PDF with blank ID, one with individual numbers)
scoresheet.pl "$proj" > "$proj"/scoresheet.tex
genids.pl "$prefix"/MT $scoresheets 1 > "$proj"/scoresheet.ids
scoresheet.pl "$proj" "$proj"/scoresheet.ids > "$proj"/scoresheets.tex
cd "$proj"
pdflatex scoresheet.tex && pdflatex scoresheet.tex
pdfmerge questionnaire.pdf scoresheet.pdf chkalign.pdf
pdflatex scoresheets.tex && pdflatex scoresheets.tex
cd ..
bdigits=$(echo -n $((nbatch)) | wc -c)
start=1
for (( batch=1 ; batch <= nbatch ; batch++ )); do
    bname=$(printf "%0${bdigits}d" $batch)
    ids="$proj"/id${bname}.list
    genids.pl "$prefix" $perbatch $start $((nbatch*perbatch)) > "$ids"
    $sdaps stamp -f "$ids" -o "$proj"/ballots_${bname}.pdf
    start=$((start + perbatch))
done
# Make a backup copy of the project directory
tar cvvfJ "$proj".sdaps.tar.xz "$proj" "$proj".tex "$proj".cand