Skip to content

Commit e2d7afe

Browse files
committed
fix: calculate WPM based on correctly typed words in Typing Speed Tester
WPM was calculated using the original sentence word count, giving inflated results when the user typed fewer or different words. Now counts only correctly typed words (net WPM) for an accurate metric. Fixes steam-bell-92#898
1 parent 96e54cf commit e2d7afe

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

utilities/Typing-Speed-Tester/Typing-Speed-Tester.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@
7070
# Calculate time
7171
time_taken = end_time - start_time
7272

73-
# Calculate words per minute
74-
words = len(sentence.split())
75-
wpm = (words / time_taken) * 60 if time_taken > 0 else 0
73+
# Calculate words per minute based on typed text
74+
sentence_words = sentence.split()
75+
typed_words = typed_text.split()
76+
correct_words = sum(
77+
1 for i, word in enumerate(typed_words)
78+
if i < len(sentence_words) and word == sentence_words[i]
79+
)
80+
wpm = (correct_words / time_taken) * 60 if time_taken > 0 else 0
7681

7782
# Calculate accuracy
7883
correct_chars = 0

0 commit comments

Comments
 (0)