|
|
|
@ -1199,7 +1199,7 @@ class Tournament(models.Model): |
|
|
|
if not matches: |
|
|
|
if not matches: |
|
|
|
return [] |
|
|
|
return [] |
|
|
|
|
|
|
|
|
|
|
|
# Get all unfinished matches with court assignments |
|
|
|
# Get all unfinished matches for courts |
|
|
|
active_matches = [ |
|
|
|
active_matches = [ |
|
|
|
m for m in matches |
|
|
|
m for m in matches |
|
|
|
if m.end_date is None # Not finished |
|
|
|
if m.end_date is None # Not finished |
|
|
|
@ -1215,6 +1215,13 @@ class Tournament(models.Model): |
|
|
|
courts.add(match.court_index) |
|
|
|
courts.add(match.court_index) |
|
|
|
matches_by_court[match.court_index].append(match) |
|
|
|
matches_by_court[match.court_index].append(match) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Sort matches within each court by start time |
|
|
|
|
|
|
|
for court in matches_by_court: |
|
|
|
|
|
|
|
matches_by_court[court].sort(key=lambda m: ( |
|
|
|
|
|
|
|
m.start_date is None, # None dates come last |
|
|
|
|
|
|
|
m.start_date if m.start_date else timezone.now() |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
# Sort courts and organize them into groups of 4 |
|
|
|
# Sort courts and organize them into groups of 4 |
|
|
|
sorted_courts = sorted(list(courts)) |
|
|
|
sorted_courts = sorted(list(courts)) |
|
|
|
court_groups = [sorted_courts[i:i+4] for i in range(0, len(sorted_courts), 4)] |
|
|
|
court_groups = [sorted_courts[i:i+4] for i in range(0, len(sorted_courts), 4)] |
|
|
|
@ -1222,19 +1229,25 @@ class Tournament(models.Model): |
|
|
|
ordered_matches = [] |
|
|
|
ordered_matches = [] |
|
|
|
# For each group of up to 4 courts |
|
|
|
# For each group of up to 4 courts |
|
|
|
for court_group in court_groups: |
|
|
|
for court_group in court_groups: |
|
|
|
# First row: current/next match for each court |
|
|
|
# First row: earliest match for each court |
|
|
|
for court in court_group: |
|
|
|
for court in court_group: |
|
|
|
if court in matches_by_court and matches_by_court[court]: |
|
|
|
if court in matches_by_court and matches_by_court[court]: |
|
|
|
ordered_matches.append(matches_by_court[court][0]) |
|
|
|
ordered_matches.append(matches_by_court[court][0]) |
|
|
|
else: |
|
|
|
else: |
|
|
|
ordered_matches.append(None) # Empty space |
|
|
|
ordered_matches.append({"empty": True}) |
|
|
|
|
|
|
|
# Pad to 4 courts if needed |
|
|
|
|
|
|
|
while len(ordered_matches) % 4 != 0: |
|
|
|
|
|
|
|
ordered_matches.append({"empty": True}) |
|
|
|
|
|
|
|
|
|
|
|
# Second row: next match for each court |
|
|
|
# Second row: next match for each court |
|
|
|
for court in court_group: |
|
|
|
for court in court_group: |
|
|
|
if court in matches_by_court and len(matches_by_court[court]) > 1: |
|
|
|
if court in matches_by_court and len(matches_by_court[court]) > 1: |
|
|
|
ordered_matches.append(matches_by_court[court][1]) |
|
|
|
ordered_matches.append(matches_by_court[court][1]) |
|
|
|
else: |
|
|
|
else: |
|
|
|
ordered_matches.append(None) # Empty space |
|
|
|
ordered_matches.append({"empty": True}) |
|
|
|
|
|
|
|
# Pad to 4 courts if needed |
|
|
|
|
|
|
|
while len(ordered_matches) % 4 != 0: |
|
|
|
|
|
|
|
ordered_matches.append({"empty": True}) |
|
|
|
|
|
|
|
|
|
|
|
# Add unassigned matches at the end if needed |
|
|
|
# Add unassigned matches at the end if needed |
|
|
|
unassigned_matches = [ |
|
|
|
unassigned_matches = [ |
|
|
|
|