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

Division by zero adding SC counts for the final year of a game #44

Closed
UEWBot opened this issue Jan 29, 2018 · 2 comments
Closed

Division by zero adding SC counts for the final year of a game #44

UEWBot opened this issue Jan 29, 2018 · 2 comments
Labels

Comments

@UEWBot
Copy link
Owner

UEWBot commented Jan 29, 2018

With a game with a set end year, entering the SC counts for that year causes a division by zero exception. The backtrace is something like this:
game_scoring.py:239 GScoringSumOfSquares.save()
models.py:802 Game.scores()
models.py:1166 Game.save()
models.py:1552 CentreCount.save()
views.py:1232 sc_counts()

It seems that local variable sum_of_squares is zero.

@UEWBot UEWBot added the bug label Jan 29, 2018
@UEWBot
Copy link
Owner Author

UEWBot commented Jan 29, 2018

I think we hit the error because the first CentreCount added is for an eliminated power. Because the year is the final year for the game, we set the game to is_finished and save it. That means recalculating the scores for the game, which retrieves the centre counts for the final year from the db, most of which don't exist. The one that does exist is zero, giving a score of 0/0.

We actually don't want to recalculate the scores until we have the centre counts for all 7 powers saved to the database, which I think means setting the game to finished from the view code instead.

The same bug probably exists if somebody solos, and I suspect things wouldn't be correct if there were no eliminated powers, too, although we might not get an exception in that case).

UEWBot added a commit that referenced this issue Jan 30, 2018
Added a test for issue #44.
Removed CentreCount.save() - we need a full set of CentreCounts before
we can calculate scores for a Game, and Game.save() will recalculate the
scores if is_finished is now True.
Added TODOs to add tests for all the other save() methods, and for where
we may be doing redundant stuff in tests.
In the views, set Game.is_finished (and call Game.save()) when we either
have added CentreCounts for the final game year or have added CentreCounts
including a solo victor.
Also, add an exception handler to Game.news() because when after making the
changes above, some tests were failing because Game.is_finished is now
False when it was previously True.
@UEWBot
Copy link
Owner Author

UEWBot commented Jan 30, 2018

Fixed by commit 6eabb82

@UEWBot UEWBot closed this as completed Jan 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant