Merge pull request #50 from lemonsqueeze/can_countercap
[pachi.git] / t-play / autotest / autotest-show
blob77d6e27299aa727e48b6106033d68582dc8d1a64
1 #!/bin/bash
2 # This is autotest display tool, showing gathered information in
3 # a hopefully meaningful way.
5 # Usage: ./autotest-show [-e] [MASK]
6 # Use -e to display winrates in terms of Elo points.
8 do_elo=
9 if [ "$1" = -e ]; then
10 do_elo=1
11 shift
14 mask="$1"
15 [ -n "$mask" ] || mask="*"
16 . ./autotest-lib
18 if [ ! -d "r" ]; then
19 echo "Did you run autotest-gather?" >&2
20 exit 1
23 # Load rc quickly:
24 player() { :; }
25 pknown=" "
26 pairing() { pknown="$pknown$(pairid "$@") "; }
27 . ./rc
29 color_stale="\033[33m"
30 color_bad="\033[31m"
31 color_fresh="\033[1m"
32 color_stop="\033[0m"
34 pairing_status() {
35 # See README for explanation of flags.
36 error=0;
37 if [ -s "r/$pairing.error" ] && [ "$(cat "r/$pairing.error")" -gt 0 ]; then
38 error=1;
40 known=1; [ "${pknown#* $pairing *}" != "$pknown" ] || known=0
41 active=1; ([ -s "r/$pairing.beacon" ] && [ "$(cat "r/$pairing.beacon")" -ge "$(($(date +%s) - 60*60*2))" ]) || active=0
42 case $error$known$active in
43 001) status="${color_stale}?";;
44 000) status="${color_stale}/";;
45 011) status="${color_fresh}.";;
46 010) status="${color_fresh}${color_bad}!";;
47 1*0) status="${color_bad}x";;
48 1*1) status="${color_fresh}${color_bad}X";;
49 esac
52 prob2elo() {
53 echo "400*l(10*$1/(1-$1))/l(10)" | bc -l
56 elo_stats() {
57 ref=0.5
58 refelo=$(prob2elo $ref); wrelo=$(prob2elo $winrate);
59 wrelo_d=$(prob2elo "($winrate-$sd)"); wrelo_u=$(prob2elo "($winrate+$sd)")
60 delo=$((${wrelo%.*}-${refelo%.*})); delo_u=$((${wrelo_u%.*}-${refelo%.*})); delo_d=$((${wrelo_d%.*}-${refelo%.*}))
61 stats="$games\t$delo_d\t$delo\t$delo_u"
64 rm -f r/*.summary.dat r/*.html
66 if [ -n "$do_elo" ]; then
67 printf "S GAMES\tWR -/0/+ (S.D.)\t\tPAIRING\n"
68 else
69 printf "S GAMES\tWINRATE\tS.D.\tPAIRING\n"
71 for pairing in $( (echo "$pknown" | tr ' ' '\n'; ls r/*.dat | sed 's#^r/##; s#\.dat$##') | sort | uniq); do
72 [ ! -s "r/$pairing.dat" ] || $twogtp_path -analyze "r/$pairing.dat"
73 pairing_status "$pairing" # sets status
74 if [ -s "r/$pairing.summary.dat" ]; then
75 cat "r/${pairing}".summary.dat | cut -f 1,7,8 | tail -n +2 | \
76 while read games winrate sd ; do
77 if [ -n "$do_elo" ]; then
78 elo_stats
79 else
80 stats="$games\t$winrate\t$sd"
82 printf "$status $stats\t$pairing$color_stop\n"
83 break
84 done
85 else
86 printf "$status 0\t-\t-\t$pairing$color_stop\n"
88 done