From c62cbb23ed9813e78a8b1ca51d4881c23e10cd85 Mon Sep 17 00:00:00 2001 From: MasterMedo Date: Fri, 8 Jan 2021 18:23:43 +0100 Subject: [PATCH] minimal requirements typetest --- typetest | 59 +++++++------------------------------------------------- 1 file changed, 7 insertions(+), 52 deletions(-) diff --git a/typetest b/typetest index 4ef827d..907e83f 100755 --- a/typetest +++ b/typetest @@ -27,8 +27,7 @@ shortcuts: """ -def main(duration, input, rows, shuffle, help, - output, mistyped, char_speeds, word_speeds): +def main(duration, input, rows, shuffle, help, output): """Reads words from `input` delimited by whitespace characters. Takes keys from console forming a word every time a whitespace is sent and compares typed words with test words. Updates the screen calling `draw` @@ -64,9 +63,6 @@ def main(duration, input, rows, shuffle, help, text = '' colors = [color_normal]*len(words) - mistyped_words = [] - char_times = [] - with term.raw(), \ term.cbreak(), \ term.fullscreen(), \ @@ -82,8 +78,7 @@ def main(duration, input, rows, shuffle, help, draw(term, rows, words, colors, word_i, text, wpm, time_passed) char = term.inkey(timeout=0.1, esc_delay=0) - char_time = time() - time_passed = char_time - start if start else 0 + time_passed = time() - start if start else 0 if not char: continue @@ -97,14 +92,15 @@ def main(duration, input, rows, shuffle, help, elif char == '\x08' or char == '\x7f': # ctrl-h or backspace text = text[:-1] - elif char == '\x12': # ctrl-r - correct_chars = total_chars = wpm = 0 + elif char == '\x12' or char == '\x13': # ctrl-r or ctrl-s + correct_chars = total_chars = -1 + wpm = 0 time_passed = actual_duration = start = 0 word_i = 0 text = '' colors = [color_normal]*len(words) - mistyped_words = [] - char_times = [] + if char == '\x13': # ctrl-s + random.shuffle(words) elif char == '\x15' or char == '\x17': # ctrl-u or ctrl-w text = '' @@ -119,21 +115,18 @@ def main(duration, input, rows, shuffle, help, colors[word_i] = color_correct else: colors[word_i] = color_wrong - mistyped_words.append((word, text)) actual_duration = time_passed wpm = min(int(correct_chars*12/actual_duration), 999) text = '' word_i += 1 - char_times.append((char, char_time)) elif not char.isspace(): total_chars += 1 text += char if word_i + 1 >= len(words) and words[-1] == text: term.ungetch(' ') - char_times.append((char, char_time)) total_chars -= len(text) accuracy = 100 * correct_chars // total_chars if total_chars else 0 @@ -147,35 +140,6 @@ def main(duration, input, rows, shuffle, help, return output.write(f'{timestamp},{wpm},{accuracy},{actual_duration},{duration}\n') - for a, b in mistyped_words: - mistyped.write(f'{a},{b},{timestamp}\n') - - char_durations = [] - for i in range(1, len(char_times)): - _, t0 = char_times[i-1] - c, t1 = char_times[i] - char_durations.append((c, t1-t0)) - - for char, t in char_durations: - char_speeds.write(f'{char},{t},{12/t},{timestamp}\n') - - word = '' - word_i = 0 - word_duration = 0 - word_durations = [] - for char, duration in char_durations: - if char.isspace(): - if word == words[word_i]: - word_durations.append((word, word_duration)) - word_i += 1 - word = '' - word_duration = 0 - else: - word += char - word_duration += duration - - for word, t in word_durations: - word_speeds.write(f'{word},{t},{len(word)*12/t},{timestamp}\n') def draw(term, rows, words, colors, word_i, text, wpm, time_passed): @@ -239,15 +203,6 @@ def parse_args(): parser.add_argument('-o', '--output', type=FileType('a'), default=os.path.dirname(__file__) + '/results', help='file to store results in\n' + default) - parser.add_argument('-m', '--mistyped', type=FileType('a'), - default=os.path.dirname(__file__) + '/mistyped_words', - help='file to store mistyped words in\n' + default) - parser.add_argument('-c', '--char_speeds', type=FileType('a'), - default=os.path.dirname(__file__) + '/char_speeds', - help='file to store character speeds in\n' + default) - parser.add_argument('-w', '--word_speeds', type=FileType('a'), - default=os.path.dirname(__file__) + '/word_speeds', - help='file to store word speeds in\n' + default) parser.add_argument('-s', '--shuffle', action='store_true', help='shuffle words ' + default) parser.add_argument('-r', '--rows', type=int, default=2,