Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set random scores for dummy matches #500

Merged
merged 2 commits into from
Feb 21, 2024
Merged
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
24 changes: 23 additions & 1 deletion backend/bracket/utils/db_init.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
from typing import TYPE_CHECKING, Any

from heliclockter import datetime_utc
Expand All @@ -9,7 +10,7 @@
from bracket.models.db.account import UserAccountType
from bracket.models.db.club import Club
from bracket.models.db.court import Court
from bracket.models.db.match import Match
from bracket.models.db.match import Match, MatchBody
from bracket.models.db.player import Player
from bracket.models.db.player_x_team import PlayerXTeam
from bracket.models.db.round import Round
Expand Down Expand Up @@ -38,7 +39,10 @@
users,
users_x_clubs,
)
from bracket.sql.matches import sql_update_match
from bracket.sql.stage_items import sql_create_stage_item
from bracket.sql.stages import get_full_tournament_details
from bracket.sql.tournaments import sql_get_tournament
from bracket.sql.users import create_user, get_user
from bracket.utils.db import insert_generic
from bracket.utils.dummy_records import (
Expand Down Expand Up @@ -319,6 +323,24 @@ async def insert_dummy(obj_to_insert: BaseModelT, update_data: dict[str, Any] =
await build_matches_for_stage_item(stage_item_2, tournament_id_1)
await build_matches_for_stage_item(stage_item_3, tournament_id_1)

tournament_details = await sql_get_tournament(tournament_id_1)

for stage in await get_full_tournament_details(tournament_id_1):
for stage_item in stage.stage_items:
for round_ in stage_item.rounds:
for match in round_.matches:
await sql_update_match(
match_id=assert_some(match.id),
match=MatchBody.model_validate(
{
**match.model_dump(),
"team1_score": random.randint(0, 10),
"team2_score": random.randint(0, 10),
}
),
tournament=tournament_details,
)

for tournament in await database.fetch_all(tournaments.select()):
await recalculate_ranking_for_tournament_id(tournament.id) # type: ignore[attr-defined]

Expand Down