add per-game accuracy and outcome table to stats/notifications
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 31s

Games-of-period responses can now include a per-game breakdown
(include_games) with Lichess post-analysis accuracy, plus which side
the tracked player was on and their rating change for that game.

- lichess_client.py requests accuracy=true from Lichess; stats_service
  computes per-mode average accuracy and builds GameRow entries
  (tracked_is_white, tracked_rating_diff) for blitz/rapid/classical
- /games/{username}/period gained an include_games query param
- formatters.py renders a column-aligned monospace table per game:
  outcome circle (win/loss/draw relative to the tracked player),
  rating change, accuracy, names/ratings, result — for today/yesterday
  and periodic notifications; week keeps an aggregate accuracy line
- usernames are Markdown-escaped before formatting since messages are
  now sent with parse_mode='Markdown'
This commit is contained in:
vrubelroman 2026-07-03 09:38:51 +00:00
parent 4a783225af
commit d479e14bf9
8 changed files with 364 additions and 75 deletions

View file

@ -498,9 +498,12 @@ async def get_games_of_period(
until: int = Query(...,
description="Конец периода (Unix timestamp в миллисекундах)",
example=1641081600000),
rated_only: bool = Query(True,
description="Только рейтинговые игры (по умолчанию true - рекомендуется)",
example=True)
rated_only: bool = Query(True,
description="Только рейтинговые игры (по умолчанию true - рекомендуется)",
example=True),
include_games: bool = Query(False,
description="Включить построчный список отдельных партий (только blitz/rapid/classical)",
example=False)
):
"""
## Статистика игр за период
@ -554,7 +557,7 @@ async def get_games_of_period(
# Конвертируем миллисекунды в секунды для внутренней логики
since_seconds = since // 1000
until_seconds = until // 1000
result = await stats_service.get_games_of_period(username, since_seconds, until_seconds, rated_only)
result = await stats_service.get_games_of_period(username, since_seconds, until_seconds, rated_only, include_games)
if not result.success:
# Реальная ошибка при обращении к Lichess — не маскируем её под "0 игр"
raise HTTPException(status_code=502, detail=result.message)