fix: match player by SNo, not name (Latin/Cyrillic mismatch)

This commit is contained in:
vrubel 2026-06-20 08:55:09 +00:00
parent ba293dcb70
commit 9a583c8fa5
2 changed files with 13 additions and 11 deletions

View file

@ -105,13 +105,13 @@ def _pad_col(s: str, width: int) -> str:
def format_pairings(pairings_data: dict, tournament_name: str, lang: str = '', def format_pairings(pairings_data: dict, tournament_name: str, lang: str = '',
player_name: str = '') -> str: player_name: str = '', player_sno: int = 0) -> str:
locale = _get_locale(lang) locale = _get_locale(lang)
pairings = pairings_data['pairings'] pairings = pairings_data['pairings']
rnd = pairings_data['round'] rnd = pairings_data['round']
# If highlighting a player, reduce name width to compensate for ✅ emoji (visually 2 chars wide) # If highlighting a player, reduce name width to compensate for ✅ emoji (visually 2 chars wide)
w_name = 15 if player_name else 17 w_name = 15 if player_sno else 17
w_board, w_rating, w_pts, w_tb1 = 2, 4, 4, 5 w_board, w_rating, w_pts, w_tb1 = 2, 4, 4, 5
border = '+'.join('-' * w for w in [w_board, w_name, w_rating, w_pts, w_tb1]) border = '+'.join('-' * w for w in [w_board, w_name, w_rating, w_pts, w_tb1])
@ -130,7 +130,7 @@ def format_pairings(pairings_data: dict, tournament_name: str, lang: str = '',
return { return {
'title': title, 'title': title,
'rows': _build_table_rows(pairings, w_board, w_name, w_rating, w_pts, w_tb1, border, 'rows': _build_table_rows(pairings, w_board, w_name, w_rating, w_pts, w_tb1, border,
locale['bye'], player_name), locale['bye'], player_name, player_sno),
'table_header': table_header, 'table_header': table_header,
'footer': footer, 'footer': footer,
} }
@ -138,14 +138,16 @@ def format_pairings(pairings_data: dict, tournament_name: str, lang: str = '',
def _build_table_rows(pairings: list, w_board: int, w_name: int, w_rating: int, def _build_table_rows(pairings: list, w_board: int, w_name: int, w_rating: int,
w_pts: int, w_tb1: int, border: str, bye_label: str = '— BYE —', w_pts: int, w_tb1: int, border: str, bye_label: str = '— BYE —',
player_name: str = '') -> list: player_name: str = '', player_sno: int = 0) -> list:
def _rating_str(p): def _rating_str(p):
return str(p.rating) if p.rating else '' return str(p.rating) if p.rating else ''
def _tb1_str(p): def _tb1_str(p):
return f"{p.tb[0]:.1f}" if p.tb else '' return f"{p.tb[0]:.1f}" if p.tb else ''
# Find the board where the player plays (normalize names: strip commas, collapse spaces) # Find the board where the player plays.
# Primary: match by SNo (reliable across Latin/Cyrillic name variations).
# Fallback: match by normalized name.
def _n(s: str) -> str: def _n(s: str) -> str:
return s.replace(',', '').replace(' ', ' ').lower() return s.replace(',', '').replace(' ', ' ').lower()
@ -156,13 +158,13 @@ def _build_table_rows(pairings: list, w_board: int, w_name: int, w_rating: int,
if len(pairing) != 3: if len(pairing) != 3:
continue continue
p1, p2, _color = pairing p1, p2, _color = pairing
if player_sno and (p1.sno == player_sno or p2.sno == player_sno):
player_board = board_idx
player_name = p1.name if p1.sno == player_sno else p2.name
break
if player_norm and (player_norm == _n(p1.name) or player_norm == _n(p2.name)): if player_norm and (player_norm == _n(p1.name) or player_norm == _n(p2.name)):
player_board = board_idx player_board = board_idx
# Store the actual name from pairings for the ✅ marker player_name = p1.name if player_norm == _n(p1.name) else p2.name
if player_norm == _n(p1.name):
player_name = p1.name
else:
player_name = p2.name
break break
board_idx += 1 board_idx += 1

View file

@ -729,7 +729,7 @@ async def check_all_subscriptions(context):
try: try:
result = calculate_next_round(tournament) result = calculate_next_round(tournament)
fmt = format_pairings(result, tournament.get('name', ''), sub['lang'], fmt = format_pairings(result, tournament.get('name', ''), sub['lang'],
sub['player_name']) sub['player_name'], sub['player_sno'])
chunks = _render_chunks(fmt) chunks = _render_chunks(fmt)
for chunk in chunks: for chunk in chunks:
try: try: