Fix estimation if the last set

clubs
Laurent 1 year ago
parent a6e6f0f3a8
commit f42d8ba394
  1. 12
      tournaments/models/enums.py
  2. 4
      tournaments/models/match.py
  3. 14
      tournaments/models/team_score.py

@ -44,3 +44,15 @@ class FederalMatchCategory(models.IntegerChoices):
TWO_SETS_DECISIVE_POINT_SUPER_TIE = 7, 'Two Sets with decisive point and super tie-break'
TWO_SETS_FOUR_GAME_DECISIVE_POINT = 8, 'Two sets of four games with decisive point'
NINE_GAMES_DECISIVE_POINT = 9, 'Nine games with decisive point'
def last_set_is_tie_break(value):
if value == FederalMatchCategory.TWO_SETS_FOUR_GAME or value == FederalMatchCategory.TWO_SETS_FOUR_GAME_DECISIVE_POINT or value == FederalMatchCategory.TWO_SETS_SUPER_TIE or value == FederalMatchCategory.SUPER_TIE or value == FederalMatchCategory.MEGA_TIE or value == FederalMatchCategory.TWO_SETS_DECISIVE_POINT_SUPER_TIE:
return True
else:
return False
def max_number_of_sets(value):
if value == FederalMatchCategory.SUPER_TIE or value == FederalMatchCategory.MEGA_TIE or value == FederalMatchCategory.NINE_GAMES or value == FederalMatchCategory.NINE_GAMES_DECISIVE_POINT:
return 1
else:
return 3

@ -116,9 +116,9 @@ class Match(models.Model):
return 3 * 60 * self.total_number_of_games()
def total_number_of_games(self):
games = 0
games = 0.0
for team_score in self.team_scores.all():
games += team_score.number_of_games()
games += team_score.estimated_number_of_games()
return games
def current_duration(self):

@ -1,5 +1,5 @@
from django.db import models
from . import Match, TeamRegistration, PlayerRegistration
from . import Match, TeamRegistration, PlayerRegistration, FederalMatchCategory
import uuid
class TeamScore(models.Model):
@ -44,6 +44,18 @@ class TeamScore(models.Model):
else:
return []
def estimated_number_of_games(self):
scores = self.scores()
format = FederalMatchCategory.NINE_GAMES_DECISIVE_POINT
games = 0.0
if self.match.format:
format = self.match.format
if FederalMatchCategory.last_set_is_tie_break(format) and len(scores) == FederalMatchCategory.max_number_of_sets(format):
points = scores.pop()
games += points / 7 # we take 7 points in average for a game
games += sum(scores)
return games
def number_of_games(self):
scores = self.scores()
return sum(scores)

Loading…
Cancel
Save