diff --git a/LichessClientTG_bot/bot.py b/LichessClientTG_bot/bot.py index 80ea661..4aa3143 100644 --- a/LichessClientTG_bot/bot.py +++ b/LichessClientTG_bot/bot.py @@ -640,6 +640,11 @@ class LichessBot: year_ms = 365 * 24 * 3600 * 1000 since_ms = now_ms - year_ms try: + # Inform user that the request is being processed + try: + await update.message.reply_text("⏳ Please wait a moment, processing the request…") + except Exception: + pass data = await self.lichess_api.get_games_period(username, since_ms, now_ms, rated_only=True) if not data: await update.message.reply_text(t('no_data', lang)) diff --git a/LichessClientTG_bot/formatters.py b/LichessClientTG_bot/formatters.py index 16c2039..fc4a3f6 100644 --- a/LichessClientTG_bot/formatters.py +++ b/LichessClientTG_bot/formatters.py @@ -11,7 +11,7 @@ class StatsFormatter: elif rating_change < 0: return f"🔴 {rating_change}" else: - return f"0" + return "⚪ 0" @staticmethod def format_stats_response(data: Dict[str, Any], username: str, period: str, lang: str = 'en') -> str: @@ -185,16 +185,18 @@ class StatsFormatter: # Title and subheader if games_count >= 1000: header = f"📈 {username}: last 1000 rated games" - # Use period_start as earliest known bound (server does not expose earliest game timestamp) - if isinstance(period_start, int): - earliest = datetime.fromtimestamp(period_start).strftime("%d.%m.%Y") - header += f"\nНачало этих 1000 партий: {earliest}" + earliest_ts = data.get('earliest_game_ts') + if isinstance(earliest_ts, int): + earliest = datetime.fromtimestamp(earliest_ts).strftime("%d.%m.%Y") + header += f"\nStart of these 1000 games: {earliest}" else: header = f"📈 {username}: last year (rated), games: {games_count}" - if isinstance(period_start, int) and isinstance(period_end, int): - start_str = datetime.fromtimestamp(period_start).strftime("%d.%m.%Y") + # Use earliest actual game date instead of naive 'year ago' + earliest_ts = data.get('earliest_game_ts', period_start) + if isinstance(earliest_ts, int) and isinstance(period_end, int): + start_str = datetime.fromtimestamp(earliest_ts).strftime("%d.%m.%Y") end_str = datetime.fromtimestamp(period_end).strftime("%d.%m.%Y") - header += f"\nПериод: {start_str}–{end_str}" + header += f"\nPeriod: {start_str}–{end_str}" # Body per mode lines = [] for mode in ["bullet", "blitz", "rapid", "classical", "correspondence"]: @@ -213,20 +215,9 @@ class StatsFormatter: rating = mode_stats.get('rating') rating_str = rating if rating is not None else "—" lines.append( - f"{emoji} {mode.title()}: {games_played} Δ {rating_change_str} R {rating_str} (+{wins} -{losses} ={draws})" + f"{emoji} {mode.title()}: {games_played} Δ {rating_change_str} R {rating_str} ✅ {wins} ❌ {losses} 🤝 {draws}" ) # Total - total = stats.get('total') or {} - total_line = "" - if total: - tg = total.get('games_played', 0) - tw = total.get('wins', 0) - tl = total.get('losses', 0) - td = total.get('draws', 0) - trc = total.get('rating_change', 0) - trc_str = StatsFormatter._format_rating_change(trc) - tr = total.get('rating') - tr_str = tr if tr is not None else "—" - total_line = f"\nИтого: {tg} Δ {trc_str} R {tr_str} (+{tw} -{tl} ={td})" - body = "\n".join(lines) + total_line + # Do not print 'Итого' line per new requirement + body = "\n".join(lines) return f"{header}\n{body}".rstrip() diff --git a/LichessWebServices/models.py b/LichessWebServices/models.py index 89955fb..84ed5a3 100644 --- a/LichessWebServices/models.py +++ b/LichessWebServices/models.py @@ -190,6 +190,7 @@ class GamesOfPeriodResponse(BaseModel): period_start: int = Field(..., description="Начало периода (Unix timestamp)", example=1640995200) period_end: int = Field(..., description="Конец периода (Unix timestamp)", example=1641081600) games_count: int = Field(..., description="Общее количество игр", example=25) + earliest_game_ts: Optional[int] = Field(None, description="Время самой старой найденной партии (Unix timestamp, секунды)", example=1638316800) data: Optional[GamesOfPeriodStats] = Field(None, description="Данные статистики игр") # ============================================================================= diff --git a/LichessWebServices/stats_service.py b/LichessWebServices/stats_service.py index 0a66aa8..1747b87 100644 --- a/LichessWebServices/stats_service.py +++ b/LichessWebServices/stats_service.py @@ -606,6 +606,15 @@ class StatsService: # Обрабатываем игры games_stats = self._process_games_of_period(games, username) + # Определяем время самой старой партии (в секундах) + earliest_game_ts = None + try: + if games: + earliest_game_ts = min(g.get('createdAt', 0) for g in games if isinstance(g.get('createdAt', None), int)) + if earliest_game_ts: + earliest_game_ts = earliest_game_ts // 1000 + except Exception: + earliest_game_ts = None return GamesOfPeriodResponse( message="Статистика игр за период", @@ -613,6 +622,7 @@ class StatsService: period_start=since_timestamp, period_end=until_timestamp, games_count=len(games), + earliest_game_ts=earliest_game_ts, data=games_stats )