diff --git a/data/data_api.py b/data/data_api.py index 101b151..977591d 100644 --- a/data/data_api.py +++ b/data/data_api.py @@ -477,6 +477,26 @@ def get_leaderboard(system_name): return result +def update_match_mmr_change(match_id, p1_change, p2_change): + """Speichert die tatsächliche MMR-Änderung für das Log fest im Match ab.""" + connection = sqlite3.connect(DB_PATH) + cursor = connection.cursor() + + cursor.execute(""" + UPDATE matches + SET player1_mmr_change = ?, player2_mmr_change = ? + WHERE id = ? + """, (p1_change, p2_change, match_id)) + + connection.commit() + connection.close() + + + +# ----------------------------------------------------- +# Matches Bestätigen, Löschen, Berechnen, ... +# ----------------------------------------------------- + def get_unconfirmed_matches(player_id): """Holt alle offenen Matches, die der Spieler noch bestätigen muss.""" connection = sqlite3.connect(DB_PATH) @@ -537,7 +557,6 @@ def set_match_counted(match_id): connection.close() - def get_submitted_matches(player_id): """Holt alle offenen Matches, die der Spieler selbst eingetragen hat, aber vom Gegner noch nicht bestätigt wurden.""" connection = sqlite3.connect(DB_PATH) diff --git a/data/setup_database.py b/data/setup_database.py index 96e9535..557b776 100644 --- a/data/setup_database.py +++ b/data/setup_database.py @@ -1,8 +1,9 @@ import sqlite3 import os import json +from main import url + -dummy_is_in = False # 1. Sucht den exakten, absoluten Pfad zu diesem Skript (z.B. /srv/Diceghost-Liga-System/data/) BASE_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -10,6 +11,12 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__)) DB_PATH = os.path.join(BASE_DIR, "league_database.db") def init_db(): + + if url == "https://liga.au-fab.eu": + dummy_is_in = False + else: + dummy_is_in = True + connection = sqlite3.connect(DB_PATH) cursor = connection.cursor() diff --git a/gui/league_statistic.py b/gui/league_statistic.py index a5d5317..4823823 100644 --- a/gui/league_statistic.py +++ b/gui/league_statistic.py @@ -44,7 +44,7 @@ def setup_routes(): table_rows.append({ 'rank': current_rank, 'trend': '➖', # Platzhalter für später - 'name': f"{player['display_name']} aka {player['discord_name']}", + 'name': f"{player['display_name']} 'aka' {player['discord_name']}", 'mmr': player['mmr'] }) diff --git a/gui/main_gui.py b/gui/main_gui.py index 202ab8b..0883765 100644 --- a/gui/main_gui.py +++ b/gui/main_gui.py @@ -224,28 +224,23 @@ def setup_routes(admin_discord_id): # --------------------------- # Match Historie # --------------------------- - with ui.card().classes("w-full"): ui.label(text= "Meine letzten Spiele").classes("font-bold text-white text-xl") - # 1. Daten aus der DB holen - raw_matches = data_api.get_recent_matches_for_player(player_id) + # 1. Daten aus der DB holen ABER per [:5] hart auf die neuesten 5 Listen-Einträge abschneiden! + raw_matches = data_api.get_recent_matches_for_player(player_id)[:5] - # 2. Daten für die Tabelle aufbereiten + # 2. Daten für die Tabelle aufbereiten (Bleibt exakt gleich wie bei dir) table_rows = [] for match in raw_matches: - # Bin ich Spieler 1 oder Spieler 2? if match['player1_id'] == player_id: - # Ich bin Spieler 1, also ist Spieler 2 der Gegner opponent_name = f"{match['p2_display']} aka {match['p2_discord']}" my_score = match['score_player1'] opp_score = match['score_player2'] else: - # Ich bin Spieler 2, also ist Spieler 1 der Gegner opponent_name = f"{match['p1_display']} aka {match['p1_discord']}" my_score = match['score_player2'] opp_score = match['score_player1'] - # Gewonnen oder Verloren? if my_score > opp_score: result_text = "Gewonnen" elif my_score < opp_score: @@ -253,10 +248,8 @@ def setup_routes(admin_discord_id): else: result_text = "Unentschieden" - # Datum hübsch machen (schneidet die Millisekunden weg) date_clean = str(match['played_at'])[:10] - # Eine fertige Zeile für unsere Tabelle bauen table_rows.append({ 'date': date_clean, 'system': match['gamesystem_name'], @@ -264,7 +257,6 @@ def setup_routes(admin_discord_id): 'result': f"{result_text} ({my_score} : {opp_score})" }) - # 3. Das Layout (Die Spalten) der Tabelle definieren table_columns = [ {'name': 'date', 'label': 'Gespielt am', 'field': 'date', 'align': 'left'}, {'name': 'system', 'label': 'System', 'field': 'system', 'align': 'left'}, @@ -272,15 +264,12 @@ def setup_routes(admin_discord_id): {'name': 'result', 'label': 'Ergebnis', 'field': 'result', 'align': 'left'} ] - # 4. Die Tabelle zeichnen! + # 4. Die Tabelle zeichnen und den NEUEN BUTTON hinzufügen if len(table_rows) > 0: ui.table(columns=table_columns, rows=table_rows, row_key='date').classes('w-full bg-zinc-900 text-white') + + # NEU: Der Button, der zur großen Log-Seite führt + ui.button("Komplette Historie & Log anzeigen", icon="history", on_click=lambda: ui.navigate.to('/matchhistory')).classes('w-full mt-4 bg-zinc-700 text-white hover:bg-zinc-600') else: ui.label("Noch keine Spiele absolviert.").classes("text-gray-500 italic") - - - - - - diff --git a/gui/match_gui.py b/gui/match_gui.py index 6413df8..e1b5451 100644 --- a/gui/match_gui.py +++ b/gui/match_gui.py @@ -37,7 +37,7 @@ def setup_routes(): for p in raw_players: if p['player_id'] == my_id: continue - dropdown_options[p['player_id']] = f"{p['display_name']} aka {p['discord_name']}" + dropdown_options[p['player_id']] = f"{p['display_name']} 'aka' {p['discord_name']}" # ÄNDERUNG: .classes('w-full') hinzugefügt, damit der Slider sich anpasst p1_points = ui.slider(min=0, max=100, value=10).props("label-always").classes('w-full') diff --git a/gui/pictures/40k_Logo_Colour_1.png b/gui/pictures/40k_Logo_Colour_1.png new file mode 100644 index 0000000..5961acd Binary files /dev/null and b/gui/pictures/40k_Logo_Colour_1.png differ diff --git a/gui/pictures/KT_Logo.png b/gui/pictures/KT_Logo.png new file mode 100644 index 0000000..9d00ba6 Binary files /dev/null and b/gui/pictures/KT_Logo.png differ diff --git a/gui/pictures/Middle_Earth_SBG_Logo_1.png b/gui/pictures/Middle_Earth_SBG_Logo_1.png new file mode 100644 index 0000000..15d9b92 Binary files /dev/null and b/gui/pictures/Middle_Earth_SBG_Logo_1.png differ diff --git a/gui/pictures/Necromunda_Logo.png b/gui/pictures/Necromunda_Logo.png new file mode 100644 index 0000000..61c16a8 Binary files /dev/null and b/gui/pictures/Necromunda_Logo.png differ diff --git a/gui/pictures/Universe_Horus_Heresy__Type_BW.png b/gui/pictures/Universe_Horus_Heresy__Type_BW.png new file mode 100644 index 0000000..a568556 Binary files /dev/null and b/gui/pictures/Universe_Horus_Heresy__Type_BW.png differ diff --git a/gui/pictures/WHAOS_logo_shadow_colour_1.png b/gui/pictures/WHAOS_logo_shadow_colour_1.png new file mode 100644 index 0000000..92a3e74 Binary files /dev/null and b/gui/pictures/WHAOS_logo_shadow_colour_1.png differ diff --git a/gui/pictures/WHAOS_logo_shadow_colour_2.png b/gui/pictures/WHAOS_logo_shadow_colour_2.png new file mode 100644 index 0000000..04b80da Binary files /dev/null and b/gui/pictures/WHAOS_logo_shadow_colour_2.png differ diff --git a/gui/pictures/Warcry_Logo.png b/gui/pictures/Warcry_Logo.png new file mode 100644 index 0000000..59ab447 Binary files /dev/null and b/gui/pictures/Warcry_Logo.png differ diff --git a/gui/pictures/blood_bowl_1.png b/gui/pictures/blood_bowl_1.png new file mode 100644 index 0000000..0053e7d Binary files /dev/null and b/gui/pictures/blood_bowl_1.png differ diff --git a/main.py b/main.py index 458de2b..fb3be2a 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,6 @@ from dotenv import load_dotenv from nicegui import ui from gui import main_gui, match_gui, discord_login, league_statistic, admin_gui - from data import database @@ -14,6 +13,7 @@ load_dotenv() client_id = os.getenv("DISCORD_CLIENT_ID") client_secret = os.getenv("DISCORD_CLIENT_SECRET") admin_discord_id = os.getenv("ADMIN") +url = os.getenv("APP_URL") database.check_db() diff --git a/match_calculations/calc_match.py b/match_calculations/calc_match.py index fc7fa8d..cd48ecd 100644 --- a/match_calculations/calc_match.py +++ b/match_calculations/calc_match.py @@ -64,6 +64,20 @@ def calculate_match (match_id): data_api.apply_match_to_player_statistic (winner_id, sys_id, mmr_change_winner, winner_score) data_api.apply_match_to_player_statistic (looser_id, sys_id, mmr_change_looser, looser_score) + + # Zuordnen: Welcher Change gehört zu P1 und welcher zu P2? + if winner_id == p1_id: + p1_change = mmr_change_winner + p2_change = mmr_change_looser + else: + # Wenn der Sieger nicht P1 ist, muss P1 der Verlierer sein (oder Draw, da ist es egal) + p1_change = mmr_change_looser + p2_change = mmr_change_winner + + # Die Änderungen für das Log ins Match eintragen! + data_api.update_match_mmr_change(match_id, p1_change, p2_change) + + # Das Match als Berechnet markieren data_api.set_match_counted(match_id)