sync
Laurent 8 months ago
parent ff01f5c77a
commit b34f1b201c
  1. 132
      tournaments/models/round.py

@ -109,70 +109,70 @@ class Round(SideStoreModel):
return True
def prepare_match_group(self, next_round, parent_round, loser_final, double_butterfly_mode, secondHalf):
matches = self.matches.filter(disabled=False).order_by('index')
if len(matches) == 0:
return None
if next_round:
next_round_matches = next_round.matches.filter(disabled=False).order_by('index')
else:
next_round_matches = []
if len(matches) < len(next_round_matches):
all_matches = self.matches.order_by('index')
filtered_matches = []
# Process matches in pairs
i = 0
while i < len(all_matches):
# Get the current match and its pair (if available)
current_match = all_matches[i]
pair_match = all_matches[i+1] if i+1 < len(all_matches) else None
# Only filter out the pair if both matches are disabled
if current_match.disabled and pair_match and pair_match.disabled:
# Skip one of the matches in the pair
if next_round_matches.filter(index=current_match.index // 2).exists():
filtered_matches.append(current_match)
filtered_matches.append(pair_match)
pass
else:
# Keep the current match
if current_match.disabled == False:
filtered_matches.append(current_match)
# If there's a pair match, keep it too
if pair_match and pair_match.disabled == False:
filtered_matches.append(pair_match)
# Move to the next pair
i += 2
# Replace the matches list with our filtered list
matches = filtered_matches
if matches:
if len(matches) > 1 and double_butterfly_mode:
midpoint = int(len(matches) / 2)
first_half_matches = matches[:midpoint]
if secondHalf:
first_half_matches = matches[midpoint:]
def prepare_match_group(self, next_round, parent_round, loser_final, double_butterfly_mode, secondHalf):
matches = self.matches.filter(disabled=False).order_by('index')
if len(matches) == 0:
return None
if next_round:
next_round_matches = next_round.matches.filter(disabled=False).order_by('index')
else:
first_half_matches = list(matches) # Convert QuerySet to a list
if self.index == 0 and loser_final:
loser_match = loser_final.matches.first()
if loser_match:
first_half_matches.append(loser_match)
if first_half_matches:
name = self.name()
if parent_round and first_half_matches[0].name is not None:
name = first_half_matches[0].name
match_group = self.tournament.create_match_group(
name=name,
matches=first_half_matches,
round_id=self.id
)
return match_group
return None
next_round_matches = []
if len(matches) < len(next_round_matches):
all_matches = self.matches.order_by('index')
filtered_matches = []
# Process matches in pairs
i = 0
while i < len(all_matches):
# Get the current match and its pair (if available)
current_match = all_matches[i]
pair_match = all_matches[i+1] if i+1 < len(all_matches) else None
# Only filter out the pair if both matches are disabled
if current_match.disabled and pair_match and pair_match.disabled:
# Skip one of the matches in the pair
if next_round_matches.filter(index=current_match.index // 2).exists():
filtered_matches.append(current_match)
filtered_matches.append(pair_match)
pass
else:
# Keep the current match
if current_match.disabled == False:
filtered_matches.append(current_match)
# If there's a pair match, keep it too
if pair_match and pair_match.disabled == False:
filtered_matches.append(pair_match)
# Move to the next pair
i += 2
# Replace the matches list with our filtered list
matches = filtered_matches
if matches:
if len(matches) > 1 and double_butterfly_mode:
midpoint = int(len(matches) / 2)
first_half_matches = matches[:midpoint]
if secondHalf:
first_half_matches = matches[midpoint:]
else:
first_half_matches = list(matches) # Convert QuerySet to a list
if self.index == 0 and loser_final:
loser_match = loser_final.match_set.first()
if loser_match:
first_half_matches.append(loser_match)
if first_half_matches:
name = self.name()
if parent_round and first_half_matches[0].name is not None:
name = first_half_matches[0].name
match_group = self.tournament.create_match_group(
name=name,
matches=first_half_matches,
round_id=self.id
)
return match_group
return None

Loading…
Cancel
Save