Compare commits
5 Commits
a62f289ce8
...
5d67238575
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d67238575 | ||
|
|
fb5a5b0608 | ||
|
|
c0e39a2beb | ||
|
|
b071c30ce0 | ||
|
|
db237b3535 |
@ -13,7 +13,7 @@ from src.ezgg_lan_manager.components.TournamentDetailsInfoRow import TournamentD
|
|||||||
from src.ezgg_lan_manager.types.DateUtil import weekday_to_display_text
|
from src.ezgg_lan_manager.types.DateUtil import weekday_to_display_text
|
||||||
from src.ezgg_lan_manager.types.Team import Team, TeamStatus
|
from src.ezgg_lan_manager.types.Team import Team, TeamStatus
|
||||||
from src.ezgg_lan_manager.types.Tournament import Tournament
|
from src.ezgg_lan_manager.types.Tournament import Tournament
|
||||||
from src.ezgg_lan_manager.types.TournamentBase import TournamentStatus, tournament_status_to_display_text, tournament_format_to_display_texts, ParticipantType
|
from src.ezgg_lan_manager.types.TournamentBase import TournamentStatus, tournament_status_to_display_text, tournament_format_to_display_texts, ParticipantType, TournamentFormat
|
||||||
from src.ezgg_lan_manager.types.User import User
|
from src.ezgg_lan_manager.types.User import User
|
||||||
from src.ezgg_lan_manager.types.UserSession import UserSession
|
from src.ezgg_lan_manager.types.UserSession import UserSession
|
||||||
|
|
||||||
@ -215,6 +215,7 @@ class TournamentDetailsPage(Component):
|
|||||||
tournament_status_color = self.session.theme.danger_color
|
tournament_status_color = self.session.theme.danger_color
|
||||||
elif self.tournament.status == TournamentStatus.ONGOING or self.tournament.status == TournamentStatus.COMPLETED:
|
elif self.tournament.status == TournamentStatus.ONGOING or self.tournament.status == TournamentStatus.COMPLETED:
|
||||||
tournament_status_color = self.session.theme.warning_color
|
tournament_status_color = self.session.theme.warning_color
|
||||||
|
if self.tournament.format != TournamentFormat.FFA:
|
||||||
tree_button = Button(
|
tree_button = Button(
|
||||||
content="Turnierbaum anzeigen",
|
content="Turnierbaum anzeigen",
|
||||||
shape="rectangle",
|
shape="rectangle",
|
||||||
|
|||||||
@ -36,7 +36,7 @@ class MatchInfo(Component):
|
|||||||
font_size=0.9
|
font_size=0.9
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
text=f"({self.opponent_1_seat})",
|
text=f"({self.opponent_1_seat})" if self.opponent_1_seat else "Freilos",
|
||||||
style=TextStyle(fill=self.session.theme.background_color),
|
style=TextStyle(fill=self.session.theme.background_color),
|
||||||
justify="left",
|
justify="left",
|
||||||
font_size=0.9
|
font_size=0.9
|
||||||
@ -52,7 +52,7 @@ class MatchInfo(Component):
|
|||||||
font_size=0.9
|
font_size=0.9
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
text=f"({self.opponent_2_seat})",
|
text=f"({self.opponent_2_seat})" if self.opponent_2_seat else "Freilos",
|
||||||
style=TextStyle(fill=self.session.theme.background_color),
|
style=TextStyle(fill=self.session.theme.background_color),
|
||||||
justify="right",
|
justify="right",
|
||||||
font_size=0.9
|
font_size=0.9
|
||||||
@ -163,11 +163,23 @@ class TournamentTreePage(Component):
|
|||||||
align_x=0.5
|
align_x=0.5
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
if self.tournament.format == TournamentFormat.FFA:
|
||||||
|
content = Column(
|
||||||
|
Text(
|
||||||
|
text=f"Dieses Turnier hat keinen Turnierbaum.",
|
||||||
|
style=TextStyle(fill=self.session.theme.background_color),
|
||||||
|
margin_top=1,
|
||||||
|
margin_bottom=1,
|
||||||
|
align_x=0.5,
|
||||||
|
overflow="wrap",
|
||||||
|
min_width=30,
|
||||||
|
justify="center"
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
file_name = self.tournament.name.replace(" ", "_") + ".json"
|
file_name = self.tournament.name.replace(" ", "_") + ".json"
|
||||||
games_per_matchup = 1
|
|
||||||
if self.tournament.format != TournamentFormat.FFA:
|
|
||||||
games_per_matchup = int(self.tournament.format.name[-1])
|
games_per_matchup = int(self.tournament.format.name[-1])
|
||||||
logger.info(f"Trying to read tournament data from {file_name}")
|
logger.info(f"Trying to read tournament data from {file_name}")
|
||||||
with open(from_root("tournament_data", file_name), "r") as f:
|
with open(from_root("tournament_data", file_name), "r") as f:
|
||||||
@ -177,14 +189,14 @@ class TournamentTreePage(Component):
|
|||||||
round_num = 0
|
round_num = 0
|
||||||
for round_ in json_data["rounds"]:
|
for round_ in json_data["rounds"]:
|
||||||
if all(
|
if all(
|
||||||
match["opponent_1_id"] is not None and match["opponent_2_id"] is not None
|
match["opponent_1_id"] is not None or match["opponent_2_id"] is not None
|
||||||
for match in round_
|
for match in round_
|
||||||
):
|
):
|
||||||
last_valid_round = round_
|
last_valid_round = round_
|
||||||
round_num += 1
|
round_num += 1
|
||||||
|
|
||||||
if last_valid_round is None:
|
if last_valid_round is None:
|
||||||
raise ValueError
|
last_valid_round = json_data["rounds"][0]
|
||||||
|
|
||||||
match_infos = []
|
match_infos = []
|
||||||
if self.tournament.participant_type == ParticipantType.PLAYER:
|
if self.tournament.participant_type == ParticipantType.PLAYER:
|
||||||
@ -200,14 +212,13 @@ class TournamentTreePage(Component):
|
|||||||
team_1: Optional[Team] = next(filter(lambda t: t.id == match["opponent_1_id"], self.teams), None)
|
team_1: Optional[Team] = next(filter(lambda t: t.id == match["opponent_1_id"], self.teams), None)
|
||||||
team_2: Optional[Team] = next(filter(lambda t: t.id == match["opponent_2_id"], self.teams), None)
|
team_2: Optional[Team] = next(filter(lambda t: t.id == match["opponent_2_id"], self.teams), None)
|
||||||
winner: Union[str, Team] = next(filter(lambda t: t.id == match["winner"], self.teams), "")
|
winner: Union[str, Team] = next(filter(lambda t: t.id == match["winner"], self.teams), "")
|
||||||
if team_1 is not None and team_2 is not None:
|
|
||||||
match_infos.append(
|
match_infos.append(
|
||||||
MatchInfo(
|
MatchInfo(
|
||||||
opponent_1=team_1.name,
|
opponent_1=team_1.name if team_1 is not None else "",
|
||||||
opponent_2=team_2.name,
|
opponent_2=team_2.name if team_2 is not None else "",
|
||||||
winner=winner if isinstance(winner, str) else winner.name,
|
winner=winner if isinstance(winner, str) else winner.name,
|
||||||
opponent_1_seat=self._get_seat_for_team(team_1),
|
opponent_1_seat=self._get_seat_for_team(team_1) if team_1 is not None else "",
|
||||||
opponent_2_seat=self._get_seat_for_team(team_2),
|
opponent_2_seat=self._get_seat_for_team(team_2) if team_2 is not None else "",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
|
import json
|
||||||
|
from pprint import pprint
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from from_root import from_root
|
||||||
|
|
||||||
from src.ezgg_lan_manager.services.DatabaseService import DatabaseService
|
from src.ezgg_lan_manager.services.DatabaseService import DatabaseService
|
||||||
from src.ezgg_lan_manager.services.UserService import UserService
|
from src.ezgg_lan_manager.services.UserService import UserService
|
||||||
from src.ezgg_lan_manager.types.Participant import Participant
|
from src.ezgg_lan_manager.types.Participant import Participant
|
||||||
@ -90,6 +94,7 @@ class TournamentService:
|
|||||||
tournament = await self.get_tournament_by_id(tournament_id)
|
tournament = await self.get_tournament_by_id(tournament_id)
|
||||||
if tournament:
|
if tournament:
|
||||||
tournament.start()
|
tournament.start()
|
||||||
|
await self._generate_initial_json_file(tournament)
|
||||||
await self._db_service.change_tournament_status(tournament_id, tournament.status)
|
await self._db_service.change_tournament_status(tournament_id, tournament.status)
|
||||||
self._cache_dirty = True
|
self._cache_dirty = True
|
||||||
|
|
||||||
@ -99,3 +104,37 @@ class TournamentService:
|
|||||||
tournament.cancel()
|
tournament.cancel()
|
||||||
await self._db_service.change_tournament_status(tournament_id, tournament.status)
|
await self._db_service.change_tournament_status(tournament_id, tournament.status)
|
||||||
self._cache_dirty = True
|
self._cache_dirty = True
|
||||||
|
|
||||||
|
async def _generate_initial_json_file(self, tournament: Tournament) -> None:
|
||||||
|
"""
|
||||||
|
Generates the initial JSON file for the tournament. Won't generate a new one if one already exists.
|
||||||
|
ToDo: Remove this method when final tournament system is completed.
|
||||||
|
"""
|
||||||
|
p = tournament.participants
|
||||||
|
pairs = [
|
||||||
|
(p[i], p[i + 1]) if i + 1 < len(p) else (p[i], None)
|
||||||
|
for i in range(0, len(p), 2)
|
||||||
|
]
|
||||||
|
data = {
|
||||||
|
"rounds": [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"opponent_1_id": pair[0].id if pair[0] is not None else None,
|
||||||
|
"opponent_2_id": pair[1].id if pair[1] is not None else None,
|
||||||
|
"winner": None
|
||||||
|
} for pair in pairs
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Resolve byes
|
||||||
|
for match in data["rounds"][0]:
|
||||||
|
if match["opponent_2_id"] is None:
|
||||||
|
match["winner"] = match["opponent_1_id"]
|
||||||
|
|
||||||
|
file_name = tournament.name.replace(" ", "_") + ".json"
|
||||||
|
try:
|
||||||
|
with open(from_root("tournament_data", file_name), "x") as f:
|
||||||
|
json.dump(data, f, indent=4)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
|||||||
@ -356,7 +356,6 @@ class Tournament:
|
|||||||
|
|
||||||
self._status = TournamentStatus.ONGOING
|
self._status = TournamentStatus.ONGOING
|
||||||
logger.info(f"New tournament status for {self._name}: {self._status}")
|
logger.info(f"New tournament status for {self._name}: {self._status}")
|
||||||
print(self._matches, self._rounds)
|
|
||||||
for match in self._matches:
|
for match in self._matches:
|
||||||
match.check_completion()
|
match.check_completion()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user