add tournament data model #31

Merged
Typhus merged 1 commits from feature/add-tournament-data-model into main 2026-01-28 20:15:39 +00:00
Owner

Adds the internal data model and core logic for tournaments.

Adds the internal data model and core logic for tournaments.
Typhus self-assigned this 2026-01-27 17:24:58 +00:00
Typhus added 1 commit 2026-01-27 17:24:59 +00:00
Typhus requested review from tcprod 2026-01-27 17:25:06 +00:00
tcprod requested changes 2026-01-28 19:55:37 +00:00
Dismissed
@@ -0,0 +5,4 @@
class Game:
def __init__(self, id_: tuple[int, int], match_id: int, game_number: int, winner_id: Optional[int], score: Optional[tuple[int, int]], game_done: bool) -> None:
self._id = id_

Wieso "id_"?

Wieso "id_"?
Author
Owner
[id() gibts schon](https://www.w3schools.com/python/ref_func_id.asp)
tcprod marked this conversation as resolved
@@ -0,0 +101,4 @@
def assign_participant(self, participant_id: int, slot: Literal[1, 2]) -> None:
new_participant = MatchParticipant(participant_id, slot)
if len(self._participants) < 2 and not any(p.participant_id == participant_id for p in self._participants):

Wäre es sinnvoll die Bedingung der If-Anweisung in eine extra Funktion zu extrahieren, um diese verständlicher zu machen?

Wäre es sinnvoll die Bedingung der If-Anweisung in eine extra Funktion zu extrahieren, um diese verständlicher zu machen?
Author
Owner

Für eine Zeile Code die bisher nur einmal genutzt wird würde ich sagen eher nicht.

YAGNI

Für eine Zeile Code die bisher nur einmal genutzt wird würde ich sagen eher nicht. YAGNI
tcprod marked this conversation as resolved
@@ -0,0 +102,4 @@
def assign_participant(self, participant_id: int, slot: Literal[1, 2]) -> None:
new_participant = MatchParticipant(participant_id, slot)
if len(self._participants) < 2 and not any(p.participant_id == participant_id for p in self._participants):
if len(self._participants) == 1 and self._participants[-1].slot_number == new_participant.slot_number:

Hier das gleiche

Hier das gleiche
Author
Owner

Selbe Antwort

Selbe Antwort
tcprod marked this conversation as resolved
@@ -0,0 +22,4 @@
self._id = id_
self._name = name
self._game_title = game_title
self._format = format_

Wieso "format_"?

Wieso "format_"?
Author
Owner
[format() gibts schon](https://www.w3schools.com/python/ref_string_format.asp)
tcprod marked this conversation as resolved
@@ -0,0 +86,4 @@
next_match.assign_participant(winner, 1)
except TournamentError:
next_match.assign_participant(winner, 2)
else: # No next match = final round

Ist das "else" nicht überflüssig?

Ist das "else" nicht überflüssig?
Author
Owner

Logisch absolut. Code Style-technisch soll das den Intend signalisieren. Also das hier gezielt auf das zuweißen weiterer matches verzichtet wird.

Logisch absolut. Code Style-technisch soll das den [Intend signalisieren](https://codingwithempathy.com/2016/10/18/capturing-intent_making-sense-of-code/). Also das hier gezielt auf das zuweißen weiterer matches verzichtet wird.
tcprod marked this conversation as resolved
@@ -0,0 +97,4 @@
next_match.assign_participant(loser.participant_id, 1)
except TournamentError:
next_match.assign_participant(loser.participant_id, 2)
else: # No next match = final round

Gleiche

Gleiche
Author
Owner

Gleiche

Gleiche
tcprod marked this conversation as resolved
@@ -0,0 +215,4 @@
num_rounds_lower = 2 * (num_rounds_upper - 1)
lower_rounds: list[list[Match]] = []
for round_number in range(1, num_rounds_lower + 1):
num_matches = 2 ** (num_rounds_lower - round_number - 1) if round_number != 1 else 2 ** (num_rounds_upper - 1)

Hier könnte man auch noch eine Funktion draus erstellen

Hier könnte man auch noch eine Funktion draus erstellen
Author
Owner

Also sowas?

def calculate_match_amount(num_rounds_lower, round_number, num_rounds_upper) -> int:
    return 2 ** (num_rounds_lower - round_number - 1) if round_number != 1 else 2 ** (num_rounds_upper - 1)

for round_number in range(1, num_rounds_lower + 1):
    num_matches = calculate_match_amount(num_rounds_lower, round_number, num_rounds_upper)

Würde es das für dich denn besser machen?

Also sowas? ```py def calculate_match_amount(num_rounds_lower, round_number, num_rounds_upper) -> int: return 2 ** (num_rounds_lower - round_number - 1) if round_number != 1 else 2 ** (num_rounds_upper - 1) for round_number in range(1, num_rounds_lower + 1): num_matches = calculate_match_amount(num_rounds_lower, round_number, num_rounds_upper) ``` Würde es das für dich denn besser machen?
tcprod marked this conversation as resolved
tcprod approved these changes 2026-01-28 20:14:39 +00:00
Typhus force-pushed feature/add-tournament-data-model from 1a0573cba9 to ff5d715a4e 2026-01-28 20:14:41 +00:00 Compare
Typhus merged commit ff5d715a4e into main 2026-01-28 20:15:39 +00:00
Typhus deleted branch feature/add-tournament-data-model 2026-01-28 20:15:39 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Vereins-IT/ezgg-lan-manager#31