修复Task #1738:OCR误识时间戳导致历史消息被放行
根因分析: - OCR将UI乱码":1:1:--"中的"1:1"误识别为时间戳 - "1:1"无法解析(分钟只有1位),返回-999.0 - 第二遍继承逻辑让无时间戳的历史消息继承了最新一条消息的新鲜度5.0 - 第一关检查只判断item是否为tuple,无法区分"自身时间戳"和"继承获得的新鲜度" - 导致历史消息被误判为"有自身新鲜时间戳"直接放行,同轮处理多条消息 修复方案: 1. 在第二遍继承时记录所有通过继承获得新鲜度的消息到_inherited_fresh_set 2. 第一关检查时,如果消息在_inherited_fresh_set中,视为"非自身时间戳",走第二关DB查库路径 3. 历史消息将被正确拦截,不再与真实新消息混合处理 4. 添加调试日志便于后续追踪
This commit is contained in:
+10
-1
@@ -10330,6 +10330,8 @@ class MessageMonitor:
|
|||||||
if freshness_score != -999.0:
|
if freshness_score != -999.0:
|
||||||
_ts_positions.append((idx, freshness_score))
|
_ts_positions.append((idx, freshness_score))
|
||||||
|
|
||||||
|
# ⭐ 记录通过继承获得新鲜度的消息(防止误判为"自身时间戳")
|
||||||
|
_inherited_fresh_set = set()
|
||||||
# 第二遍:为无时间戳的消息分配最近时间戳的新鲜度
|
# 第二遍:为无时间戳的消息分配最近时间戳的新鲜度
|
||||||
for idx, item in enumerate(texts):
|
for idx, item in enumerate(texts):
|
||||||
# 解包元组 (text, timestamp)
|
# 解包元组 (text, timestamp)
|
||||||
@@ -10378,6 +10380,8 @@ class MessageMonitor:
|
|||||||
f"(pos {idx} <- ts pos {_actual_pos}): "
|
f"(pos {idx} <- ts pos {_actual_pos}): "
|
||||||
f"{best_freshness:.1f}: {ts[:20]!r}")
|
f"{best_freshness:.1f}: {ts[:20]!r}")
|
||||||
freshness_scores[ts] = best_freshness
|
freshness_scores[ts] = best_freshness
|
||||||
|
# ⭐ 记录此消息通过继承获得新鲜度,第一关需排除
|
||||||
|
_inherited_fresh_set.add(ts)
|
||||||
# else: 整批无时间戳,保持-999.0
|
# else: 整批无时间戳,保持-999.0
|
||||||
|
|
||||||
# === 所有消息都必须经过过滤器(不再跳过) ===
|
# === 所有消息都必须经过过滤器(不再跳过) ===
|
||||||
@@ -11102,11 +11106,16 @@ class MessageMonitor:
|
|||||||
# 第一关:有5分钟内新鲜时间戳(自身时间戳,不是继承的)
|
# 第一关:有5分钟内新鲜时间戳(自身时间戳,不是继承的)
|
||||||
# 第二关:没有新鲜时间戳 → 查库
|
# 第二关:没有新鲜时间戳 → 查库
|
||||||
_is_inherited_ts = isinstance(item, tuple) and len(item) == 2 and item[1] is not None
|
_is_inherited_ts = isinstance(item, tuple) and len(item) == 2 and item[1] is not None
|
||||||
|
# ⭐ Task #1738: 额外检查是否通过第二遍继承获得新鲜度
|
||||||
|
_is_inherited_fresh = cleaned_item in _inherited_fresh_set if _inherited_fresh_set else False
|
||||||
|
if _is_inherited_fresh:
|
||||||
|
logger.debug(f"[{platform}] 消息通过继承获得新鲜度,第一关不通过: {cleaned_item[:50]!r}")
|
||||||
|
|
||||||
|
|
||||||
# 第一关:检查是否有5分钟内的新鲜时间戳(自身时间戳)
|
# 第一关:检查是否有5分钟内的新鲜时间戳(自身时间戳)
|
||||||
# freshness_score >= 5 表示时间戳在5分钟内
|
# freshness_score >= 5 表示时间戳在5分钟内
|
||||||
# 但必须是自身时间戳,不是继承的
|
# 但必须是自身时间戳,不是继承的
|
||||||
_has_fresh_own_ts = (freshness_score >= 5) and not _is_inherited_ts
|
_has_fresh_own_ts = (freshness_score >= 5) and not _is_inherited_ts and not _is_inherited_fresh
|
||||||
if _has_fresh_own_ts:
|
if _has_fresh_own_ts:
|
||||||
# 第一关通过:有5分钟内新鲜时间戳(自身时间戳)
|
# 第一关通过:有5分钟内新鲜时间戳(自身时间戳)
|
||||||
old_score = score
|
old_score = score
|
||||||
|
|||||||
Reference in New Issue
Block a user