修复OCR时间戳拼接污染:过去日期+新鲜时间戳放行给DB查重

This commit is contained in:
youpaishidifu
2026-08-24 13:48:09 +08:00
parent b83556f37f
commit f74e59845e
+33 -1
View File
@@ -6377,7 +6377,39 @@ class MessageMonitor:
else:
unclear_date = True
if clear_date:
# 清晰年月日:历史消息特征 → 整段丢弃
# 清晰年月日:检查日期是否为过去
has_past = False
has_today = False
for date_str in dates:
try:
parts = date_str.split('/')
y, m, d = int(parts[0]), int(parts[1]), int(parts[2])
date_obj = datetime(y, m, d).date()
date_diff = (today - date_obj).days
if date_diff > 0:
has_past = True
elif date_diff == 0:
has_today = True
except (ValueError, IndexError):
pass
if has_today:
# 有今天日期:历史消息特征 → 整段丢弃
logger.debug(f"[ocr] 过滤器1结果: 检测到今天日期,丢弃历史消息: {text[:80]!r}")
return False
if has_past:
# 有过去日期:检查是否有新鲜时间戳(可能OCR拼接了今天的独立时间戳)
if timestamps:
for ts in timestamps:
try:
if not self._is_timestamp_old(ts, 300):
logger.debug(f"[ocr] 过滤器1结果: 过去日期+新鲜时间戳{ts}(≤300s),放行")
return True
except Exception:
pass
# 无新鲜时间戳:丢弃
logger.debug(f"[ocr] 过滤器1结果: 过去日期+无新鲜时间戳,丢弃: {text[:80]!r}")
return False
# 其他情况:丢弃(理论上不会到这里)
logger.debug(f"[ocr] 过滤器1结果: 检测到清晰年月日,丢弃历史消息: {text[:80]!r}")
return False
elif unclear_date: