|
|
|
|
@ -85,12 +85,26 @@ class Match(models.Model): |
|
|
|
|
previous_index = self.round.index + 1 |
|
|
|
|
|
|
|
|
|
# Check if the next index is within the bounds of the rounds array |
|
|
|
|
if previous_index < self.round.tournament.round_set.count(): |
|
|
|
|
return self.round.tournament.round_set.filter(index=previous_index, parent = None).first() |
|
|
|
|
return self.round.tournament.round_set.filter(index=previous_index, parent = self.round.parent).first() |
|
|
|
|
|
|
|
|
|
# Return None or an appropriate value if the index is out of bounds |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
def get_loser_previous_round(self): |
|
|
|
|
# Calculate the next index |
|
|
|
|
if self.round is None: |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
previous_index = self.round.index + 1 |
|
|
|
|
|
|
|
|
|
previous_round = None |
|
|
|
|
# Check if the next index is within the bounds of the rounds array |
|
|
|
|
previous_round = self.round.tournament.round_set.filter(index=previous_index, parent = self.round.parent).first() |
|
|
|
|
if previous_round is None and self.round.parent is not None: |
|
|
|
|
previous_round = self.round.tournament.round_set.filter(id=self.round.parent.id).first() |
|
|
|
|
return previous_round |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
def precedent_match(self, top): |
|
|
|
|
previous_round = self.get_previous_round() |
|
|
|
|
#print(previous_round) |
|
|
|
|
@ -103,6 +117,17 @@ class Match(models.Model): |
|
|
|
|
match = matches.filter(index=match_index).first() |
|
|
|
|
return match |
|
|
|
|
|
|
|
|
|
def loser_precedent_match(self, top): |
|
|
|
|
previous_round = self.get_loser_previous_round() |
|
|
|
|
match = None |
|
|
|
|
if previous_round: |
|
|
|
|
matches = previous_round.match_set.all() # Retrieve the QuerySet |
|
|
|
|
match_index = self.index * 2 + 1 |
|
|
|
|
if top == False: |
|
|
|
|
match_index += 1 |
|
|
|
|
match = matches.filter(index=match_index).first() |
|
|
|
|
return match |
|
|
|
|
|
|
|
|
|
def computed_name(self): |
|
|
|
|
if self.round and self.round.parent is None: |
|
|
|
|
return self.backup_name() |
|
|
|
|
@ -150,44 +175,83 @@ class Match(models.Model): |
|
|
|
|
team_scores = list(self.team_scores.all()) |
|
|
|
|
previous_top_match = self.precedent_match(True) |
|
|
|
|
previous_bottom_match = self.precedent_match(False) |
|
|
|
|
loser_top_match = self.loser_precedent_match(True) |
|
|
|
|
loser_bottom_match = self.loser_precedent_match(False) |
|
|
|
|
|
|
|
|
|
if len(team_scores) == 0: |
|
|
|
|
if (self.round and self.round.tournament.round_set.count() == self.round.index -1): |
|
|
|
|
if (self.round and self.round.parent is None and self.round.tournament.round_set.filter(parent__isnull=True, group_stage_loser_bracket=False).count() - 1 == self.round.index): |
|
|
|
|
names = ["Qualifié", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(team) |
|
|
|
|
names = ["Qualifié", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(team) |
|
|
|
|
return teams |
|
|
|
|
if (self.group_stage): |
|
|
|
|
return teams |
|
|
|
|
|
|
|
|
|
if self.round and self.round.parent: |
|
|
|
|
return teams |
|
|
|
|
|
|
|
|
|
# No team scores at all |
|
|
|
|
if previous_top_match: |
|
|
|
|
names = [f"Gagnants {previous_top_match.computed_name()}", ''] |
|
|
|
|
names = ["Équipe de poule", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(team) |
|
|
|
|
if previous_bottom_match: |
|
|
|
|
names = [f"Gagnants {previous_bottom_match.computed_name()}", ''] |
|
|
|
|
names = ["Équipe de poule", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(team) |
|
|
|
|
return teams |
|
|
|
|
elif self.round and self.round.parent: |
|
|
|
|
if loser_top_match: |
|
|
|
|
names = [f"Perdant {loser_top_match.computed_name()}", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(team) |
|
|
|
|
if loser_bottom_match: |
|
|
|
|
names = [f"Perdant {loser_bottom_match.computed_name()}", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(team) |
|
|
|
|
if previous_top_match: |
|
|
|
|
names = [f"Gagnant {previous_top_match.computed_name()}", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(team) |
|
|
|
|
if previous_bottom_match: |
|
|
|
|
names = [f"Gagnant {previous_bottom_match.computed_name()}", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(team) |
|
|
|
|
elif len(team_scores) == 1: |
|
|
|
|
# Only one team score, handle missing one |
|
|
|
|
existing_team = team_scores[0].live_team(self) |
|
|
|
|
if self.round and self.round.parent: |
|
|
|
|
teams.append(existing_team) |
|
|
|
|
elif (self.group_stage): |
|
|
|
|
if (self.group_stage): |
|
|
|
|
teams.append(existing_team) |
|
|
|
|
else: |
|
|
|
|
if previous_top_match and previous_top_match.disabled == False and previous_top_match.end_date is None: |
|
|
|
|
names = [f"Gagnants {previous_top_match.computed_name()}", ''] |
|
|
|
|
names = ["Équipe de poule", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(team) |
|
|
|
|
elif self.round: |
|
|
|
|
if loser_top_match and loser_top_match.disabled == False and loser_top_match.end_date is None: |
|
|
|
|
names = [f"Perdant {loser_top_match.computed_name()}", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(team) |
|
|
|
|
teams.append(existing_team) |
|
|
|
|
elif previous_bottom_match: |
|
|
|
|
names = [f"Gagnants {previous_bottom_match.computed_name()}", ''] |
|
|
|
|
elif loser_bottom_match: |
|
|
|
|
names = [f"Perdant {loser_bottom_match.computed_name()}", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(existing_team) |
|
|
|
|
teams.append(team) |
|
|
|
|
else: |
|
|
|
|
elif previous_top_match and previous_top_match.disabled == False and previous_top_match.end_date is None: |
|
|
|
|
names = [f"Gagnant {previous_top_match.computed_name()}", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(team) |
|
|
|
|
teams.append(existing_team) |
|
|
|
|
elif previous_bottom_match: |
|
|
|
|
names = [f"Gagnant {previous_bottom_match.computed_name()}", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
teams.append(existing_team) |
|
|
|
|
teams.append(team) |
|
|
|
|
elif (self.round.parent is None and self.round.tournament.round_set.filter(parent__isnull=True, group_stage_loser_bracket=False).count() - 1 == self.round.index): |
|
|
|
|
match_index_within_round = self.index - (int(2 ** self.round.index) - 1) |
|
|
|
|
names = ["Qualifié", ''] |
|
|
|
|
team = self.default_live_team(names) |
|
|
|
|
if match_index_within_round < int(2 ** self.round.index) / 2: |
|
|
|
|
teams.append(existing_team) |
|
|
|
|
teams.append(team) |
|
|
|
|
else: |
|
|
|
|
teams.append(team) |
|
|
|
|
teams.append(existing_team) |
|
|
|
|
|
|
|
|
|
elif len(team_scores) == 2: |
|
|
|
|
# Both team scores present |
|
|
|
|
teams.extend([team_score.live_team(self) for team_score in team_scores]) |
|
|
|
|
|