|
|
|
|
@ -324,126 +324,94 @@ class Tournament(models.Model): |
|
|
|
|
print("else", index, self.team_count) |
|
|
|
|
return -1 |
|
|
|
|
|
|
|
|
|
def teams(self, includeWaitingList): |
|
|
|
|
# print("Starting teams method") |
|
|
|
|
bracket_teams = [] |
|
|
|
|
group_stage_teams = [] |
|
|
|
|
waiting_teams = [] |
|
|
|
|
teams = [] |
|
|
|
|
def teams(self, include_waiting_list): |
|
|
|
|
""" |
|
|
|
|
Get sorted list of teams for the tournament. |
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
include_waiting_list (bool): Whether to include teams in waiting list |
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
|
list: List of TeamItem objects sorted according to tournament rules |
|
|
|
|
""" |
|
|
|
|
# Initialize team categories |
|
|
|
|
complete_teams = [] |
|
|
|
|
wildcard_bracket = [] |
|
|
|
|
wildcard_group_stage = [] |
|
|
|
|
complete_teams = [] |
|
|
|
|
closed_registration_date = self.closed_registration_date |
|
|
|
|
# print(f"Closed registration date: {closed_registration_date}") |
|
|
|
|
waiting_teams = [] |
|
|
|
|
|
|
|
|
|
for team_registration in self.teamregistration_set.all(): |
|
|
|
|
# print(f"Processing team registration: {team_registration}") |
|
|
|
|
is_valid = False |
|
|
|
|
if closed_registration_date is not None and team_registration.registration_date is not None and team_registration.registration_date <= closed_registration_date: |
|
|
|
|
is_valid = True |
|
|
|
|
if closed_registration_date is None: |
|
|
|
|
is_valid = True |
|
|
|
|
if team_registration.registration_date is None: |
|
|
|
|
is_valid = True |
|
|
|
|
# print(f"Is valid: {is_valid}") |
|
|
|
|
if team_registration.out_of_tournament() is False: |
|
|
|
|
team = TeamItem(team_registration) |
|
|
|
|
# print(f"Created team: {team}") |
|
|
|
|
if team_registration.group_stage_position is not None: |
|
|
|
|
team.set_stage("Poule") |
|
|
|
|
elif team_registration.bracket_position is not None: |
|
|
|
|
team.set_stage("Tableau") |
|
|
|
|
else: |
|
|
|
|
team.set_stage("Attente") |
|
|
|
|
# print(f"Team stage: {team.stage}") |
|
|
|
|
# Get registration cutoff date |
|
|
|
|
closed_date = self.closed_registration_date |
|
|
|
|
|
|
|
|
|
# Process each team registration |
|
|
|
|
for team_reg in self.teamregistration_set.all(): |
|
|
|
|
if team_reg.out_of_tournament(): |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
# Create team item |
|
|
|
|
team = TeamItem(team_reg) |
|
|
|
|
|
|
|
|
|
# Determine if registration is valid based on date |
|
|
|
|
is_valid = ( |
|
|
|
|
closed_date is None or |
|
|
|
|
team_reg.registration_date is None or |
|
|
|
|
(team_reg.registration_date and team_reg.registration_date <= closed_date) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
teams.append(team) |
|
|
|
|
if team_registration.wild_card_bracket: |
|
|
|
|
# Categorize team |
|
|
|
|
if team_reg.wild_card_bracket: |
|
|
|
|
wildcard_bracket.append(team) |
|
|
|
|
elif team_registration.wild_card_group_stage: |
|
|
|
|
elif team_reg.wild_card_group_stage: |
|
|
|
|
wildcard_group_stage.append(team) |
|
|
|
|
elif is_valid is True: |
|
|
|
|
elif is_valid: |
|
|
|
|
complete_teams.append(team) |
|
|
|
|
else: |
|
|
|
|
waiting_teams.append(team) |
|
|
|
|
|
|
|
|
|
# print(f"Total teams: {len(teams)}") |
|
|
|
|
# print(f"Wildcard bracket: {len(wildcard_bracket)}") |
|
|
|
|
# print(f"Wildcard group stage: {len(wildcard_group_stage)}") |
|
|
|
|
# print(f"Complete teams: {len(complete_teams)}") |
|
|
|
|
# print(f"Waiting teams: {len(waiting_teams)}") |
|
|
|
|
|
|
|
|
|
if len(teams) < self.team_count: |
|
|
|
|
teams.sort(key=lambda s: (s.initial_weight, s.team_registration.id)) |
|
|
|
|
return teams |
|
|
|
|
|
|
|
|
|
seeds_count = min(self.team_count, len(teams)) - self.group_stage_count * self.teams_per_group_stage - len(wildcard_bracket) |
|
|
|
|
group_stage_members_count = self.group_stage_count * self.teams_per_group_stage - len(wildcard_group_stage) |
|
|
|
|
if group_stage_members_count < 0: |
|
|
|
|
group_stage_members_count = 0 |
|
|
|
|
if seeds_count < 0: |
|
|
|
|
seeds_count = 0 |
|
|
|
|
# print(f"Seeds count: {seeds_count}") |
|
|
|
|
# print(f"Group stage members count: {group_stage_members_count}") |
|
|
|
|
|
|
|
|
|
if self.team_sorting == TeamSortingType.INSCRIPTION_DATE: |
|
|
|
|
complete_teams.sort(key=lambda s: (s.registration_date is None, s.registration_date or datetime.min, s.initial_weight, s.team_registration.id)) |
|
|
|
|
else: |
|
|
|
|
complete_teams.sort(key=lambda s: (s.initial_weight, s.team_registration.id)) |
|
|
|
|
|
|
|
|
|
selected_teams = complete_teams[:self.team_count] |
|
|
|
|
selected_teams.sort(key=lambda s: (s.initial_weight, s.team_registration.id)) |
|
|
|
|
|
|
|
|
|
if seeds_count > 0: |
|
|
|
|
bracket_teams = selected_teams[:seeds_count] + wildcard_bracket |
|
|
|
|
else: |
|
|
|
|
bracket_teams = [] |
|
|
|
|
# print(f"Bracket teams: {len(bracket_teams)}") |
|
|
|
|
|
|
|
|
|
if group_stage_members_count: |
|
|
|
|
group_stage_end = seeds_count + group_stage_members_count |
|
|
|
|
group_stage_teams = selected_teams[seeds_count:group_stage_end] + wildcard_group_stage |
|
|
|
|
else: |
|
|
|
|
group_stage_teams = [] |
|
|
|
|
# print(f"Group stage teams: {len(group_stage_teams)}") |
|
|
|
|
|
|
|
|
|
waiting_list_count = len(teams) - self.team_count |
|
|
|
|
if waiting_list_count < 0: |
|
|
|
|
waiting_list_count = 0 |
|
|
|
|
# print(f"Waiting list count: {waiting_list_count}") |
|
|
|
|
|
|
|
|
|
if waiting_list_count > 0 or len(waiting_teams) > 0: |
|
|
|
|
if waiting_list_count > 0: |
|
|
|
|
waiting_teams = waiting_teams + complete_teams[-waiting_list_count:] |
|
|
|
|
if self.team_sorting == TeamSortingType.INSCRIPTION_DATE: |
|
|
|
|
waiting_teams.sort(key=lambda s: (s.registration_date is None, s.registration_date or datetime.min, s.initial_weight, s.team_registration.id)) |
|
|
|
|
else: |
|
|
|
|
waiting_teams.sort(key=lambda s: (s.initial_weight, s.team_registration.id)) |
|
|
|
|
else: |
|
|
|
|
waiting_teams = [] |
|
|
|
|
# print(f"Final waiting teams: {len(waiting_teams)}") |
|
|
|
|
|
|
|
|
|
bracket_teams.sort(key=lambda s: (s.weight, s.team_registration.id)) |
|
|
|
|
group_stage_teams.sort(key=lambda s: (s.weight, s.team_registration.id)) |
|
|
|
|
|
|
|
|
|
for team in bracket_teams: |
|
|
|
|
if team.stage == "Attente": |
|
|
|
|
team.set_stage("Tableau") |
|
|
|
|
|
|
|
|
|
for team in group_stage_teams: |
|
|
|
|
if team.stage == "Attente": |
|
|
|
|
# Set initial stage |
|
|
|
|
if team_reg.group_stage_position is not None: |
|
|
|
|
team.set_stage("Poule") |
|
|
|
|
|
|
|
|
|
for team in waiting_teams: |
|
|
|
|
elif team_reg.bracket_position is not None: |
|
|
|
|
team.set_stage("Tableau") |
|
|
|
|
else: |
|
|
|
|
team.set_stage("Attente") |
|
|
|
|
|
|
|
|
|
if includeWaitingList is True: |
|
|
|
|
final_teams = bracket_teams + group_stage_teams + waiting_teams |
|
|
|
|
# print(f"Final teams with waiting list: {len(final_teams)}") |
|
|
|
|
# Sort teams based on tournament rules |
|
|
|
|
if self.team_sorting == TeamSortingType.INSCRIPTION_DATE: |
|
|
|
|
complete_teams.sort(key=lambda t: ( |
|
|
|
|
t.registration_date is None, |
|
|
|
|
t.registration_date or datetime.min, |
|
|
|
|
t.initial_weight, |
|
|
|
|
t.team_registration.id |
|
|
|
|
)) |
|
|
|
|
waiting_teams.sort(key=lambda t: ( |
|
|
|
|
t.registration_date is None, |
|
|
|
|
t.registration_date or datetime.min, |
|
|
|
|
t.initial_weight, |
|
|
|
|
t.team_registration.id |
|
|
|
|
)) |
|
|
|
|
else: |
|
|
|
|
final_teams = bracket_teams + group_stage_teams |
|
|
|
|
# print(f"Final teams without waiting list: {len(final_teams)}") |
|
|
|
|
return final_teams |
|
|
|
|
complete_teams.sort(key=lambda t: (t.initial_weight, t.team_registration.id)) |
|
|
|
|
waiting_teams.sort(key=lambda t: (t.initial_weight, t.team_registration.id)) |
|
|
|
|
|
|
|
|
|
# Determine final team list based on tournament settings |
|
|
|
|
if len(complete_teams) <= self.team_count: |
|
|
|
|
all_teams = wildcard_bracket + wildcard_group_stage + complete_teams |
|
|
|
|
if include_waiting_list: |
|
|
|
|
all_teams.extend(waiting_teams) |
|
|
|
|
return all_teams |
|
|
|
|
|
|
|
|
|
# Split teams into main bracket and waiting list |
|
|
|
|
qualified_teams = complete_teams[:self.team_count] |
|
|
|
|
excess_teams = complete_teams[self.team_count:] |
|
|
|
|
|
|
|
|
|
# Combine all waiting list teams |
|
|
|
|
waiting_list = excess_teams + waiting_teams |
|
|
|
|
|
|
|
|
|
# Return final sorted list |
|
|
|
|
if include_waiting_list: |
|
|
|
|
return wildcard_bracket + wildcard_group_stage + qualified_teams + waiting_list |
|
|
|
|
return wildcard_bracket + wildcard_group_stage + qualified_teams |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def match_groups(self, broadcasted, group_stage_id, round_id): |
|
|
|
|
|