From 4b6790be14200dfb70fe64b644fdbe993e675159 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Sun, 23 Nov 2025 12:51:14 +0300 Subject: [PATCH] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BD=D0=B0=20=D1=87?= =?UTF-8?q?=D1=83=D0=B2=D1=81=D1=82=D0=B2=D0=B8=D1=82=D0=B5=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=BA=20=D1=80=D0=B5=D0=B3?= =?UTF-8?q?=D0=B8=D1=81=D1=82=D1=80=D1=83=20=D0=B2=20=D0=BD=D0=B8=D0=BA?= =?UTF-8?q?=D0=BD=D0=B5=D0=B9=D0=BC=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LichessClientTG_bot/formatters.py | 40 +++++++++++++++++-------- LichessWebServices/stats_service.py | 34 ++++++++++++++++----- LichessWebView/auth_config.example.json | 1 + LichessWebView/auth_config.py | 1 + 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/LichessClientTG_bot/formatters.py b/LichessClientTG_bot/formatters.py index 26b24ad..e0bf77d 100644 --- a/LichessClientTG_bot/formatters.py +++ b/LichessClientTG_bot/formatters.py @@ -126,25 +126,41 @@ class StatsFormatter: result = t('period_notification_title', lang, username=username, period_text=period_text) # Format puzzles first (if available and there's actual activity) - if puzzles_data and puzzles_data.get('data'): - puzzles_info = puzzles_data['data'] - total_puzzles = puzzles_info.get('total_attempts', 0) - solved = puzzles_info.get('solved', 0) - failed = puzzles_info.get('failed', 0) - - # Only show tasks section if there's actual activity (not all zeros) - if total_puzzles > 0 or solved > 0 or failed > 0: - result += t('period_puzzles_section', lang, total=total_puzzles, solved=solved, failed=failed) + has_puzzles_data = False + if puzzles_data: + # Check puzzles_in_period on top level first (priority) + top_level_puzzles = puzzles_data.get('puzzles_in_period', 0) + # Also check data.total_attempts + if puzzles_data.get('data'): + puzzles_info = puzzles_data['data'] + total_puzzles = puzzles_info.get('total_attempts', 0) + solved = puzzles_info.get('solved', 0) + failed = puzzles_info.get('failed', 0) + + effective_puzzles = top_level_puzzles if top_level_puzzles > 0 else total_puzzles + + # Only show tasks section if there's actual activity (not all zeros) + if effective_puzzles > 0 or solved > 0 or failed > 0: + has_puzzles_data = True + result += t('period_puzzles_section', lang, total=effective_puzzles, solved=solved, failed=failed) # Format games + has_games_data = False if games_data and games_data.get('data'): games_info = games_data['data'] + # Check games_count on top level first (priority) + top_level_games_count = games_data.get('games_count', 0) + # Also check data.total.games_played total_games = games_info.get('total', {}).get('games_played', 0) + # Use top-level games_count if available, otherwise use total.games_played + effective_games_count = top_level_games_count if top_level_games_count > 0 else total_games + # Show details for each game type if there were games - if total_games > 0: + if effective_games_count > 0: for game_type, game_data in games_info.items(): if game_type != 'total' and game_data and game_data.get('games_played', 0) > 0: + has_games_data = True # Only set to True if we actually add game data emoji = StatsFormatter._get_game_type_emoji(game_type) games_count = game_data.get('games_played', 0) rating_change = game_data.get('rating_change', 0) @@ -167,8 +183,8 @@ class StatsFormatter: draws=draws ) - # If no activity - if not (games_data and games_data.get('data')) and not (puzzles_data and puzzles_data.get('data')): + # If no activity at all + if not has_games_data and not has_puzzles_data: result += t('no_activity', lang) return result.rstrip() diff --git a/LichessWebServices/stats_service.py b/LichessWebServices/stats_service.py index bbc0bb1..b699d5f 100644 --- a/LichessWebServices/stats_service.py +++ b/LichessWebServices/stats_service.py @@ -459,11 +459,15 @@ class StatsService: winner = game.get('winner') players = game.get('players', {}) - # Определяем цвет игрока + # Определяем цвет игрока (сравниваем имена без учета регистра) + username_lower = username.lower() user_color = None - if players.get('white', {}).get('user', {}).get('name') == username: + white_name = players.get('white', {}).get('user', {}).get('name', '') + black_name = players.get('black', {}).get('user', {}).get('name', '') + + if white_name.lower() == username_lower: user_color = 'white' - elif players.get('black', {}).get('user', {}).get('name') == username: + elif black_name.lower() == username_lower: user_color = 'black' if user_color is None: @@ -483,11 +487,15 @@ class StatsService: """ players = game.get('players', {}) - # Определяем цвет игрока + # Определяем цвет игрока (сравниваем имена без учета регистра) + username_lower = username.lower() user_color = None - if players.get('white', {}).get('user', {}).get('name') == username: + white_name = players.get('white', {}).get('user', {}).get('name', '') + black_name = players.get('black', {}).get('user', {}).get('name', '') + + if white_name.lower() == username_lower: user_color = 'white' - elif players.get('black', {}).get('user', {}).get('name') == username: + elif black_name.lower() == username_lower: user_color = 'black' if user_color is None: @@ -546,18 +554,30 @@ class StatsService: # Сортируем игры по времени создания (от старых к новым) для правильного вычисления итогового рейтинга sorted_games = sorted(games, key=lambda x: x.get('createdAt', 0)) - for game in sorted_games: + logger.info(f"🔍 Processing {len(sorted_games)} games for {username}") + + for idx, game in enumerate(sorted_games): speed = game.get('speed', 'unknown') + game_id = game.get('id', 'unknown') + + logger.debug(f"🔍 Game {idx+1}/{len(sorted_games)}: id={game_id}, speed={speed}, username={username}") # Пропускаем неизвестные типы игр if speed not in stats: + logger.warning(f"⚠️ Skipping game {game_id}: unknown speed '{speed}' (expected: bullet, blitz, rapid, classical, correspondence)") continue # Определяем результат игры result = self._determine_game_result(game, username) if result == 'unknown': + players = game.get('players', {}) + white_name = players.get('white', {}).get('user', {}).get('name', 'N/A') + black_name = players.get('black', {}).get('user', {}).get('name', 'N/A') + logger.warning(f"⚠️ Skipping game {game_id}: cannot determine result for username '{username}' (white: '{white_name}', black: '{black_name}')") continue + logger.debug(f"✅ Processing game {game_id}: speed={speed}, result={result}") + # Получаем изменение рейтинга и итоговый рейтинг rating_change, final_rating = self._get_rating_info(game, username) diff --git a/LichessWebView/auth_config.example.json b/LichessWebView/auth_config.example.json index a33c8e2..642bee2 100644 --- a/LichessWebView/auth_config.example.json +++ b/LichessWebView/auth_config.example.json @@ -11,3 +11,4 @@ ] } + diff --git a/LichessWebView/auth_config.py b/LichessWebView/auth_config.py index f44caaa..e72e086 100644 --- a/LichessWebView/auth_config.py +++ b/LichessWebView/auth_config.py @@ -58,3 +58,4 @@ def validate_credentials(username: str, password: str) -> bool: return False +