1 Commits

Author SHA1 Message Date
David Rodenkirchen e92dc25ade wip / do not merge 2026-04-16 07:26:50 +02:00
24 changed files with 76 additions and 479 deletions
+1 -1
View File
@@ -1 +1 @@
0.3.8 0.3.6
BIN
View File
Binary file not shown.
+13 -23
View File
@@ -1,14 +1,14 @@
import logging import logging
from uuid import uuid4
import sys import sys
from pathlib import Path from pathlib import Path
from uuid import uuid4
from rio import App, Theme, Color, Font, ComponentPage, Session from rio import App, Theme, Color, Font, ComponentPage, Session
from from_root import from_root from from_root import from_root
from src.ezgg_lan_manager import pages, init_services, LocalDataService, RefreshService from src.ezgg_lan_manager import pages, init_services, LocalDataService
from src.ezgg_lan_manager.helpers.LoggedInGuard import logged_in_guard, not_logged_in_guard, team_guard from src.ezgg_lan_manager.helpers.LoggedInGuard import logged_in_guard, not_logged_in_guard, team_guard
from src.ezgg_lan_manager.services.LocalDataService import LocalData from src.ezgg_lan_manager.services.LocalDataService import LocalData
from src.ezgg_lan_manager.types.UserSession import UserSession from src.ezgg_lan_manager.types.UserSession import UserSession
@@ -27,7 +27,10 @@ if __name__ == "__main__":
corner_radius_small=0, corner_radius_small=0,
corner_radius_medium=0, corner_radius_medium=0,
corner_radius_large=0, corner_radius_large=0,
font=Font(from_root("src/ezgg_lan_manager/assets/fonts/joystix.otf")) font=Font(
regular=from_root("src/ezgg_lan_manager/assets/fonts/PixelOperatorMono.ttf"),
bold=from_root("src/ezgg_lan_manager/assets/fonts/PixelOperatorMono-Bold.ttf"),
)
) )
default_attachments: list = [LocalData(stored_session_token=None)] default_attachments: list = [LocalData(stored_session_token=None)]
default_attachments.extend(init_services()) default_attachments.extend(init_services())
@@ -36,13 +39,12 @@ if __name__ == "__main__":
async def on_session_start(session: Session) -> None: async def on_session_start(session: Session) -> None:
# Use this line to fake being any user without having to log in # Use this line to fake being any user without having to log in
session.attach(UserSession(id=uuid4(), user_id=30, is_team_member=True)) # session.attach(UserSession(id=uuid4(), user_id=30, is_team_member=True))
await session.set_title(lan_info.name) await session.set_title(lan_info.name)
session.attach(RefreshService()) if session[LocalData].stored_session_token:
# if session[LocalData].stored_session_token: user_session = session[LocalDataService].verify_token(session[LocalData].stored_session_token)
# user_session = session[LocalDataService].verify_token(session[LocalData].stored_session_token) if user_session is not None:
# if user_session is not None: session.attach(user_session)
# session.attach(user_session)
async def on_app_start(a: App) -> None: async def on_app_start(a: App) -> None:
init_result = await a.default_attachments[4].init_db_pool() init_result = await a.default_attachments[4].init_db_pool()
@@ -178,11 +180,6 @@ if __name__ == "__main__":
url_segment="tournament", url_segment="tournament",
build=pages.TournamentDetailsPage, build=pages.TournamentDetailsPage,
), ),
ComponentPage(
name="TournamentTreePage",
url_segment="tournament-tree",
build=pages.TournamentTreePage,
),
ComponentPage( ComponentPage(
name="TournamentRulesPage", name="TournamentRulesPage",
url_segment="tournament-rules", url_segment="tournament-rules",
@@ -222,14 +219,7 @@ if __name__ == "__main__":
} }
) )
try: sys.exit(app.run_as_web_server(
app.run_as_web_server(
host="0.0.0.0", host="0.0.0.0",
port=8000, port=8000,
) ))
except (KeyboardInterrupt, SystemExit):
logger.info("EZGG LAN Manager was shut down.")
sys.exit(0)
except Exception as e:
logger.error(e)
sys.exit(1)
+2 -2
View File
@@ -20,7 +20,7 @@ from src.ezgg_lan_manager.services.UserService import UserService
from src.ezgg_lan_manager.types import * from src.ezgg_lan_manager.types import *
# Inits services in the correct order # Inits services in the correct order
def init_services() -> tuple[AccountingService, CateringService, ConfigurationService, DatabaseService, MailingService, NewsService, SeatingService, TicketingService, UserService, LocalDataService, ReceiptPrintingService, TournamentService, TeamService]: def init_services() -> tuple[AccountingService, CateringService, ConfigurationService, DatabaseService, MailingService, NewsService, SeatingService, TicketingService, UserService, LocalDataService, ReceiptPrintingService, TournamentService, TeamService, RefreshService]:
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
configuration_service = ConfigurationService(from_root("config.toml")) configuration_service = ConfigurationService(from_root("config.toml"))
db_service = DatabaseService(configuration_service.get_database_configuration()) db_service = DatabaseService(configuration_service.get_database_configuration())
@@ -37,4 +37,4 @@ def init_services() -> tuple[AccountingService, CateringService, ConfigurationSe
team_service = TeamService(db_service) team_service = TeamService(db_service)
refresh_service = RefreshService() refresh_service = RefreshService()
return accounting_service, catering_service, configuration_service, db_service, mailing_service, news_service, seating_service, ticketing_service, user_service, local_data_service, receipt_printing_service, tournament_service, team_service return accounting_service, catering_service, configuration_service, db_service, mailing_service, news_service, seating_service, ticketing_service, user_service, local_data_service, receipt_printing_service, tournament_service, team_service, refresh_service
@@ -47,8 +47,8 @@ class DesktopNavigation(Component):
return Card( return Card(
Column( Column(
Text(lan_info.name, align_x=0.5, margin_top=0.3, style=TextStyle(fill=self.session.theme.hud_color, font_size=1.9)), Text(lan_info.name, align_x=0.5, margin_top=0.3, style=TextStyle(fill=self.session.theme.hud_color, font_size=2.5), font_weight="bold"),
Text(f"Edition {lan_info.iteration}", align_x=0.5, style=TextStyle(fill=self.session.theme.hud_color, font_size=1.2), margin_top=0.3, margin_bottom=2), Text(f"Edition {lan_info.iteration}", align_x=0.5, style=TextStyle(fill=self.session.theme.hud_color, font_size=1.6), margin_top=0.3, margin_bottom=2, font_weight="bold"),
user_info_and_login_box, user_info_and_login_box,
*navigation, *navigation,
Text("Unsere Sponsoren", align_x=0.5, style=TextStyle(fill=self.session.theme.hud_color, font_size=0.9), margin_bottom=0.5, margin_top=1), Text("Unsere Sponsoren", align_x=0.5, style=TextStyle(fill=self.session.theme.hud_color, font_size=0.9), margin_bottom=0.5, margin_top=1),
@@ -1,7 +1,7 @@
from rio import Component, TextStyle, Color, Link, Button, Text from rio import Component, TextStyle, Color, Link, Button, Text
class DesktopNavigationButton(Component): class DesktopNavigationButton(Component):
STYLE = TextStyle(fill=Color.from_hex("02dac5"), font_size=0.9) STYLE = TextStyle(fill=Color.from_hex("02dac5"), font_size=1.2, font_weight="bold")
TEAM_STYLE = TextStyle(fill=Color.from_hex("F0EADE"), font_size=0.9) TEAM_STYLE = TextStyle(fill=Color.from_hex("F0EADE"), font_size=0.9)
label: str label: str
target_url: str target_url: str
@@ -60,15 +60,12 @@ class UserInfoBox(Component):
self.session[LocalDataService].del_session(self.session[LocalData].stored_session_token) self.session[LocalDataService].del_session(self.session[LocalData].stored_session_token)
self.session[LocalData].stored_session_token = None self.session[LocalData].stored_session_token = None
self.session.attach(self.session[LocalData]) self.session.attach(self.session[LocalData])
if self.status_change_cb is not None:
await self.status_change_cb() await self.status_change_cb()
await self.session[RefreshService].trigger_refresh() await self.session[RefreshService].trigger_refresh()
self.session.navigate_to("")
@event.on_populate @event.on_populate
async def async_init(self) -> None: async def async_init(self) -> None:
self.user = await self.session[UserService].get_user(self.user_id) self.user = await self.session[UserService].get_user(self.user_id)
if self.user is not None:
self.user_balance = await self.session[AccountingService].get_balance(self.user.user_id) self.user_balance = await self.session[AccountingService].get_balance(self.user.user_id)
self.user_ticket = await self.session[TicketingService].get_user_ticket(self.user.user_id) self.user_ticket = await self.session[TicketingService].get_user_ticket(self.user.user_id)
self.user_seat = await self.session[SeatingService].get_user_seat(self.user.user_id) self.user_seat = await self.session[SeatingService].get_user_seat(self.user.user_id)
+15 -26
View File
@@ -1,7 +1,7 @@
from decimal import Decimal from decimal import Decimal
from typing import Optional from typing import Optional
from rio import Column, Component, event, Text, TextStyle, Button, Color, Revealer, Row, ProgressCircle, Link, Image from rio import Column, Component, event, Text, TextStyle, Button, Color, Revealer, Row, ProgressCircle, Link
from src.ezgg_lan_manager import ConfigurationService, UserService, AccountingService from src.ezgg_lan_manager import ConfigurationService, UserService, AccountingService
from src.ezgg_lan_manager.components.MainViewContentBox import MainViewContentBox from src.ezgg_lan_manager.components.MainViewContentBox import MainViewContentBox
@@ -14,7 +14,6 @@ class AccountPage(Component):
user: Optional[User] = None user: Optional[User] = None
balance: Optional[Decimal] = None balance: Optional[Decimal] = None
transaction_history: list[Transaction] = list() transaction_history: list[Transaction] = list()
payment_qr_image: bytes = None
banking_info_revealer_open: bool = False banking_info_revealer_open: bool = False
paypal_info_revealer_open: bool = False paypal_info_revealer_open: bool = False
@@ -29,11 +28,6 @@ class AccountPage(Component):
self.user = await self.session[UserService].get_user(user_id) self.user = await self.session[UserService].get_user(user_id)
self.balance = await self.session[AccountingService].get_balance(user_id) self.balance = await self.session[AccountingService].get_balance(user_id)
self.transaction_history = await self.session[AccountingService].get_transaction_history(user_id) self.transaction_history = await self.session[AccountingService].get_transaction_history(user_id)
self.payment_qr_image = self.session[AccountingService].make_payment_qr_image(
"Einfach Zocken Gaming Gesellschaft",
"GENODE51BIK",
"DE47517624340019856607",
f"AUFLADUNG - {self.user.user_id} - {self.user.user_name}")
async def _on_banking_info_press(self) -> None: async def _on_banking_info_press(self) -> None:
self.banking_info_revealer_open = not self.banking_info_revealer_open self.banking_info_revealer_open = not self.banking_info_revealer_open
@@ -42,7 +36,7 @@ class AccountPage(Component):
self.paypal_info_revealer_open = not self.paypal_info_revealer_open self.paypal_info_revealer_open = not self.paypal_info_revealer_open
def build(self) -> Component: def build(self) -> Component:
if not self.user or not self.payment_qr_image: if not self.user and not self.balance:
return Column( return Column(
MainViewContentBox( MainViewContentBox(
ProgressCircle( ProgressCircle(
@@ -91,10 +85,6 @@ class AccountPage(Component):
margin=0, margin=0,
margin_bottom=1, margin_bottom=1,
align_x=0.5 align_x=0.5
),
Image(self.payment_qr_image,
min_width=20,
min_height=20
) )
), ),
margin=2, margin=2,
@@ -233,20 +223,19 @@ class AccountPage(Component):
on_press=self._on_paypal_info_press on_press=self._on_paypal_info_press
), ),
paypal_info_revealer, paypal_info_revealer,
# Disabled because people did not understand the fee's and kept charging 24.03 € to their accounts Link(
# Link( content=Button(
# content=Button( content=Text("PAYPAL (3% Gebühr - Gewerblich)", style=TextStyle(fill=Color.from_hex("121212"), font_size=0.8), justify="center"),
# content=Text("PAYPAL (3% Gebühr - Gewerblich)", style=TextStyle(fill=Color.from_hex("121212"), font_size=0.8), justify="center"), shape="rectangle",
# shape="rectangle", style="major",
# style="major", color="secondary",
# color="secondary", grow_x=True,
# grow_x=True, margin=2,
# margin=2, margin_top=0
# margin_top=0 ),
# ), target_url="https://www.paypal.com/ncp/payment/89YMGVZ4S33RS",
# target_url="https://www.paypal.com/ncp/payment/89YMGVZ4S33RS", open_in_new_tab=True
# open_in_new_tab=True )
# )
) )
), ),
MainViewContentBox( MainViewContentBox(
@@ -18,6 +18,7 @@ class CateringPage(Component):
@event.on_populate @event.on_populate
async def on_populate(self) -> None: async def on_populate(self) -> None:
self.session[RefreshService].subscribe(self.on_populate)
await self.session.set_title(f"{self.session[ConfigurationService].get_lan_info().name} - Catering") await self.session.set_title(f"{self.session[ConfigurationService].get_lan_info().name} - Catering")
self.all_menu_items = await self.session[CateringService].get_menu() self.all_menu_items = await self.session[CateringService].get_menu()
@@ -7,7 +7,7 @@ from from_root import from_root
from rio import Column, Component, event, TextStyle, Text, Row, Image, Spacer, ProgressCircle, Button, Checkbox, ThemeContextSwitcher, Link, Revealer, PointerEventListener, \ from rio import Column, Component, event, TextStyle, Text, Row, Image, Spacer, ProgressCircle, Button, Checkbox, ThemeContextSwitcher, Link, Revealer, PointerEventListener, \
PointerEvent, Rectangle, Color, Popup, Dropdown PointerEvent, Rectangle, Color, Popup, Dropdown
from src.ezgg_lan_manager import ConfigurationService, TournamentService, UserService, TicketingService, TeamService, RefreshService from src.ezgg_lan_manager import ConfigurationService, TournamentService, UserService, TicketingService, TeamService
from src.ezgg_lan_manager.components.MainViewContentBox import MainViewContentBox from src.ezgg_lan_manager.components.MainViewContentBox import MainViewContentBox
from src.ezgg_lan_manager.components.TournamentDetailsInfoRow import TournamentDetailsInfoRow from src.ezgg_lan_manager.components.TournamentDetailsInfoRow import TournamentDetailsInfoRow
from src.ezgg_lan_manager.types.DateUtil import weekday_to_display_text from src.ezgg_lan_manager.types.DateUtil import weekday_to_display_text
@@ -44,7 +44,7 @@ class TournamentDetailsPage(Component):
tournament_id = None tournament_id = None
if tournament_id is not None: if tournament_id is not None:
self.tournament = await self.session[TournamentService].get_tournament_by_id(tournament_id) self.tournament = await self.session[TournamentService].get_tournament_by_id(tournament_id)
if isinstance(self.tournament, Tournament): if self.tournament is not None:
await self.session.set_title(f"{self.session[ConfigurationService].get_lan_info().name} - {self.tournament.name}") await self.session.set_title(f"{self.session[ConfigurationService].get_lan_info().name} - {self.tournament.name}")
if self.tournament.participant_type == ParticipantType.PLAYER: if self.tournament.participant_type == ParticipantType.PLAYER:
self.current_tournament_user_or_team_list = await self.session[TournamentService].get_users_from_participant_list(self.tournament.participants) self.current_tournament_user_or_team_list = await self.session[TournamentService].get_users_from_participant_list(self.tournament.participants)
@@ -61,8 +61,6 @@ class TournamentDetailsPage(Component):
self.user = None self.user = None
self.user_teams = [] self.user_teams = []
self.session[RefreshService].subscribe(self.on_populate)
self.loading_done() self.loading_done()
@staticmethod @staticmethod
@@ -70,9 +68,8 @@ class TournamentDetailsPage(Component):
await sleep(0.8) # https://medium.com/design-bootcamp/ux-psychology-of-artificial-waiting-enhancing-user-experiences-through-deliberate-delays-d7822faf3930 await sleep(0.8) # https://medium.com/design-bootcamp/ux-psychology-of-artificial-waiting-enhancing-user-experiences-through-deliberate-delays-d7822faf3930
async def update(self) -> None: async def update(self) -> None:
if isinstance(self.tournament, Tournament):
self.tournament = await self.session[TournamentService].get_tournament_by_id(self.tournament.id) self.tournament = await self.session[TournamentService].get_tournament_by_id(self.tournament.id)
if self.tournament is None or isinstance(self.tournament, str): if self.tournament is None:
return return
if self.tournament.participant_type == ParticipantType.PLAYER: if self.tournament.participant_type == ParticipantType.PLAYER:
self.current_tournament_user_or_team_list = await self.session[TournamentService].get_users_from_participant_list(self.tournament.participants) self.current_tournament_user_or_team_list = await self.session[TournamentService].get_users_from_participant_list(self.tournament.participants)
@@ -91,9 +88,6 @@ class TournamentDetailsPage(Component):
if user_ticket is None: if user_ticket is None:
self.is_success = False self.is_success = False
self.message = "Turnieranmeldung nur mit Ticket" self.message = "Turnieranmeldung nur mit Ticket"
elif not isinstance(self.tournament, Tournament):
self.is_success = False
self.message = "Fehler bei der Anmeldung"
else: else:
# Register single player # Register single player
if self.tournament.participant_type == ParticipantType.PLAYER: if self.tournament.participant_type == ParticipantType.PLAYER:
@@ -131,15 +125,12 @@ class TournamentDetailsPage(Component):
await self.on_team_register_canceled() await self.on_team_register_canceled()
return return
try: try:
if isinstance(self.tournament, Tournament):
await self.session[TournamentService].register_team_for_tournament(self.team_selected_for_register.id, self.tournament.id) await self.session[TournamentService].register_team_for_tournament(self.team_selected_for_register.id, self.tournament.id)
await self.artificial_delay() await self.artificial_delay()
self.is_success = True self.is_success = True
self.message = f"Erfolgreich angemeldet!" self.message = f"Erfolgreich angemeldet!"
self.team_dialog_open = False self.team_dialog_open = False
self.team_selected_for_register = None self.team_selected_for_register = None
else:
raise ValueError("Turnier nicht gefunden")
except Exception as e: except Exception as e:
logger.error(e) logger.error(e)
self.message = f"Fehler: {e}" self.message = f"Fehler: {e}"
@@ -158,9 +149,9 @@ class TournamentDetailsPage(Component):
return return
try: try:
if isinstance(self.tournament, Tournament) and self.tournament.participant_type == ParticipantType.PLAYER: if self.tournament.participant_type == ParticipantType.PLAYER:
await self.session[TournamentService].unregister_user_from_tournament(self.user.user_id, self.tournament.id) await self.session[TournamentService].unregister_user_from_tournament(self.user.user_id, self.tournament.id)
elif isinstance(self.tournament, Tournament) and self.tournament.participant_type == ParticipantType.TEAM: elif self.tournament.participant_type == ParticipantType.TEAM:
if team.members[self.user] == TeamStatus.OFFICER or team.members[self.user] == TeamStatus.LEADER: if team.members[self.user] == TeamStatus.OFFICER or team.members[self.user] == TeamStatus.LEADER:
await self.session[TournamentService].unregister_team_from_tournament(team.id, self.tournament.id) await self.session[TournamentService].unregister_team_from_tournament(team.id, self.tournament.id)
else: else:
@@ -175,8 +166,7 @@ class TournamentDetailsPage(Component):
self.loading = False self.loading = False
async def tree_button_clicked(self) -> None: async def tree_button_clicked(self) -> None:
if isinstance(self.tournament, Tournament): pass # ToDo: Implement tournament tree view
self.session.navigate_to(f"tournament-tree?id={self.tournament.id}")
def loading_done(self) -> None: def loading_done(self) -> None:
if self.tournament is None: if self.tournament is None:
@@ -359,7 +349,7 @@ class TournamentDetailsPage(Component):
button button
) )
if isinstance(self.tournament, Tournament) and self.tournament.participant_type == ParticipantType.TEAM: if self.tournament and self.tournament.participant_type == ParticipantType.TEAM:
content = Popup( content = Popup(
anchor=content, anchor=content,
content=Rectangle( content=Rectangle(
@@ -1,269 +0,0 @@
import json
import logging
from typing import Optional, Union
from from_root import from_root
from rio import Column, Component, event, TextStyle, Text, Row, Spacer, ProgressCircle, Rectangle, Stack
from src.ezgg_lan_manager import ConfigurationService, TournamentService, UserService, TeamService, RefreshService, SeatingService
from src.ezgg_lan_manager.components.MainViewContentBox import MainViewContentBox
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.TournamentBase import ParticipantType, TournamentFormat
from src.ezgg_lan_manager.types.User import User
from src.ezgg_lan_manager.types.UserSession import UserSession
logger = logging.getLogger(__name__.split(".")[-1])
class MatchInfo(Component):
opponent_1: str = ""
opponent_2: str = ""
opponent_1_seat: str = ""
opponent_2_seat: str = ""
winner: str = ""
def build(self) -> Component:
return Rectangle(
content=Column(
Stack(
Row(
Row(
Text(
text=self.opponent_1,
style=TextStyle(fill=self.session.theme.success_color if self.winner == self.opponent_1 else self.session.theme.background_color),
justify="left",
margin_right=0.6,
font_size=0.9
),
Text(
text=f"({self.opponent_1_seat})",
style=TextStyle(fill=self.session.theme.background_color),
justify="left",
font_size=0.9
)
),
Spacer(),
Row(
Text(
text=self.opponent_2,
style=TextStyle(fill=self.session.theme.success_color if self.winner == self.opponent_2 else self.session.theme.background_color),
justify="right",
margin_right=0.6,
font_size=0.9
),
Text(
text=f"({self.opponent_2_seat})",
style=TextStyle(fill=self.session.theme.background_color),
justify="right",
font_size=0.9
)
),
margin=0.3
),
Row(
Text(
text=f"vs.",
style=TextStyle(fill=self.session.theme.background_color),
justify="center"
),
margin=0.3
)
)
),
margin=1,
stroke_width=0.2,
stroke_color=self.session.theme.background_color,
fill=self.session.theme.hud_color,
)
class TournamentTreePage(Component):
tournament: Optional[Union[Tournament, str]] = None
user: Optional[User] = None
teams: list[Team] = []
id_to_username_map: dict[int, str] = {}
id_to_seat_map: dict[int, str] = {}
is_fully_loaded: bool = False
@event.on_populate
async def on_populate(self) -> None:
try:
tournament_id = int(self.session.active_page_url.query_string.split("id=")[-1])
except (ValueError, AttributeError, TypeError):
tournament_id = None
if tournament_id is not None:
self.tournament = await self.session[TournamentService].get_tournament_by_id(tournament_id)
if isinstance(self.tournament, Tournament):
await self.session.set_title(f"{self.session[ConfigurationService].get_lan_info().name} - {self.tournament.name}")
else:
await self.session.set_title(f"{self.session[ConfigurationService].get_lan_info().name} - Turniere")
try:
user_id = self.session[UserSession].user_id
self.user = await self.session[UserService].get_user(user_id)
except KeyError:
self.user = None
self.teams = await self.session[TeamService].get_all_teams()
all_users = await self.session[UserService].get_all_users()
id_to_username_map = {}
id_to_seat_map = {}
for user in all_users:
id_to_username_map[user.user_id] = user.user_name
seat = await self.session[SeatingService].get_user_seat(user.user_id)
if seat is not None:
id_to_seat_map[user.user_id] = seat.seat_id
self.id_to_username_map = id_to_username_map
self.id_to_seat_map = id_to_seat_map
self.session[RefreshService].subscribe(self.on_populate)
self.is_fully_loaded = True
def _get_seat_for_team(self, team: Team) -> str:
# Retrieves seat id for leader of a team
leader = list(team.members.keys())[0]
for member, rank in team.members.items():
if rank == TeamStatus.LEADER:
leader = member
break
return self.id_to_seat_map[leader.user_id]
def build(self) -> Component:
if self.tournament is None or not self.is_fully_loaded:
return Column(
MainViewContentBox(
Column(
Spacer(min_height=1),
Column(
ProgressCircle(
color="secondary",
align_x=0.5,
margin_top=0,
margin_bottom=0
),
min_height=10
),
Spacer(min_height=1)
)
),
align_y=0
)
elif isinstance(self.tournament, str):
content = Row(
Text(
text=self.tournament,
style=TextStyle(
fill=self.session.theme.background_color,
font_size=1
),
margin_top=2,
margin_bottom=2,
align_x=0.5
)
)
else:
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(
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(
MainViewContentBox(
Column(
Spacer(min_height=1),
content,
Spacer(min_height=1)
)
),
align_y=0
)
-1
View File
@@ -25,4 +25,3 @@ from .TournamentRulesPage import TournamentRulesPage
from .ConwayPage import ConwayPage from .ConwayPage import ConwayPage
from .TeamsPage import TeamsPage from .TeamsPage import TeamsPage
from .AdminNavigationPage import AdminNavigationPage from .AdminNavigationPage import AdminNavigationPage
from .TournamentTreePage import TournamentTreePage
@@ -1,6 +1,4 @@
import io
import logging import logging
import qrcode
from collections.abc import Callable from collections.abc import Callable
from datetime import datetime from datetime import datetime
from decimal import Decimal, ROUND_DOWN from decimal import Decimal, ROUND_DOWN
@@ -76,29 +74,3 @@ class AccountingService:
return "0.00 €" return "0.00 €"
rounded_decimal = str(euros.quantize(Decimal(".01"), rounding=ROUND_DOWN)) rounded_decimal = str(euros.quantize(Decimal(".01"), rounding=ROUND_DOWN))
return f"{rounded_decimal}" return f"{rounded_decimal}"
@staticmethod
def make_payment_qr_image(beneficiary_name, beneficiary_bic, beneficiary_iban, text, amount_euros=None) -> bytes:
text = text.replace("\n",";")
amount_formatted = "EUR{:.2f}".format(amount_euros) if amount_euros else ""
epc_text = f"""BCD
002
1
SCT
{beneficiary_bic}
{beneficiary_name}
{beneficiary_iban}
{amount_formatted}
{text}
"""
qr = qrcode.QRCode(
version=6,
error_correction=qrcode.constants.ERROR_CORRECT_M,
)
qr.add_data(epc_text)
img = qr.make_image()
img_bytes = io.BytesIO()
img.save(img_bytes)
return img_bytes.getvalue()
@@ -1,6 +1,6 @@
import logging import logging
from datetime import date, datetime, UTC from datetime import date, datetime
from typing import Optional from typing import Optional
from decimal import Decimal from decimal import Decimal
@@ -16,7 +16,7 @@ from src.ezgg_lan_manager.types.Seat import Seat
from src.ezgg_lan_manager.types.Team import TeamStatus, Team from src.ezgg_lan_manager.types.Team import TeamStatus, Team
from src.ezgg_lan_manager.types.Ticket import Ticket from src.ezgg_lan_manager.types.Ticket import Ticket
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 GameTitle, TournamentFormat, TournamentStatus, ParticipantType, MatchStatus from src.ezgg_lan_manager.types.TournamentBase import GameTitle, TournamentFormat, TournamentStatus, ParticipantType
from src.ezgg_lan_manager.types.Transaction import Transaction from src.ezgg_lan_manager.types.Transaction import Transaction
from src.ezgg_lan_manager.types.User import User from src.ezgg_lan_manager.types.User import User
@@ -1185,18 +1185,3 @@ class DatabaseService:
if not pool_init_result: if not pool_init_result:
raise NoDatabaseConnectionError raise NoDatabaseConnectionError
return await self.remove_user_from_team(team, user) return await self.remove_user_from_team(team, user)
async def change_tournament_status(self, tournament_id: int, status: TournamentStatus) -> None:
async with self._connection_pool.acquire() as conn:
async with conn.cursor(aiomysql.Cursor) as cursor:
try:
await cursor.execute(
"UPDATE tournaments SET status = %s WHERE (id = %s)",
(status.name, tournament_id)
)
await conn.commit()
except aiomysql.InterfaceError:
pool_init_result = await self.init_db_pool()
if not pool_init_result:
raise NoDatabaseConnectionError
return await self.change_tournament_status(tournament_id, status)
@@ -21,6 +21,5 @@ class LocalDataService:
self._session[key] = session self._session[key] = session
return key return key
def del_session(self, token: Optional[str]) -> None: def del_session(self, token: str) -> None:
if token is not None:
self._session.pop(token, None) self._session.pop(token, None)
@@ -1,17 +1,17 @@
from typing import Callable, Optional from typing import Callable
class RefreshService: class RefreshService:
""" """
The active rio.Components can subscribe to this service with their on_populate method. rio.Components can subscribe to this service with their on_populate method.
This methods get called whenever a overall refresh is needed. Usually when the user logs in or out. Those methods get called whenever a overall refresh is needed. Usually when the user logs in or out.
""" """
def __init__(self) -> None: def __init__(self) -> None:
self.subscriber: Optional[Callable] = None self.subscribers: set[Callable] = set()
def subscribe(self, refresh_cb: Callable) -> None: def subscribe(self, refresh_cb: Callable) -> None:
self.subscriber = refresh_cb self.subscribers.add(refresh_cb)
async def trigger_refresh(self) -> None: async def trigger_refresh(self) -> None:
if self.subscriber is not None: for refresh_cb in self.subscribers:
await self.subscriber() await refresh_cb()
@@ -90,12 +90,12 @@ 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._db_service.change_tournament_status(tournament_id, tournament.status) # ToDo: Write matches/round to database
self._cache_dirty = True self._cache_dirty = True
async def cancel_tournament(self, tournament_id: int): async def cancel_tournament(self, tournament_id: int):
tournament = await self.get_tournament_by_id(tournament_id) tournament = await self.get_tournament_by_id(tournament_id)
if tournament: if tournament:
tournament.cancel() tournament.cancel()
await self._db_service.change_tournament_status(tournament_id, tournament.status) # ToDo: Update to database
self._cache_dirty = True self._cache_dirty = True
-8
View File
@@ -49,14 +49,6 @@ class Match:
games.append(Game(game_id, self._match_id, game_number, None, None, False)) games.append(Game(game_id, self._match_id, game_number, None, None, False))
return tuple(games) return tuple(games)
@property
def round_number(self) -> int:
return self._round_number
@property
def best_of(self) -> int:
return self._best_of
@property @property
def status(self) -> MatchStatus: def status(self) -> MatchStatus:
if self._status == MatchStatus.COMPLETED: if self._status == MatchStatus.COMPLETED:
-4
View File
@@ -1,4 +1,3 @@
import logging
import uuid import uuid
from datetime import datetime from datetime import datetime
from typing import Optional from typing import Optional
@@ -8,7 +7,6 @@ from src.ezgg_lan_manager.types.Match import Match, FFAMatch
from src.ezgg_lan_manager.types.Participant import Participant from src.ezgg_lan_manager.types.Participant import Participant
from src.ezgg_lan_manager.types.TournamentBase import GameTitle, TournamentFormat, TournamentStatus, TournamentError, Bracket, MatchStatus, ParticipantType from src.ezgg_lan_manager.types.TournamentBase import GameTitle, TournamentFormat, TournamentStatus, TournamentError, Bracket, MatchStatus, ParticipantType
logger = logging.getLogger(__name__.split(".")[-1])
class Tournament: class Tournament:
def __init__(self, def __init__(self,
@@ -355,8 +353,6 @@ class Tournament:
raise TournamentError(f"Unknown bracket type: {bracket_type}") raise TournamentError(f"Unknown bracket type: {bracket_type}")
self._status = TournamentStatus.ONGOING self._status = TournamentStatus.ONGOING
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()
+3 -3
View File
@@ -1,9 +1,9 @@
from dataclasses import dataclass
from uuid import UUID from uuid import UUID
from rio import Dataclass
@dataclass
class UserSession(Dataclass): class UserSession:
id: UUID id: UUID
user_id: int user_id: int
is_team_member: bool is_team_member: bool
-1
View File
@@ -1 +0,0 @@
*.json
-43
View File
@@ -1,43 +0,0 @@
# Tournament data
This directory contains JSON files for tournament trees.
This is a temporary solution until the automatic tournament tree generation is completed.
# Structure
## Naming
Tournament name with `_` as separators and `.json` suffix.
## JSON structure
```json
{
"rounds": [
[
{
"opponent_1_id": 1,
"opponent_2_id": 2,
"winner": 1
},
{
"opponent_1_id": 3,
"opponent_2_id": 4,
"winner": null
}
],
[
{
"opponent_1_id": 1,
"opponent_2_id": null,
"winner": null
}
]
]
}
```
## ToDo
- Make start button in UI generate initial `.json` file for started tournament