Closed UEWBot closed 1 year ago
A new flag for "interim" may not need to go in the database - it could just read the corresponding is_finished (Game.is_finished, Round.is_finished() or Tournament.is_finished()).
If we do this, we need to move the code that reads the WDD out of TournamentPlayer.save() because we'll be saving TournamentPlayers much more frequently. Or maybe only do that part if the TournamentPlayer is new?
The more I think about it, the more sense this makes. It makes the database schema less confusing. It should be more efficient, in that we're doing the math less often and effectively caching the results in the database. It also makes the view code simpler, in that we should be able to just pass TournamentPlayers, RoundPlayers, and GamePlayers into the template and read the scores there rather than calculating them in the python view code. That should also open up more opportunities to display that data in different ways.
This will also help with issue #225
And it will address issue #199
We already changed TournamentPlayer.save() to only add background for a new TP (commit 07efe15f70d1fe526638a85e157e29f47d86800c), so that's not an issue.
Changed to always store "if everything ended now" scores. Changed all the various views that display scores to pass objects to their templates and do the formatting work in the template.
Currently, the score attribute of GamePlayer, RoundPlayer and TournamentPlayer is only set when the Game, Round, and Tournament ends (which is somewhat confusing). The current score is instead calculated whenever it is needed. But it can only change when SCs change hands, so we're likely recalculating it many more times than we need to - we could calculate it after a game year ends and store it, ideally with a new flag indicating that it is an interim rather than final score. This may well also simplify some of the view code, which could just pass say a GamePlayer object to the template and let the template code retrieve the score. We already have Tournament.store_scores() and Round.store_scores(). Would probably make sense to add a boolean "interim" parameter and to add Game.store_scores(). View code would call the latter, which would then call up to the Round which would update the Tournament.