From d3b872cd866486fe25f0fe1f72be8a71133627d5 Mon Sep 17 00:00:00 2001 From: Ching L Date: Fri, 5 Sep 2025 17:39:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=AF=94=E5=88=86=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复将日期时间误识别为比分的bug(如"19-00") - 改进比分识别逻辑: - 只在包含"vs"的行中查找比分模式 - 验证比分在合理范围内(0-5) - 排除时间格式的模式 - 更新CHANGELOG记录此修复 🤖 Generated with Claude Code Co-Authored-By: Claude --- CHANGELOG.md | 7 +++++++ sync_dota2_matches.py | 26 ++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bac045..bf277a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## v3.2.1 - 修复比分识别问题 +- **修复错误的比分解析**: + - 修复了将日期时间误识别为比分的问题(如 "19-00") + - 改进比分识别逻辑,只在包含 "vs" 的上下文中查找比分 + - 添加比分范围验证(0-5),排除不合理的数值 + - 增强时间模式识别,避免将时间戳识别为比分 + ## v3.2 - TBD 比赛优化 - **智能去重机制**: - 相同时间、相同轮次的多个 TBD 比赛只保留一个代表 diff --git a/sync_dota2_matches.py b/sync_dota2_matches.py index 6edda69..296b81f 100644 --- a/sync_dota2_matches.py +++ b/sync_dota2_matches.py @@ -108,8 +108,30 @@ class Dota2CalendarSync: text = parent.get_text() # Check if it has a score (completed match) - score_match = re.search(r'(\d+)[-:](\d+)', text) - has_score = score_match and not ('10:00' in text or '13:00' in text or '16:00' in text) + # Look for score patterns specifically in match result context + # Scores are typically between team names, not part of timestamps + score_match = None + has_score = False + + # First check if this looks like a completed match by looking for score indicators + # Split the text to analyze structure better + lines = text.split('\n') + for line in lines: + # Look for patterns like "Team1 2-1 Team2" or "Team1 2:1 Team2" + # Score should be surrounded by team names or 'vs' context + if 'vs' in line.lower(): + # Check for score pattern near 'vs' + score_pattern = re.search(r'(?:^|\s)(\d{1,2})[-:](\d{1,2})(?:\s|$)', line) + if score_pattern: + score1 = int(score_pattern.group(1)) + score2 = int(score_pattern.group(2)) + # Validate it's a reasonable game score (typically 0-5 for Bo5, 0-3 for Bo3) + if 0 <= score1 <= 5 and 0 <= score2 <= 5 and (score1 + score2) > 0: + # Additional check: not a time pattern + if not re.search(r'\d{1,2}:\d{2}(?:\s*[AP]M)?(?:\s*[A-Z]{3,4})?', line): + score_match = score_pattern + has_score = True + break # Extract teams and format vs_pattern = r'([A-Za-z0-9\s\.\-_]+?)vs\(?(Bo\d)\)?([A-Za-z0-9\s\.\-_]+?)(?:TI2025|Round|Playoff|Group|\+|$)'