-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats
executable file
·62 lines (55 loc) · 1.21 KB
/
stats
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
#!/bin/sh
#
# Runs an optimization multiple times, grades results against a threshold
GRY='\e[1;30m'
RED='\e[0;31m'
GRN='\e[0;32m'
YLW='\e[0;33m'
MGT='\e[0;35m'
CYN='\e[0;36m'
NRM='\e[0m'
exp_to_fixed () {
echo $1 | sed -E 's/([+-]?[0-9.]+)[eE]\+?(-?)([0-9]+)/(\1*10^\2\3)/g'
}
args="$0 $*"
n_args=$(($# + 1))
printf "${GRY}args ${NRM}%s${GRY} [ ${MGT}%s${GRY} ]${NRM}\n" $n_args "$args" >&2
samples=$1
threshold=$2
places=$4
shift 2
args="$*"
passed=0
count=1
while [ $count -le $samples ]
do
set -- $($args 2>&1 >/dev/null | tail -1)
result=$*
shift $(($# - 1))
value=$(exp_to_fixed $1)
thrsh=$(exp_to_fixed $threshold)
if [ $(printf "scale=$((places + 3)); $value >= $thrsh;\n" | /usr/bin/bc) -eq 1 ]
then
failed=$((failed + 1))
colour=${RED}
else
passed=$((passed + 1))
colour=${GRN}
fi
printf "${GRY}%3s${NRM} ${colour}%s${NRM}\n" $count "$result"
count=$((count + 1))
done
percent=$((100 * passed / samples))
if [ $percent -ge 90 ]
then
colour=${GRN}
elif [ $percent -ge 70 ]
then
colour=${CYN}
elif [ $percent -ge 20 ]
then
colour=${YLW}
else
colour=${RED}
fi
printf "${GRY} Passed${NRM} ${colour}%3s${NRM} %%\n" $percent >&2