I’m not sure what causes it, as the calculation is simple:
TextBox.Focused:Connect(function()
LastTime = tick()
end)
local function CalculateWPM()
local words = string.split(TextBox.Text, " ")
print(words)
return #words * 60 / (tick() - LastTime)
end
TextBox.FocusLost:Connect(function(enterPressed)
if enterPressed then
local wpm = CalculateWPM()
print("WPM:", wpm)
end
end)
Are you sure it’s wrong? The calculation doesn’t seem wrong - you first calculate the words per second and convert it to words per minute. Can you try typing longer sentences and words and then checking if it is more correct? Because you’ve got to remember that you typed 3 very short words (I, am, su) so it’s not unlikely to get that low of a score. Tell us if it looks more correct or if it’s still off.
There seems to be something wrong with the (tick() - LastTime) part. It seems to always be equal to around 1.
Take a look at this:
In your last example, you typed 18 words and got a result of 535.7816955941303. Dividing this by 60 and 18 (your number of words), then taking the inverse, you get ~2.016s. (sorry jesus I think I copied the wrong values here) That doesn’t seem to be right. I don’t think you only typed for two seconds.
Not sure what could be wrong here, but .Focused seems to be firing more often than once.
Transcribed Text (T) is the final text entered by the
participant, and |T| is the length of T.
…
WPM = (|T|-1) / S * 60 * 1 / 5
Here, S is time in seconds measured from the first key press
to the last, including backspaces and other edit and modifier
keys. The constant 60 is the number of seconds per minute, and the factor of one fifth accounts for the average length of a word in characters including spaces, numbers, and other printable characters [3]. Note that S is measured from the entry of the
very first character to the last, which means that the entry of the
first character is never timed, which is the motivation for the “–
1” in the numerator of (1). While this assures accuracy, other
researchers sometimes omit this factor.
In other words, if you’re making a WPM typing test-like input box, this paper suggests using local words = (#TextBox.Text - 1) / 5
It also suggests starting your timer when the first character is pressed after focusing, rather than immediately when focusing.
That paper has more good info about how typing errors can be used to adjust the final score.