PRT.bash (2130B)
1 #!/bin/bash 2 3 pendingPredictions=/home/pendingPredictions.txt 4 pendingPredictionsTemp="${pendingPredictions}.t" 5 resolvedPredictions=/home/resolvedPredictions.txt 6 7 function predict(){ 8 read -p "> Statement: " statement 9 read -p "> Probability (%): " probability 10 read -p "> Date of resolution (year/month/day): " date 11 echo UNRESOLVED,$date,$probability,$statement >> $pendingPredictions 12 } 13 14 function resolve(){ 15 > $pendingPredictions 16 while IFS= read -r -u9 line || [[ -n "$line" ]]; do 17 18 resolutionState="$(cut -d',' -f1 <<<"$line")" 19 date="$(cut -d',' -f2 <<<"$line")" 20 probability="$(cut -d',' -f3 <<<"$line")" 21 statement="$(cut -d',' -f4 <<<"$line")" 22 23 today=$(date +"%Y/%m/%d") 24 if [[ "$today" > "$date" ]]; 25 then 26 # Already passed 27 echo $statement "("$date")" 28 read -p "> (TRUE/FALSE) " resolutionState 29 echo $resolutionState,$date,$probability,$statement >> $resolvedPredictions 30 else 31 # Not yet passed 32 echo $line >> $pendingPredictionsTemp 33 fi 34 done 9< "$pendingPredictions" 35 mv $pendingPredictionsTemp $pendingPredictions 36 } 37 38 function tally(){ 39 40 numTRUEtens=0 41 numFALSEtens=0 42 for i in {0..100} 43 do 44 45 regExPatternTRUE="TRUE.*,${i}," 46 regExPatternFALSE="FALSE.*,${i}," 47 numTRUE="$(grep -c -e $regExPatternTRUE $resolvedPredictions)" 48 numFALSE="$(grep -c -e $regExPatternFALSE $resolvedPredictions)" 49 50 numTRUEtens=$((numTRUEtens+numTRUE)) 51 numFALSEtens=$((numFALSEtens+numFALSE)) 52 if [ $(( $i % 10 )) -eq 0 ] && [ $i -ne 0 ] ; then 53 echo $((i-10)) to $i : $numTRUEtens TRUE and $numFALSEtens FALSE 54 numTRUEtens=0 55 numFALSEtens=0 56 fi 57 done 58 59 }