MCPcopy Index your code
hub / github.com/FrameworkComputer/inputmodule-rs / wpm_demo

Function wpm_demo

python/inputmodule/gui/games.py:200–218  ·  view source on GitHub ↗

Capture keypresses and calculate the WPM of the last 10 seconds TODO: I'm not sure my calculation is right.

(dev)

Source from the content-addressed store, hash-verified

198
199
200def wpm_demo(dev):
201 """Capture keypresses and calculate the WPM of the last 10 seconds
202 TODO: I'm not sure my calculation is right."""
203 start = datetime.now()
204 keypresses = []
205 while True:
206 _ = getkey()
207
208 now = datetime.now()
209 keypresses = [x for x in keypresses if (now - x).total_seconds() < 10]
210 keypresses.append(now)
211 # Word is five letters
212 wpm = (len(keypresses) / 5) * 6
213
214 total_time = (now - start).total_seconds()
215 if total_time < 10:
216 wpm = wpm / (total_time / 10)
217
218 show_string(dev, " " + str(int(wpm)))

Callers 1

main_cliFunction · 0.90

Calls 1

show_stringFunction · 0.90

Tested by

no test coverage detected