forked from CristianCantoro/wscontest-votecounter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
count_votes.sh
executable file
·63 lines (51 loc) · 1.66 KB
/
count_votes.sh
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
#!/usr/bin/env bash
if [ ! -f "books.tsv" ]; then
echo "This script assumes that the book list is in a file named "
echo "'books.tsv' in the current directory "
exit -1
fi
read -p "Number of chuncks to process (1 <= N <= 16)? "
if [ "$REPLY" -lt 1 ]; then
REPLY=1;
fi
if [ "$REPLY" -gt 16 ]; then
REPLY=16;
fi
NUM_CHUNKS=$REPLY
echo "Processing books in $NUM_CHUNKS chunks."
rm -rf output_dir
rm -f books*_sublist.tsv*
rm -f results*_sublist.tsv*
echo
echo -n "Preparing book lists..."
cat "books.tsv" | grep -v -e "#" | sort | sed '/^$/d' > "united"
NUM_BOOKS=$(wc -l < "united")
BOOKS_PER_FILE=$(expr $NUM_BOOKS / $NUM_CHUNKS + 1)
echo " each list will contain $BOOKS_PER_FILE books"
split -l $BOOKS_PER_FILE --numeric-suffixes=01 --additional-suffix="_sublist.tsv" united books
rm united
NUM_BOOK_LISTS=$(ls -1 books*_sublist.tsv | wc -l)
echo
echo "There are $NUM_BOOK_LISTS sub-lists with $BOOKS_PER_FILE books per list"
echo
echo "***********************************************"
echo "I will launch the parallel processes"
echo "Check the progress with the following command:"
echo
echo "tail -n 3 output_dir/1/*/stderr"
echo
echo "***********************************************"
echo
seq -w 01 $NUM_BOOK_LISTS | parallel -t --files --results output_dir $(which python3) score.py -v -f books{}_sublist.tsv -o results{}_sublist.tsv
echo
echo "Books processed... removing temporary files"
rm -rf output_dir
rm -f books*_sublist.tsv*
echo
echo "Merging results..."
$(which python3) merge.py -v --html --html-output index.html results*_sublist.tsv
echo
echo "Done... removing temporary files"
rm results*_sublist.tsv*
echo
echo "All done results are in results_tot.tsv"