UEWBot / dipvis

Django-based visualiser for tournaments for the boardgame Diplomacy
GNU General Public License v3.0
7 stars 5 forks source link

Store "if the game ends now" scores #234

Closed UEWBot closed 1 year ago

UEWBot commented 1 year ago

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.

UEWBot commented 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()).

UEWBot commented 1 year ago

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?

UEWBot commented 1 year ago

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.

UEWBot commented 1 year ago

This will also help with issue #225

UEWBot commented 1 year ago

And it will address issue #199

UEWBot commented 1 year ago

We already changed TournamentPlayer.save() to only add background for a new TP (commit 07efe15f70d1fe526638a85e157e29f47d86800c), so that's not an issue.

UEWBot commented 1 year ago

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.