From f375439b5d11400b26f7bf939ab7821ef787fe54 Mon Sep 17 00:00:00 2001 From: davidovski Date: Wed, 27 Dec 2023 19:26:37 +0000 Subject: accurate accuracy tracking --- typr.sh | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'typr.sh') diff --git a/typr.sh b/typr.sh index 676b208..c45a25d 100755 --- a/typr.sh +++ b/typr.sh @@ -107,7 +107,7 @@ typr_show_results () { words="$(set -- $text ; printf "%s" "$#")" wpm="$((time_ns*words/60000000000))" - acc="100%" + acc="$(typr_calculate_acc)" printf "[%s;${areax}H%s" \ "${areay}" "wpm" \ @@ -115,7 +115,9 @@ typr_show_results () { "$((areay+2))" "acc" \ "$((areay+3))" "$acc" \ "$((areay+4))" "time" \ - "$((areay+5))" "$(typr_get_time)" + "$((areay+5))" "$(typr_get_time)" \ + "$((areay+6))" "words" \ + "$((areay+7))" "$words" } typr_generate_text () { @@ -138,7 +140,30 @@ typr_start_timer () { export start draw_pid } +typr_calculate_acc () { + [ "$total_kp" != "0" ] && printf "%s%%" "$(((100*correct_kp)/total_kp))" || printf "0%" +} + +typr_update_acc () { + c=$1 + total_kp=$((total_kp+1)) + + i=0 + t="$text" + while [ "$i" -lt "$((${#entered_text}-1))" ]; do + i=$((i+1)) + t="${t#?}" # remove first letter + done + correct_c=${t%${t#?}} + + [ "$c" == "$correct_c" ] && correct_kp=$((correct_kp+1)) + export correct_kp total_kp +} + typr_main () { + total_kp=0 + correct_kp=0 + export correct_kp total_kp while true; do typr_draw_text @@ -152,6 +177,7 @@ typr_main () { [ -z "$start" ] && typr_start_timer entered_text="$entered_text$c" + typr_update_acc "$c" ;; esac -- cgit v1.2.1