Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Division by zero #86

Closed
yyolk opened this issue Apr 29, 2024 · 3 comments
Closed

[BUG] Division by zero #86

yyolk opened this issue Apr 29, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@yyolk
Copy link

yyolk commented Apr 29, 2024

Describe the bug 🐛

The application panics with ZeroDivisionError when calculating the accuracy on a new test when the first character is erased.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ /Users/yolk/Library/Application Support/pipx/venvs/smassh/lib/python3.12/site-packages/smassh/ui/widgets/typing/space.py:153 in check_restrictions                                                                                                                         │
│                                                                                                                                                                                                                                                                            │
│   150 │   │   │   return                                                                       ╭────── locals ───────╮                                                                                                                                                     │
│   151 │   │                                                                                    │ min_speed = 3       │                                                                                                                                                     │
│   152 │   │   if min_speed := config_parser.get("min_speed"):                                  │      self = Space() │                                                                                                                                                     │
│ ❱ 153 │   │   │   wpm = self.tracker.stats.wpm                                                 ╰─────────────────────╯                                                                                                                                                     │
│   154 │   │   │   if wpm < min_speed:                                                                                                                                                                                                                                      │
│   155 │   │   │   │   return self.finish_typing()                                                                                                                                                                                                                          │
│   156                                                                                                                                                                                                                                                                      │
│                                                                                                                                                                                                                                                                            │
│ /Users/yolk/Library/Application Support/pipx/venvs/smassh/lib/python3.12/site-packages/smassh/src/stats_tracker.py:116 in wpm                                                                                                                                              │
│                                                                                                                                                                                                                                                                            │
│   113 │                                                                                        ╭─────────────────────────────── locals ───────────────────────────────╮                                                                                                    │
│   114 │   @property                                                                            │ self = <smassh.src.stats_tracker.StatsTracker object at 0x1066ae120> │                                                                                                    │
│   115 │   def wpm(self) -> int:                                                                ╰──────────────────────────────────────────────────────────────────────╯                                                                                                    │
│ ❱ 116 │   │   return round(self.raw_wpm * (self.accuracy / 100))                                                                                                                                                                                                           │
│   117 │                                                                                                                                                                                                                                                                    │
│   118 │   @property                                                                                                                                                                                                                                                        │
│   119 │   def correct(self) -> int:                                                                                                                                                                                                                                        │
│                                                                                                                                                                                                                                                                            │
│ /Users/yolk/Library/Application Support/pipx/venvs/smassh/lib/python3.12/site-packages/smassh/src/stats_tracker.py:111 in accuracy                                                                                                                                         │
│                                                                                                                                                                                                                                                                            │
│   108 │                                                                                        ╭─────────────────────────────── locals ───────────────────────────────╮                                                                                                    │
│   109 │   @property                                                                            │ self = <smassh.src.stats_tracker.StatsTracker object at 0x1066ae120> │                                                                                                    │
│   110 │   def accuracy(self) -> int:                                                           ╰──────────────────────────────────────────────────────────────────────╯                                                                                                    │
│ ❱ 111 │   │   accuracy = (self.correct / (self.correct + self.incorrect)) * 100                                                                                                                                                                                            │
│   112 │   │   return round(accuracy)                                                                                                                                                                                                                                       │
│   113 │                                                                                                                                                                                                                                                                    │
│   114 │   @property                                                                                                                                                                                                                                                        │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

To Reproduce 🐣

  1. Start typing in a new test after launching smassh
  2. You can type one or more characters, the character doesn't need to be accurate.
  3. Erase up to and including the first character.
  4. When you erase the first character the application will quit with ZeroDivisionError

Expected behavior 🤔

The application doesn't crash when trying to erase the first character.

The statistics account for the first character being erased.

Maybe the WPM calculation accounts for all characters typed at the start of the session; where erased characters aren't subtracted from the overall calculation.

Screenshots 🧐

I couldn't capture screenshots, but I was able to make a video recording.

smassh-division-by-zero.mov

Your operating system name

Mac OS

Your operating system version

Sonoma 14.4.1

Additional context 📝

If I set the Min Speed to 0 in settings, I cannot cause the application to crash with ZeroDivisionError using the steps above.

@yyolk yyolk added the bug Something isn't working label Apr 29, 2024
kraanzu added a commit that referenced this issue Apr 30, 2024
fix: division by zero error when calculating accuracy (#86)
@eklairs
Copy link
Collaborator

eklairs commented Apr 30, 2024

Hey @yyolk!

This bug will be fixed in the next release!

If you are having this bug, again and again, you can install the fixed version from the master branch with:

pip install git+https://github.com/kraanzu/smassh.git

@eklairs eklairs self-assigned this May 5, 2024
@kraanzu
Copy link
Owner

kraanzu commented Oct 1, 2024

Should be fixed now. Please re-open if the issue still persists

@kraanzu kraanzu closed this as completed Oct 1, 2024
Copy link

github-actions bot commented Oct 1, 2024

Did we solve your problem?

Glad we could help!
Don't forget to star the repository!
@kraanzu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants