Skip to content
Open
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
6 changes: 3 additions & 3 deletions backend/bracket/models/db/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MatchBaseInsertable(BaseModelORM):
court_id: CourtId | None = None
stage_item_input1_conflict: bool
stage_item_input2_conflict: bool
played: bool = False

@property
def end_time(self) -> datetime_utc:
Expand Down Expand Up @@ -60,9 +61,7 @@ class MatchWithDetails(Match):
court: Court | None = None


def get_match_hash(
stage_item_input1_id: StageItemInputId | None, stage_item_input2_id: StageItemInputId | None
) -> str:
def get_match_hash(stage_item_input1_id: StageItemInputId | None, stage_item_input2_id: StageItemInputId | None) -> str:
return f"{stage_item_input1_id}-{stage_item_input2_id}"


Expand Down Expand Up @@ -93,6 +92,7 @@ class MatchBody(BaseModelORM):
court_id: CourtId | None = None
custom_duration_minutes: int | None = None
custom_margin_minutes: int | None = None
played: bool = False


class MatchCreateBodyFrontend(BaseModelORM):
Expand Down
21 changes: 8 additions & 13 deletions backend/bracket/routes/matches.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
from fastapi import APIRouter, Depends, HTTPException
from starlette import status

from bracket.logger import get_logger
from bracket.logic.planning.conflicts import handle_conflicts
from bracket.logic.planning.matches import (
get_scheduled_matches,
handle_match_reschedule,
reorder_matches_for_court,
schedule_all_unscheduled_matches,
)
from bracket.logic.ranking.calculation import (
recalculate_ranking_for_stage_item,
)
from bracket.logic.ranking.calculation import recalculate_ranking_for_stage_item
from bracket.logic.ranking.elimination import update_inputs_in_subsequent_elimination_rounds
from bracket.logic.scheduling.upcoming_matches import (
get_draft_round_in_stage_item,
get_upcoming_matches_for_swiss,
)
from bracket.logic.scheduling.upcoming_matches import get_draft_round_in_stage_item, get_upcoming_matches_for_swiss
from bracket.models.db.match import (
Match,
MatchBody,
Expand All @@ -41,6 +37,7 @@
from bracket.utils.types import assert_some

router = APIRouter()
logger = get_logger("bracket")


@router.get(
Expand Down Expand Up @@ -68,9 +65,7 @@ async def get_matches_to_schedule(
if len(courts) <= len(draft_round.matches):
return UpcomingMatchesResponse(data=[])

return UpcomingMatchesResponse(
data=get_upcoming_matches_for_swiss(match_filter, stage_item, draft_round)
)
return UpcomingMatchesResponse(data=get_upcoming_matches_for_swiss(match_filter, stage_item, draft_round))


@router.delete("/tournaments/{tournament_id}/matches/{match_id}", response_model=SuccessResponse)
Expand Down Expand Up @@ -136,9 +131,7 @@ async def schedule_matches(
return SuccessResponse()


@router.post(
"/tournaments/{tournament_id}/matches/{match_id}/reschedule", response_model=SuccessResponse
)
@router.post("/tournaments/{tournament_id}/matches/{match_id}/reschedule", response_model=SuccessResponse)
async def reschedule_match(
tournament_id: TournamentId,
match_id: MatchId,
Expand All @@ -164,6 +157,8 @@ async def update_match_by_id(
await check_foreign_keys_belong_to_tournament(match_body, tournament_id)
tournament = await sql_get_tournament(tournament_id)

logger.info(f"Updating match {match_id} with body: {match_body.model_dump()}")

await sql_update_match(match_id, match_body, tournament)

round_ = await get_round_by_id(tournament_id, match.round_id)
Expand Down
1 change: 1 addition & 0 deletions backend/bracket/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
Column("stage_item_input1_score", Integer, nullable=False),
Column("stage_item_input2_score", Integer, nullable=False),
Column("position_in_schedule", Integer, nullable=True),
Column("played", Boolean, nullable=False),
)

teams = Table(
Expand Down
31 changes: 11 additions & 20 deletions backend/bracket/sql/matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ async def sql_create_match(match: MatchCreateBody) -> Match:
stage_item_input2_score,
stage_item_input1_conflict,
stage_item_input2_conflict,
created
created,
played
)
VALUES (
:round_id,
Expand All @@ -70,7 +71,8 @@ async def sql_create_match(match: MatchCreateBody) -> Match:
0,
false,
false,
NOW()
NOW(),
false
)
RETURNING *
"""
Expand All @@ -92,20 +94,17 @@ async def sql_update_match(match_id: MatchId, match: MatchBody, tournament: Tour
custom_duration_minutes = :custom_duration_minutes,
custom_margin_minutes = :custom_margin_minutes,
duration_minutes = :duration_minutes,
margin_minutes = :margin_minutes
margin_minutes = :margin_minutes,
played = :played
WHERE matches.id = :match_id
RETURNING *
"""

duration_minutes = (
match.custom_duration_minutes
if match.custom_duration_minutes is not None
else tournament.duration_minutes
match.custom_duration_minutes if match.custom_duration_minutes is not None else tournament.duration_minutes
)
margin_minutes = (
match.custom_margin_minutes
if match.custom_margin_minutes is not None
else tournament.margin_minutes
match.custom_margin_minutes if match.custom_margin_minutes is not None else tournament.margin_minutes
)
await database.execute(
query=query,
Expand Down Expand Up @@ -189,15 +188,9 @@ async def sql_reschedule_match_and_determine_duration_and_margin(
tournament: Tournament,
) -> None:
duration_minutes = (
tournament.duration_minutes
if match.custom_duration_minutes is None
else match.custom_duration_minutes
)
margin_minutes = (
tournament.margin_minutes
if match.custom_margin_minutes is None
else match.custom_margin_minutes
tournament.duration_minutes if match.custom_duration_minutes is None else match.custom_duration_minutes
)
margin_minutes = tournament.margin_minutes if match.custom_margin_minutes is None else match.custom_margin_minutes
await sql_reschedule_match(
match.id,
court_id,
Expand Down Expand Up @@ -226,9 +219,7 @@ async def sql_get_match(match_id: MatchId) -> Match:
return Match.model_validate(dict(result._mapping))


async def clear_scores_for_matches_in_stage_item(
tournament_id: TournamentId, stage_item_id: StageItemId
) -> None:
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,
Expand Down
4 changes: 3 additions & 1 deletion frontend/public/locales/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,7 @@
"win_distribution_text_draws": "zeichnet",
"win_distribution_text_losses": "Niederlagen",
"win_distribution_text_win": "Siege",
"win_points_input_label": "Punkte für einen Sieg"
"win_points_input_label": "Punkte für einen Sieg",
"results_tab_upcoming": "Bevorstehende Spiele",
"results_tab_past": "Vergangene Spiele"
}
4 changes: 3 additions & 1 deletion frontend/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,7 @@
"win_distribution_text_draws": "draws",
"win_distribution_text_losses": "losses",
"win_distribution_text_win": "wins",
"win_points_input_label": "Points for a win"
"win_points_input_label": "Points for a win",
"results_tab_upcoming": "Upcoming Matches",
"results_tab_past": "Past Matches"
}
1 change: 1 addition & 0 deletions frontend/src/components/dashboard/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function DoubleHeader({ tournamentData }: { tournamentData: Tournament })

const mainLinks = [
{ link: `/tournaments/${endpoint}/dashboard`, label: 'Matches' },
{ link: `/tournaments/${endpoint}/dashboard/results`, label: 'Results' },
{ link: `/tournaments/${endpoint}/dashboard/standings`, label: 'Standings' },
];

Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/modals/match_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function MatchModalForm({
court_id: match.court_id,
custom_duration_minutes: customDurationEnabled ? values.custom_duration_minutes : null,
custom_margin_minutes: customMarginEnabled ? values.custom_margin_minutes : null,
played: true,
};
await updateMatch(tournamentData.id, match.id, updatedMatch);
await swrStagesResponse.mutate();
Expand Down
1 change: 1 addition & 0 deletions frontend/src/interfaces/match.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface MatchBodyInterface {
court_id: number | null;
custom_duration_minutes: number | null;
custom_margin_minutes: number | null;
played: boolean;
}

export interface MatchRescheduleInterface {
Expand Down
15 changes: 1 addition & 14 deletions frontend/src/pages/tournaments/[id]/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export function Schedule({
const matches: any[] = Object.values(matchesLookup);
const sortedMatches = matches
.filter((m1: any) => m1.match.start_time != null)
.filter((m1: any) => m1.match.played === false)
.sort(
(m1: any, m2: any) =>
compareDateTime(m1.match.start_time, m2.match.start_time) ||
Expand All @@ -143,20 +144,6 @@ export function Schedule({
for (let c = 0; c < sortedMatches.length; c += 1) {
const data = sortedMatches[c];

if (c < 1 || sortedMatches[c - 1].match.start_time) {
const startTime = formatTime(data.match.start_time);

if (c < 1 || startTime !== formatTime(sortedMatches[c - 1].match.start_time)) {
rows.push(
<Center mt="md" key={`time-${c}`}>
<Text size="xl" fw={800}>
{startTime}
</Text>
</Center>
);
}
}

rows.push(
<ScheduleRow
key={data.match.id}
Expand Down
Loading