mirror of
https://github.com/evroon/bracket.git
synced 2026-01-17 18:48:30 -05:00
Discard match results when activating previous stage (#995)
This commit is contained in:
@@ -9,6 +9,7 @@ from bracket.logic.ranking.statistics import TeamStatistics
|
||||
from bracket.models.db.stage_item_inputs import StageItemInputFinal, StageItemInputTentative
|
||||
from bracket.models.db.team import Team
|
||||
from bracket.models.db.util import StageWithStageItems
|
||||
from bracket.sql.matches import clear_scores_for_matches_in_stage_item
|
||||
from bracket.sql.rankings import get_ranking_for_stage_item
|
||||
from bracket.sql.stage_item_inputs import (
|
||||
get_stage_item_input_by_id,
|
||||
@@ -131,6 +132,8 @@ async def update_matches_in_deactivated_stage(
|
||||
Unsets the team_id for stage item inputs of the newly deactivated stage.
|
||||
"""
|
||||
for stage_item in deactivated_stage.stage_items:
|
||||
await clear_scores_for_matches_in_stage_item(tournament_id, stage_item.id)
|
||||
|
||||
for stage_item_input in stage_item.inputs:
|
||||
if stage_item_input.winner_from_stage_item_id is not None:
|
||||
await sql_set_team_id_for_stage_item_input(tournament_id, stage_item_input.id, None)
|
||||
|
||||
@@ -5,7 +5,7 @@ from heliclockter import datetime_utc
|
||||
from bracket.database import database
|
||||
from bracket.models.db.match import Match, MatchBody, MatchCreateBody
|
||||
from bracket.models.db.tournament import Tournament
|
||||
from bracket.utils.id_types import CourtId, MatchId, StageItemId
|
||||
from bracket.utils.id_types import CourtId, MatchId, StageItemId, TournamentId
|
||||
|
||||
|
||||
async def sql_delete_match(match_id: MatchId) -> None:
|
||||
@@ -197,3 +197,26 @@ async def sql_get_match(match_id: MatchId) -> Match:
|
||||
raise ValueError("Could not create stage")
|
||||
|
||||
return Match.model_validate(dict(result._mapping))
|
||||
|
||||
|
||||
async def clear_scores_for_matches_in_stage_item(
|
||||
tournament_id: TournamentId, stage_item_id: StageItemId
|
||||
) -> None:
|
||||
query = """
|
||||
UPDATE matches
|
||||
SET stage_item_input1_score = 0,
|
||||
stage_item_input2_score = 0
|
||||
FROM rounds
|
||||
JOIN stage_items ON rounds.stage_item_id = stage_items.id
|
||||
JOIN stages ON stages.id = stage_items.stage_id
|
||||
WHERE rounds.id = matches.round_id
|
||||
AND stages.tournament_id = :tournament_id
|
||||
AND stage_items.id = :stage_item_id
|
||||
"""
|
||||
await database.execute(
|
||||
query=query,
|
||||
values={
|
||||
"stage_item_id": stage_item_id,
|
||||
"tournament_id": tournament_id,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user