Compare commits

..

No commits in common. "5d67238575074f3a38f3aa0811e803152ad5bcf9" and "a62f289ce8b421243a18956894545f454c4eb367" have entirely different histories.

5 changed files with 96 additions and 146 deletions

View File

@ -1 +1 @@
0.4.0 0.3.8

View File

@ -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, TournamentFormat 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.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,17 +215,16 @@ 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", style="minor",
style="minor", color="hud",
color="hud", margin_left=4,
margin_left=4, margin_right=4,
margin_right=4, margin_top=1,
margin_top=1, on_press=self.tree_button_clicked
on_press=self.tree_button_clicked )
)
ids_of_participants = [p.id for p in self.tournament.participants] ids_of_participants = [p.id for p in self.tournament.participants]
color_key: Literal["hud", "danger"] = "hud" color_key: Literal["hud", "danger"] = "hud"

View File

@ -36,7 +36,7 @@ class MatchInfo(Component):
font_size=0.9 font_size=0.9
), ),
Text( Text(
text=f"({self.opponent_1_seat})" if self.opponent_1_seat else "Freilos", text=f"({self.opponent_1_seat})",
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})" if self.opponent_2_seat else "Freilos", text=f"({self.opponent_2_seat})",
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
@ -164,10 +164,89 @@ class TournamentTreePage(Component):
) )
) )
else: else:
if self.tournament.format == TournamentFormat.FFA: try:
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])
logger.info(f"Trying to read tournament data from {file_name}")
with open(from_root("tournament_data", file_name), "r") as f:
json_data = json.load(f)
last_valid_round = None
round_num = 0
for round_ in json_data["rounds"]:
if all(
match["opponent_1_id"] is not None and match["opponent_2_id"] is not None
for match in round_
):
last_valid_round = round_
round_num += 1
if last_valid_round is None:
raise ValueError
match_infos = []
if self.tournament.participant_type == ParticipantType.PLAYER:
match_infos = [MatchInfo(
opponent_1=self.id_to_username_map.get(match["opponent_1_id"], ""),
opponent_2=self.id_to_username_map.get(match["opponent_2_id"], ""),
winner=self.id_to_username_map.get(match["winner"], ""),
opponent_1_seat=self.id_to_seat_map.get(match["opponent_1_id"], ""),
opponent_2_seat=self.id_to_seat_map.get(match["opponent_2_id"], ""),
) for match in last_valid_round]
elif self.tournament.participant_type == ParticipantType.TEAM:
for match in last_valid_round:
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)
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(
MatchInfo(
opponent_1=team_1.name,
opponent_2=team_2.name,
winner=winner if isinstance(winner, str) else winner.name,
opponent_1_seat=self._get_seat_for_team(team_1),
opponent_2_seat=self._get_seat_for_team(team_2),
)
)
else:
raise ValueError("Unknown participant type")
content = Column( content = Column(
Text( Text(
text=f"Dieses Turnier hat keinen Turnierbaum.", text=f"{self.tournament.name}",
style=TextStyle(fill=self.session.theme.background_color),
justify="center",
font_size=1.2
),
Text(
text="Finale" if len(json_data["rounds"]) == round_num else f"Runde {round_num}",
style=TextStyle(fill=self.session.theme.background_color),
justify="center",
font_size=0.9,
margin_bottom=1
),
Text(
text=f"Spiele pro Matchup: {games_per_matchup}",
style=TextStyle(fill=self.session.theme.background_color),
justify="center",
font_size=0.8
),
Text(
text=f"Melde als Verlierer deinen Matchausgang\nim Discord oder an der Orga-Ecke",
style=TextStyle(fill=self.session.theme.background_color),
justify="center",
font_size=0.8
),
*match_infos
)
except (FileNotFoundError, ValueError, AttributeError):
content = Column(
Text(
text=f"Der Turnierbaum für dieses Turnier steht leider nicht zur Verfügung.\n\nBitte melde sich beim Orga-Team.",
style=TextStyle(fill=self.session.theme.background_color), style=TextStyle(fill=self.session.theme.background_color),
margin_top=1, margin_top=1,
margin_bottom=1, margin_bottom=1,
@ -177,96 +256,6 @@ class TournamentTreePage(Component):
justify="center" justify="center"
) )
) )
else:
try:
file_name = self.tournament.name.replace(" ", "_") + ".json"
games_per_matchup = int(self.tournament.format.name[-1])
logger.info(f"Trying to read tournament data from {file_name}")
with open(from_root("tournament_data", file_name), "r") as f:
json_data = json.load(f)
last_valid_round = None
round_num = 0
for round_ in json_data["rounds"]:
if all(
match["opponent_1_id"] is not None or match["opponent_2_id"] is not None
for match in round_
):
last_valid_round = round_
round_num += 1
if last_valid_round is None:
last_valid_round = json_data["rounds"][0]
match_infos = []
if self.tournament.participant_type == ParticipantType.PLAYER:
match_infos = [MatchInfo(
opponent_1=self.id_to_username_map.get(match["opponent_1_id"], ""),
opponent_2=self.id_to_username_map.get(match["opponent_2_id"], ""),
winner=self.id_to_username_map.get(match["winner"], ""),
opponent_1_seat=self.id_to_seat_map.get(match["opponent_1_id"], ""),
opponent_2_seat=self.id_to_seat_map.get(match["opponent_2_id"], ""),
) for match in last_valid_round]
elif self.tournament.participant_type == ParticipantType.TEAM:
for match in last_valid_round:
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)
winner: Union[str, Team] = next(filter(lambda t: t.id == match["winner"], self.teams), "")
match_infos.append(
MatchInfo(
opponent_1=team_1.name if team_1 is not None else "",
opponent_2=team_2.name if team_2 is not None else "",
winner=winner if isinstance(winner, str) else winner.name,
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) if team_2 is not None else "",
)
)
else:
raise ValueError("Unknown participant type")
content = Column(
Text(
text=f"{self.tournament.name}",
style=TextStyle(fill=self.session.theme.background_color),
justify="center",
font_size=1.2
),
Text(
text="Finale" if len(json_data["rounds"]) == round_num else f"Runde {round_num}",
style=TextStyle(fill=self.session.theme.background_color),
justify="center",
font_size=0.9,
margin_bottom=1
),
Text(
text=f"Spiele pro Matchup: {games_per_matchup}",
style=TextStyle(fill=self.session.theme.background_color),
justify="center",
font_size=0.8
),
Text(
text=f"Melde als Verlierer deinen Matchausgang\nim Discord oder an der Orga-Ecke",
style=TextStyle(fill=self.session.theme.background_color),
justify="center",
font_size=0.8
),
*match_infos
)
except (FileNotFoundError, ValueError, AttributeError):
content = Column(
Text(
text=f"Der Turnierbaum für dieses Turnier steht leider nicht zur Verfügung.\n\nBitte melde sich beim Orga-Team.",
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"
)
)
return Column( return Column(
MainViewContentBox( MainViewContentBox(

View File

@ -1,9 +1,5 @@
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
@ -94,7 +90,6 @@ 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
@ -104,37 +99,3 @@ 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

View File

@ -356,6 +356,7 @@ 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()