Убрал таблицу, заменил на компактный список (влезает на телефон)
Каждая пара — одна строка: номер, белые (очки) — чёрные (очки). Убрал мёртвый код: _display_width, _make_table_* и др.
This commit is contained in:
parent
35fb54a887
commit
566daf5bb4
1 changed files with 14 additions and 74 deletions
|
|
@ -44,64 +44,15 @@ def _md_escape(text: str) -> str:
|
||||||
return ''.join(result)
|
return ''.join(result)
|
||||||
|
|
||||||
|
|
||||||
def _display_width(s: str) -> int:
|
|
||||||
w = 0
|
|
||||||
for ch in s:
|
|
||||||
cp = ord(ch)
|
|
||||||
# Cyrillic, CJK, etc — typically 2-wide in monospace
|
|
||||||
if (0x0400 <= cp <= 0x04FF or 0x0500 <= cp <= 0x052F or
|
|
||||||
0x2E80 <= cp <= 0x9FFF or 0xF900 <= cp <= 0xFAFF or
|
|
||||||
0xFE30 <= cp <= 0xFE4F or cp == 0x2116):
|
|
||||||
w += 2
|
|
||||||
else:
|
|
||||||
w += 1
|
|
||||||
return w
|
|
||||||
|
|
||||||
|
|
||||||
def _pad_to_width(s: str, width: int) -> str:
|
|
||||||
cur = _display_width(s)
|
|
||||||
if cur >= width:
|
|
||||||
return s
|
|
||||||
return s + ' ' * (width - cur)
|
|
||||||
|
|
||||||
|
|
||||||
def _trim_to_width(s: str, width: int) -> str:
|
|
||||||
result = []
|
|
||||||
cur = 0
|
|
||||||
for ch in s:
|
|
||||||
cw = 2 if _display_width(ch) == 2 else 1
|
|
||||||
if cur + cw > width:
|
|
||||||
break
|
|
||||||
result.append(ch)
|
|
||||||
cur += cw
|
|
||||||
return ''.join(result)
|
|
||||||
|
|
||||||
|
|
||||||
def _make_table_header(cols: list, widths: list) -> str:
|
|
||||||
parts = [_pad_to_width(c, w) for c, w in zip(cols, widths)]
|
|
||||||
line = ' │ '.join(parts)
|
|
||||||
sep = '─┼─'.join('─' * w for w in widths)
|
|
||||||
return line + '\n' + sep
|
|
||||||
|
|
||||||
|
|
||||||
def _make_table_row(cols: list, widths: list) -> str:
|
|
||||||
parts = [_pad_to_width(c, w) for c, w in zip(cols, widths)]
|
|
||||||
return ' │ '.join(parts)
|
|
||||||
|
|
||||||
|
|
||||||
def format_pairings(pairings_data: dict, tournament_name: str) -> str:
|
def format_pairings(pairings_data: dict, tournament_name: str) -> str:
|
||||||
pairings = pairings_data['pairings']
|
pairings = pairings_data['pairings']
|
||||||
rnd = pairings_data['round']
|
rnd = pairings_data['round']
|
||||||
|
|
||||||
max_name = 28
|
lines = [
|
||||||
cols = ['#', 'Белые', 'О', 'Чёрные', 'О']
|
f'*{_md_escape(tournament_name)}*',
|
||||||
widths = [5, max_name, 5, max_name, 5]
|
f'📋 *Тур {rnd}* — пары',
|
||||||
|
'',
|
||||||
header_line = f'*{_md_escape(tournament_name)}*\n📋 *Тур {rnd}* — пары\n'
|
]
|
||||||
|
|
||||||
table_lines = []
|
|
||||||
table_lines.append('```')
|
|
||||||
table_lines.append(_make_table_header(cols, widths))
|
|
||||||
|
|
||||||
board = 1
|
board = 1
|
||||||
for pairing in pairings:
|
for pairing in pairings:
|
||||||
|
|
@ -110,11 +61,7 @@ def format_pairings(pairings_data: dict, tournament_name: str) -> str:
|
||||||
p1, p2, color = pairing
|
p1, p2, color = pairing
|
||||||
|
|
||||||
if color == 'bye':
|
if color == 'bye':
|
||||||
bye_name = _trim_to_width(p1.name, max_name)
|
lines.append(f'{board}\\. {_md_escape(p1.name)} — BYE')
|
||||||
table_lines.append(
|
|
||||||
_make_table_row(
|
|
||||||
[str(board), bye_name, str(p1.points), '— BYE —', ''],
|
|
||||||
widths))
|
|
||||||
board += 1
|
board += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -123,27 +70,20 @@ def format_pairings(pairings_data: dict, tournament_name: str) -> str:
|
||||||
else:
|
else:
|
||||||
white, black = p2, p1
|
white, black = p2, p1
|
||||||
|
|
||||||
w_name = _trim_to_width(white.name, max_name)
|
lines.append(
|
||||||
b_name = _trim_to_width(black.name, max_name)
|
f'{board}\\. {_md_escape(white.name)} '
|
||||||
w_pts = f'{white.points:.1f}'
|
f'\\({white.points:.1f}\\) — '
|
||||||
b_pts = f'{black.points:.1f}'
|
f'{_md_escape(black.name)} \\({black.points:.1f}\\)'
|
||||||
|
)
|
||||||
table_lines.append(
|
|
||||||
_make_table_row(
|
|
||||||
[str(board), w_name, w_pts, b_name, b_pts],
|
|
||||||
widths))
|
|
||||||
board += 1
|
board += 1
|
||||||
|
|
||||||
table_lines.append('```')
|
|
||||||
|
|
||||||
footer = ''
|
|
||||||
source = pairings_data.get('source', 'algorithm')
|
source = pairings_data.get('source', 'algorithm')
|
||||||
if source == 'bbp_pairings_fide_2025':
|
if source == 'bbp_pairings_fide_2025':
|
||||||
footer = '\n_FIDE 2025 \(bbpPairings\)_'
|
lines.append('\n_FIDE 2025 \(bbpPairings\)_')
|
||||||
elif source == 'swiss_algorithm_simplified':
|
elif source == 'swiss_algorithm_simplified':
|
||||||
footer = '\n_Упрощённый Swiss \(bbpPairings недоступен\)_'
|
lines.append('\n_Упрощённый Swiss \(bbpPairings недоступен\)_')
|
||||||
|
|
||||||
return header_line + '\n'.join(table_lines) + footer
|
return '\n'.join(lines)
|
||||||
|
|
||||||
|
|
||||||
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue