123 lines
5.8 KiB
Python
123 lines
5.8 KiB
Python
from nicegui import ui, app
|
|
from data import data_api
|
|
from gui import gui_style
|
|
|
|
|
|
def setup_routes():
|
|
@ui.page('/matchhistory', dark=True)
|
|
def match_history_page():
|
|
|
|
gui_style.apply_design()
|
|
|
|
if not app.storage.user.get('authenticated', False):
|
|
ui.label('Bitte logge dich ein.').classes('text-red-500 text-2xl m-4')
|
|
return
|
|
|
|
player_id = app.storage.user.get('db_id')
|
|
|
|
with ui.column().classes('w-full max-w-7xl mx-auto p-4'):
|
|
|
|
with ui.row().classes('w-full items-center justify-between mb-6'):
|
|
ui.label("Komplette Match Historie").classes("text-3xl font-bold text-white")
|
|
ui.button("Zurück", icon="arrow_back", on_click=lambda: ui.navigate.to('/')).classes('bg-zinc-700 text-white')
|
|
|
|
raw_matches = data_api.get_match_history_log(player_id)
|
|
table_rows = []
|
|
|
|
def fmt_signed(val, pending=False):
|
|
"""Formatiert einen Integer-Wert mit Vorzeichen oder gibt Sondertexte zurück."""
|
|
if pending:
|
|
return "Ausstehend"
|
|
if val is None:
|
|
return "0"
|
|
if val > 0:
|
|
return f"+{val}"
|
|
return str(val)
|
|
|
|
for i, match in enumerate(raw_matches):
|
|
is_player1 = match['player1_id'] == player_id
|
|
pending = match['match_is_counted'] == 0
|
|
|
|
if is_player1:
|
|
opponent = f"{match['p2_display']} aka {match['p2_discord']}"
|
|
my_score = match['score_player1']
|
|
opp_score = match['score_player2']
|
|
my_mmr_change = match['player1_mmr_change']
|
|
my_khorne = match['player1_khorne']
|
|
my_tzeentch = match['player1_tzeentch']
|
|
my_slaanesh = match['player1_slaanesh']
|
|
else:
|
|
opponent = f"{match['p1_display']} aka {match['p1_discord']}"
|
|
my_score = match['score_player2']
|
|
opp_score = match['score_player1']
|
|
my_mmr_change = match['player2_mmr_change']
|
|
my_khorne = match['player2_khorne']
|
|
my_tzeentch = match['player2_tzeentch']
|
|
my_slaanesh = match['player2_slaanesh']
|
|
|
|
if my_score > opp_score:
|
|
result = "Gewonnen"
|
|
elif my_score < opp_score:
|
|
result = "Verloren"
|
|
else:
|
|
result = "Unentschieden"
|
|
|
|
elo_factor = match['elo_factor']
|
|
rust_factor = match['rust_factor']
|
|
|
|
table_rows.append({
|
|
'id': i,
|
|
'date': str(match['played_at'])[:10],
|
|
'system': match['gamesystem_name'],
|
|
'score': str(my_score),
|
|
'opponent': opponent,
|
|
'opp_score': str(opp_score),
|
|
'result': result,
|
|
'elo': fmt_signed(round(elo_factor, 2) if elo_factor is not None else None, pending),
|
|
'rust': fmt_signed(round(rust_factor, 2) if rust_factor is not None else None, pending),
|
|
'khorne': fmt_signed(my_khorne, pending),
|
|
'tzeentch': fmt_signed(my_tzeentch, pending),
|
|
'slaanesh': fmt_signed(my_slaanesh, pending),
|
|
'mmr': fmt_signed(my_mmr_change, pending),
|
|
})
|
|
|
|
columns = [
|
|
{'name': 'date', 'label': 'Datum', 'field': 'date', 'align': 'left'},
|
|
{'name': 'system', 'label': 'System', 'field': 'system', 'align': 'left'},
|
|
{'name': 'score', 'label': 'Eigene Punkte', 'field': 'score', 'align': 'center'},
|
|
{'name': 'opponent', 'label': 'Gegner', 'field': 'opponent', 'align': 'left'},
|
|
{'name': 'opp_score','label': 'Gegner Punkte', 'field': 'opp_score','align': 'center'},
|
|
{'name': 'result', 'label': 'Ergebnis', 'field': 'result', 'align': 'left'},
|
|
{'name': 'elo', 'label': 'Elo Faktor', 'field': 'elo', 'align': 'right'},
|
|
{'name': 'rust', 'label': 'Rost Faktor', 'field': 'rust', 'align': 'right'},
|
|
{'name': 'khorne', 'label': 'Khorne', 'field': 'khorne', 'align': 'right'},
|
|
{'name': 'tzeentch', 'label': 'Tzeentch', 'field': 'tzeentch', 'align': 'right'},
|
|
{'name': 'slaanesh', 'label': 'Slaanesh', 'field': 'slaanesh', 'align': 'right'},
|
|
{'name': 'mmr', 'label': 'MMR Änderung', 'field': 'mmr', 'align': 'right'},
|
|
]
|
|
|
|
# Shared slot template for colored signed values
|
|
colored_slot = '''
|
|
<q-td :props="props">
|
|
<span :class="{
|
|
'text-green-500 font-bold': props.row[props.col.field].startsWith('+'),
|
|
'text-red-500 font-bold': props.row[props.col.field].startsWith('-'),
|
|
'text-gray-400 italic': props.row[props.col.field] === 'Ausstehend'
|
|
}">
|
|
{{ props.row[props.col.field] }}
|
|
</span>
|
|
</q-td>
|
|
'''
|
|
|
|
if table_rows:
|
|
history_table = ui.table(
|
|
columns=columns,
|
|
rows=table_rows,
|
|
row_key='id'
|
|
).classes('w-full bg-zinc-900 text-white')
|
|
|
|
for col in ['elo', 'rust', 'khorne', 'tzeentch', 'slaanesh', 'mmr']:
|
|
history_table.add_slot(f'body-cell-{col}', colored_slot)
|
|
else:
|
|
ui.label("Keine Spiele gefunden.").classes("text-gray-400 italic")
|