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

Fix divide by 0 issues during betting calculations #589

Closed
wants to merge 2 commits into from

Conversation

ryanolee
Copy link

@ryanolee ryanolee commented Sep 7, 2022

What

This PR aims to avoid inadvertent divide by 0 errors by clamping the minimum divide values to 1 while betting as a defensive measure

Why

Currently bet.py can trigger divide by 0 errors under certain scenarios. In theory given we are calculating percentages / decimal probabilities in this part of the code all dividing values should be > 0 in either case.

Traceback (most recent call last):
  File "/usr/src/app/TwitchChannelPointsMiner/classes/WebSocketsPool.py", line 310, in on_message
    ws.events_predictions[event_id].bet.update_outcomes(
  File "/usr/src/app/TwitchChannelPointsMiner/classes/entities/Bet.py", line 177, in update_outcomes
    self.total_points / self.outcomes[index][OutcomeKeys.TOTAL_POINTS]
ZeroDivisionError: division by zero

This should hopefully raise the stability of the script in edge cases

How

By clamping any values we use for calculating the values to divide to by to one and above

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (README.md) (N/a)
  • My changes generate no new warnings (N/a)
  • Any dependent changes have been updated in requirements.txt (N/a)

@ryanolee
Copy link
Author

ryanolee commented Sep 7, 2022

Note that this might be superseded by #499.

@stale
Copy link

stale bot commented Feb 4, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Feb 4, 2023
@stale stale bot closed this Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant