Capture keypresses and calculate the WPM of the last 10 seconds TODO: I'm not sure my calculation is right.
(dev)
| 198 | |
| 199 | |
| 200 | def 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))) |
no test coverage detected