General clean-up
This commit is contained in:
@@ -168,6 +168,8 @@ class BracketGenerator:
|
||||
self.match_counter += 1
|
||||
gf.next_loss = reset
|
||||
gf.next_loss_slot = 0
|
||||
gf.next_win = reset
|
||||
gf.next_win_slot = 1
|
||||
|
||||
def _resolve_byes(self, num_players: int) -> None:
|
||||
"""
|
||||
|
||||
+24
-8
@@ -6,7 +6,7 @@ from uuid import uuid4
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from . import models
|
||||
from .constants import MatchStatus, TournamentTypes
|
||||
from .constants import BracketTypes, MatchStatus, TournamentTypes
|
||||
from .core.brackets import BracketGenerator
|
||||
|
||||
|
||||
@@ -181,6 +181,25 @@ def advance_winner(db: Session, match: models.Match, winner_id: int):
|
||||
|
||||
loser_id = match.p1_team_id if match.p1_team_id != winner_id else match.p2_team_id
|
||||
|
||||
if (
|
||||
match.bracket_type == BracketTypes.FINALS
|
||||
and match.winner_next_match
|
||||
and match.winner_next_match.bracket_type == BracketTypes.FINALS
|
||||
):
|
||||
if winner_id == match.p1_team_id:
|
||||
reset_match = match.winner_next_match
|
||||
if reset_match.winner_team_id:
|
||||
undo_advancement(db, reset_match)
|
||||
reset_match.winner_team_id = None
|
||||
reset_match.sets = []
|
||||
reset_match.p1_team_id = None
|
||||
reset_match.p2_team_id = None
|
||||
reset_match.status = MatchStatus.SCHEDULED
|
||||
|
||||
db.add(reset_match)
|
||||
db.commit()
|
||||
return
|
||||
|
||||
def update_next_match(
|
||||
next_match: models.Match, team_id: int, target_slot: int | None
|
||||
):
|
||||
@@ -214,9 +233,7 @@ def undo_advancement(db: Session, match: models.Match):
|
||||
winner_id = match.winner_team_id
|
||||
loser_id = match.p1_team_id if match.p1_team_id != winner_id else match.p2_team_id
|
||||
|
||||
def clear_from_next(
|
||||
next_match: models.Match, team_id: int, target_slot: int | None
|
||||
):
|
||||
def clear_from_next(next_match: models.Match, target_slot: int | None):
|
||||
if not next_match or target_slot is None:
|
||||
return
|
||||
|
||||
@@ -230,11 +247,10 @@ def undo_advancement(db: Session, match: models.Match):
|
||||
elif target_slot == 1:
|
||||
next_match.p2_team_id = None
|
||||
|
||||
if next_match.status == MatchStatus.PENDING:
|
||||
next_match.status = MatchStatus.SCHEDULED
|
||||
next_match.status = MatchStatus.SCHEDULED
|
||||
|
||||
db.add(next_match)
|
||||
|
||||
clear_from_next(match.winner_next_match, winner_id, match.winner_next_match_slot)
|
||||
clear_from_next(match.winner_next_match, match.winner_next_match_slot)
|
||||
if match.loser_next_match and loser_id:
|
||||
clear_from_next(match.loser_next_match, loser_id, match.loser_next_match_slot)
|
||||
clear_from_next(match.loser_next_match, match.loser_next_match_slot)
|
||||
|
||||
Reference in New Issue
Block a user