Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/bracket/logic/ranking/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
D = 400


def match_has_result(match: MatchWithDetailsDefinitive) -> bool:
return not (match.stage_item_input1_score == 0 and match.stage_item_input2_score == 0)


def set_statistics_for_stage_item_input(
team_index: int,
stats: defaultdict[StageItemInputId, TeamStatistics],
Expand Down Expand Up @@ -76,6 +80,7 @@ def determine_ranking_for_stage_item(
if not round_.is_draft
for match in round_.matches
if isinstance(match, MatchWithDetailsDefinitive)
if match_has_result(match)
]
for match in matches:
for team_index, stage_item_input in enumerate(match.stage_item_inputs):
Expand Down
85 changes: 85 additions & 0 deletions backend/tests/unit_tests/ranking_calculation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,91 @@ def test_determine_ranking_for_stage_item_elimination() -> None:
}


def test_determine_ranking_for_stage_item_round_robin_ignores_unplayed_match() -> None:
tournament_id = TournamentId(-1)
now = datetime_utc.now()
stage_item_input1 = StageItemInputFinal(
id=StageItemInputId(-1),
team_id=TeamId(-1),
slot=1,
tournament_id=tournament_id,
team=Team(**DUMMY_TEAM1.model_dump(), id=TeamId(-1)),
)
stage_item_input2 = StageItemInputFinal(
id=StageItemInputId(-2),
team_id=TeamId(-2),
slot=1,
tournament_id=tournament_id,
team=Team(**DUMMY_TEAM2.model_dump(), id=TeamId(-2)),
)

ranking = determine_ranking_for_stage_item(
StageItemWithRounds(
rounds=[
RoundWithMatches(
id=RoundId(-1),
matches=[
MatchWithDetailsDefinitive(
id=MatchId(-1),
stage_item_input1=stage_item_input1,
stage_item_input2=stage_item_input2,
created=now,
duration_minutes=90,
margin_minutes=15,
round_id=RoundId(-1),
stage_item_input1_score=0,
stage_item_input2_score=0,
stage_item_input1_conflict=False,
stage_item_input2_conflict=False,
),
MatchWithDetailsDefinitive(
id=MatchId(-2),
stage_item_input1=stage_item_input1,
stage_item_input2=stage_item_input2,
created=now,
duration_minutes=90,
margin_minutes=15,
round_id=RoundId(-1),
stage_item_input1_score=2,
stage_item_input2_score=0,
stage_item_input1_conflict=False,
stage_item_input2_conflict=False,
),
],
stage_item_id=StageItemId(-1),
created=now,
is_draft=False,
name="",
)
],
inputs=[stage_item_input1, stage_item_input2],
type_name="Round Robin",
team_count=4,
ranking_id=None,
id=StageItemId(-1),
stage_id=StageId(-1),
name="",
created=now,
type=StageType.ROUND_ROBIN,
),
Ranking(
id=RankingId(-1),
tournament_id=tournament_id,
created=now,
win_points=Decimal("3.5"),
draw_points=Decimal("1.25"),
loss_points=Decimal("0.0"),
add_score_points=False,
position=0,
),
)

assert ranking == {
-2: TeamStatistics(wins=0, draws=0, losses=1, points=Decimal("0.0")),
-1: TeamStatistics(wins=1, draws=0, losses=0, points=Decimal("3.5")),
}


def test_determine_ranking_for_stage_item_swiss() -> None:
tournament_id = TournamentId(-1)
now = datetime_utc.now()
Expand Down
Loading