Skip to content

Commit

Permalink
fixup! fixup! Assign teams to subsequent elimination rounds
Browse files Browse the repository at this point in the history
  • Loading branch information
evroon committed Nov 8, 2024
1 parent 2116e3d commit 193237e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
14 changes: 8 additions & 6 deletions backend/bracket/logic/ranking/elimination.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TypeVar

from bracket.logic.ranking.statistics import START_ELO, TeamStatistics
from bracket.models.db.match import MatchWithDetailsDefinitive
from bracket.models.db.match import MatchWithDetails, MatchWithDetailsDefinitive
from bracket.models.db.ranking import Ranking
from bracket.models.db.stage_item import StageType
from bracket.models.db.util import RoundWithMatches, StageItemWithRounds
Expand Down Expand Up @@ -120,12 +120,11 @@ async def update_teams_in_subsequent_elimination_rounds(
updated_input_ids = [match.stage_item_input1_id, match.stage_item_input2_id]

Check warning on line 120 in backend/bracket/logic/ranking/elimination.py

View check run for this annotation

Codecov / codecov/patch

backend/bracket/logic/ranking/elimination.py#L118-L120

Added lines #L118 - L120 were not covered by tests

if match.stage_item_input1_winner_from_match_id in affected_match_ids:
referenced_match: MatchWithDetailsDefinitive | None = next(
referenced_match: MatchWithDetailsDefinitive | MatchWithDetails | None = next(

Check warning on line 123 in backend/bracket/logic/ranking/elimination.py

View check run for this annotation

Codecov / codecov/patch

backend/bracket/logic/ranking/elimination.py#L122-L123

Added lines #L122 - L123 were not covered by tests
(
earlier_match
for earlier_match in current_round.matches
if isinstance(earlier_match, MatchWithDetailsDefinitive)
and match.stage_item_input1_winner_from_match_id == earlier_match.id
if match.stage_item_input1_winner_from_match_id == earlier_match.id
),
None,
)
Expand All @@ -138,8 +137,7 @@ async def update_teams_in_subsequent_elimination_rounds(
(
earlier_match
for earlier_match in current_round.matches
if isinstance(earlier_match, MatchWithDetailsDefinitive)
and match.stage_item_input2_winner_from_match_id == earlier_match.id
if match.stage_item_input2_winner_from_match_id == earlier_match.id
),
None,
)
Expand All @@ -148,3 +146,7 @@ async def update_teams_in_subsequent_elimination_rounds(
updated_input_ids[1] = winner.id if winner is not None else None

Check warning on line 146 in backend/bracket/logic/ranking/elimination.py

View check run for this annotation

Codecov / codecov/patch

backend/bracket/logic/ranking/elimination.py#L144-L146

Added lines #L144 - L146 were not covered by tests

await sql_set_input_id_for_match_winner_input(round_.id, match.id, updated_input_ids)

Check warning on line 148 in backend/bracket/logic/ranking/elimination.py

View check run for this annotation

Codecov / codecov/patch

backend/bracket/logic/ranking/elimination.py#L148

Added line #L148 was not covered by tests

# Matches from this round also affect matches of the next round
for match in round_.matches:
affected_match_ids.add(match.id)

Check warning on line 152 in backend/bracket/logic/ranking/elimination.py

View check run for this annotation

Codecov / codecov/patch

backend/bracket/logic/ranking/elimination.py#L151-L152

Added lines #L151 - L152 were not covered by tests
20 changes: 10 additions & 10 deletions backend/bracket/models/db/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,23 @@ class MatchInsertable(MatchBaseInsertable):

class Match(MatchInsertable):
id: MatchId
stage_item_input1: StageItemInput | None = None
stage_item_input2: StageItemInput | None = None

def get_winner(self) -> StageItemInput | None:
if self.stage_item_input1_score > self.stage_item_input2_score:
return self.stage_item_input1
if self.stage_item_input1_score < self.stage_item_input2_score:
return self.stage_item_input2

Check warning on line 50 in backend/bracket/models/db/match.py

View check run for this annotation

Codecov / codecov/patch

backend/bracket/models/db/match.py#L47-L50

Added lines #L47 - L50 were not covered by tests

return None

Check warning on line 52 in backend/bracket/models/db/match.py

View check run for this annotation

Codecov / codecov/patch

backend/bracket/models/db/match.py#L52

Added line #L52 was not covered by tests


class MatchWithDetails(Match):
"""
MatchWithDetails has zero or one defined stage item inputs, but not both.
"""

stage_item_input1: StageItemInput | None = None
stage_item_input2: StageItemInput | None = None
court: Court | None = None


Expand Down Expand Up @@ -77,14 +85,6 @@ def get_input_ids_hashes(self) -> list[str]:
get_match_hash(self.stage_item_input2_id, self.stage_item_input1_id),
]

def get_winner(self) -> StageItemInput | None:
if self.stage_item_input1_score > self.stage_item_input2_score:
return self.stage_item_input1
if self.stage_item_input1_score < self.stage_item_input2_score:
return self.stage_item_input2

return None


class MatchBody(BaseModelORM):
round_id: RoundId
Expand Down

0 comments on commit 193237e

Please sign in to comment.