refactor(gui_core): 抽 _update_stats_from_line 解析逻辑到 stats_log_parser (1207 → 541)

Runner._update_stats_from_line 是 666 行的"日志行 → 计数器更新"巨型方法。
按业务事件分类 14 个独立段(福袋字段 / 打开-参与计数器 / 跳过原因 /
错误统计 / 粉丝团 / 预约 / 开奖结果 / 直播间切换 / 阶段诊断 / OCR / 性能 /
详情识别 / 福袋查找 / 回退操作)。

抽到 gui/gui_core_pkg/stats_log_parser.py:
- update_stats_from_line(runner, line) 主入口
- 14 个 _parse_* 子函数按事件分组
- 通过 runner.* 调用保持与原 Runner 方法/状态一致

Runner._update_stats_from_line 从 666 行变成 4 行委托。模块级测试更易于
单独覆盖各分类的解析逻辑。

1408 passed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
CodexandClaude Opus 4.7 committed 2026-05-23 03:35:04 +08:00
1 parent fb35670032
commit 3b8f85b9cb
2 files changed
+736 -666

No files matched your search

+3 -666
View File
@@ -152,672 +152,9 @@ class Runner:
}
def _update_stats_from_line(self, line: str) -> None:
s = (line or "").strip()
if not s:
return
with self._lock:
self._last_log_ts = time.time()
# --- 福袋:抽取"最近一次"识别到的信息 ---
# 支持多种格式:旧格式"福袋内容:"和新格式"字段_内容="或"内容="
content_extracted = False
room_title = ""
if "福袋内容:" in s:
with self._lock:
self._fudai_last["content"] = (
s.split("福袋内容:", 1)[1].strip().split()[0]
) # 只取第一个词,避免包含后续字段
self._fudai_last["updated_ts"] = time.time()
content_extracted = True
else:
# 新格式:字段_内容= 或 内容=
m = re.search(r"(?:字段_)?内容[=:]\s*([^\s]+)", s)
if m:
with self._lock:
self._fudai_last["content"] = m.group(1).strip()
self._fudai_last["updated_ts"] = time.time()
content_extracted = True
# 提取直播间标题
m = re.search(r"room_title[=:]\s*([^\s,]+)", s)
if m:
room_title = m.group(1).strip()
if content_extracted:
fudai_content = self._fudai_last.get("content", "")
key = (room_title, fudai_content)
if key not in self._recorded_fudai_seen:
self._recorded_fudai_seen.add(key)
self._inc("fudai_seen")
self._record_event("fudai_seen", self._snapshot_fudai())
# 唯一口径:优先按当前直播间位置去重(每个直播间只记一次),回退到 content/prize/countdown 三元组
try:
if self._current_room_pos is not None:
try:
rp = int(self._current_room_pos)
except Exception:
rp = None
if rp is not None and rp not in self._fudai_seen_room_pos:
self._fudai_seen_room_pos.add(rp)
self._inc("fudai_seen_unique")
else:
key = self._make_unique_key()
if key and key not in self._unique_keys_seen:
self._unique_keys_seen.add(key)
self._inc("fudai_seen_unique")
except Exception:
pass
# 参与人数:支持多种格式
m = re.search(r"(?:字段_)?参与人数[=:]?\s*(\d+)", s)
if not m:
m = re.search(r"参与人数:\s*(\d+)", s)
if m:
with self._lock:
self._fudai_last["participants"] = int(m.group(1))
self._fudai_last["updated_ts"] = time.time()
# 福袋份数:支持多种格式
m = re.search(r"(?:字段_)?份数[=:]?\s*(\d+)", s)
if not m:
m = re.search(r"福袋份数:\s*(\d+)", s)
if m:
with self._lock:
self._fudai_last["copies"] = int(m.group(1))
self._fudai_last["updated_ts"] = time.time()
# 倒计时:支持多种格式
if "倒计时时间:" in s:
with self._lock:
self._fudai_last["countdown"] = (
s.split("倒计时时间:", 1)[1].strip().split()[0]
)
self._fudai_last["updated_ts"] = time.time()
else:
m = re.search(r"(?:字段_)?倒计时[=:]?\s*([^\s]+)", s)
if m:
with self._lock:
self._fudai_last["countdown"] = m.group(1).strip()
self._fudai_last["updated_ts"] = time.time()
# 奖品价值:支持多种格式
m = re.search(
r"(?:字段_)?(?:价值|价值元|奖品价值)[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)",
s,
)
if not m:
m = re.search(
r"奖品价值:\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)\s*元", s
)
if m:
try:
with self._lock:
self._fudai_last["prize_value_yuan"] = float(m.group(1))
self._fudai_last["updated_ts"] = time.time()
except Exception:
pass
# --- 福袋:关键流程计数 ---
if "点击打开福袋详情" in s or ("[流程]" in s and "检测到福袋图标并点击" in s):
self._inc("fudai_open_detail")
self._record_event("fudai_open_detail", self._snapshot_fudai())
try:
key = self._make_unique_key()
if key and key not in self._unique_keys_open:
self._unique_keys_open.add(key)
self._inc("fudai_open_detail_unique")
except Exception:
pass
if "点击参与抽奖" in s or (
"[参与]" in s and ("动作=点击参与" in s or "动作=参与" in s)
):
self._inc("fudai_click_attend")
self._record_event("fudai_click_attend", self._snapshot_fudai())
try:
key = self._make_unique_key()
if key and key not in self._unique_keys_attend:
self._unique_keys_attend.add(key)
self._inc("fudai_click_attend_unique")
except Exception:
pass
# 参与成功/已参与:支持更多格式
if (
"已经参与,等待开奖" in s
or "已经参与,等待看播时间凑齐开奖" in s
or "已参与成功(或看播中)" in s
or (
"[参与]" in s
and ("结果=已参与" in s or "结果=看播中" in s or "结果=参与成功" in s)
)
or ("[参与]" in s and "已参与" in s and "等待开奖" in s)
or ("预约回退后直接参与" in s and "参与成功" in s)
):
self._inc("fudai_attend_ok")
self._record_event("fudai_attend_ok", self._snapshot_fudai())
try:
# 优先按直播间去重
if self._current_room_pos is not None:
try:
rp = int(self._current_room_pos)
except Exception:
rp = None
if rp is not None and rp not in self._fudai_attend_ok_room_pos:
self._fudai_attend_ok_room_pos.add(rp)
self._inc("fudai_attend_ok_unique")
else:
key = self._make_unique_key()
if key and key not in self._unique_keys_attend:
self._unique_keys_attend.add(key)
self._inc("fudai_attend_ok_unique")
except Exception:
pass
if "参与抽奖失败" in s or ("[参与]" in s and "结果=失败" in s):
self._inc("fudai_attend_fail")
self._record_event("fudai_attend_fail", self._snapshot_fudai())
try:
# 优先按直播间去重
if self._current_room_pos is not None:
try:
rp = int(self._current_room_pos)
except Exception:
rp = None
if rp is not None and rp not in self._fudai_attend_fail_room_pos:
self._fudai_attend_fail_room_pos.add(rp)
self._inc("fudai_attend_fail_unique")
else:
# 回退到 key 去重(使用相同的 unique_keys_attend 集合)
try:
key = self._make_unique_key()
if key and key not in self._unique_keys_attend:
self._unique_keys_attend.add(key)
self._inc("fudai_attend_fail_unique")
except Exception:
pass
except Exception:
pass
# --- 福袋:跳过/过滤原因 ---
if "参与人数" in s and "< 阈值" in s and "不参与" in s:
self._inc("fudai_skip_participants_low")
# 提取实际参与人数和阈值
meta = self._snapshot_fudai()
m = re.search(r"参与人数[=:]?\s*(\d+)", s)
if m:
try:
meta["participants"] = int(m.group(1))
except Exception:
pass
m = re.search(r"阈值[=:]?\s*(\d+)", s)
if m:
try:
meta["threshold"] = int(m.group(1))
except Exception:
pass
self._record_event("fudai_skip", {"reason": "participants_low", **meta})
if "参与人数" in s and "> 阈值" in s and "不参与" in s:
self._inc("fudai_skip_participants_high")
# 提取实际参与人数和阈值
meta = self._snapshot_fudai()
m = re.search(r"参与人数[=:]?\s*(\d+)", s)
if m:
try:
meta["participants"] = int(m.group(1))
except Exception:
pass
m = re.search(r"阈值[=:]?\s*(\d+)", s)
if m:
try:
meta["threshold"] = int(m.group(1))
except Exception:
pass
self._record_event("fudai_skip", {"reason": "participants_high", **meta})
if "奖品价值" in s and "< 阈值" in s and "不参与" in s:
self._inc("fudai_skip_value_low")
# 提取实际价值和阈值
meta = self._snapshot_fudai()
m = re.search(
r"(?:奖品)?价值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s
)
if m:
try:
meta["prize_value_yuan"] = float(m.group(1))
except Exception:
pass
m = re.search(
r"阈值[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)", s
)
if m:
try:
meta["threshold"] = float(m.group(1))
except Exception:
pass
self._record_event("fudai_skip", {"reason": "value_low", **meta})
if "福袋内容不理想" in s or ("[筛选]" in s and "内容" in s and "黑名单" in s):
self._inc("fudai_skip_content")
self._record_event(
"fudai_skip", {"reason": "content", **self._snapshot_fudai()}
)
if "抽奖倒计时时间小于" in s and "不参与" in s:
self._inc("fudai_skip_countdown_short")
# 提取倒计时秒数
meta = self._snapshot_fudai()
m = re.search(r"(\d+)\s*秒", s)
if m:
try:
meta["countdown_seconds"] = int(m.group(1))
except Exception:
pass
self._record_event("fudai_skip", {"reason": "countdown_short", **meta})
if "抽奖倒计时时间大于" in s and "暂不参与" in s:
self._inc("fudai_skip_countdown_long")
# 提取倒计时秒数
meta = self._snapshot_fudai()
m = re.search(r"(\d+)\s*秒", s)
if m:
try:
meta["countdown_seconds"] = int(m.group(1))
except Exception:
pass
self._record_event("fudai_skip", {"reason": "countdown_long", **meta})
if (
"需要看播时长:默认不参与" in s
or "需要开始观看/看播门槛:默认不参与" in s
or ("[参与]" in s and "结果=看播门槛" in s)
):
self._inc("fudai_skip_watch_required")
self._record_event(
"fudai_skip", {"reason": "watch_required", **self._snapshot_fudai()}
)
if "打开福袋异常" in s or ("[流程]" in s and "打开福袋异常" in s):
self._inc("fudai_open_error")
self._record_event("fudai_open_error", self._snapshot_fudai())
if "超过10次点击福袋无法打开详情" in s:
self._inc("fudai_open_error_too_many")
self._record_event("fudai_open_error_too_many", self._snapshot_fudai())
# 倒计时大于阈值但价值达到高价值阈值,记录预约
if (
"[流程]" in s and "倒计时大于阈值,但价值达到高价值阈值,记录预约" in s
) or ("[参与]" in s and "倒计时大于阈值,但价值达到高价值阈值,记录预约" in s):
self._inc("fudai_reserved_high_value")
# 提取价值和倒计时信息
meta = self._snapshot_fudai()
m = re.search(
r"(?:价值|价值元)[=:]?\s*([0-9]+(?:[.\u00B7\uFF0E\uFF61·.。][0-9]+)?)",
s,
)
if m:
try:
meta["prize_value_yuan"] = float(m.group(1))
except Exception:
pass
m = re.search(r"(?:剩余|倒计时)[=:]?\s*(\d+)\s*秒", s)
if m:
try:
meta["remain_seconds"] = int(m.group(1))
except Exception:
pass
self._record_event("fudai_reserved_high_value", meta)
# --- 错误和异常统计 ---
if "[错误]" in s or "[异常]" in s or "错误=" in s or "异常=" in s:
self._inc("error_total")
# 提取错误类型
error_type = "unknown"
if "UnboundLocalError" in s:
error_type = "UnboundLocalError"
self._inc("error_unbound_local")
elif "AttributeError" in s:
error_type = "AttributeError"
self._inc("error_attribute")
elif "KeyError" in s:
error_type = "KeyError"
self._inc("error_key")
elif "ValueError" in s:
error_type = "ValueError"
self._inc("error_value")
elif "TypeError" in s:
error_type = "TypeError"
self._inc("error_type")
elif "TimeoutError" in s or "超时" in s:
error_type = "TimeoutError"
self._inc("error_timeout")
elif "ConnectionError" in s or "连接" in s and "失败" in s:
error_type = "ConnectionError"
self._inc("error_connection")
elif "OCR" in s and ("失败" in s or "错误" in s):
error_type = "OCR_Error"
self._inc("error_ocr")
elif "截图" in s and ("失败" in s or "错误" in s):
error_type = "Screenshot_Error"
self._inc("error_screenshot")
elif "识别" in s and ("失败" in s or "错误" in s):
error_type = "Detection_Error"
self._inc("error_detection")
self._record_event("error", {"error_type": error_type})
# --- 阶段诊断错误 ---
if "阶段诊断" in s and ("失败" in s or "错误" in s or "异常" in s):
self._inc("error_stage_diagnosis")
self._record_event("error_stage_diagnosis", {})
# --- 详情读取错误 ---
if "读取福袋详情" in s and ("失败" in s or "错误" in s or "异常" in s):
self._inc("error_read_detail")
self._record_event("error_read_detail", {})
# --- 配置加载错误 ---
if "load_config" in s and ("失败" in s or "错误" in s or "异常" in s):
self._inc("error_config_load")
self._record_event("error_config_load", {})
# --- 状态文件错误 ---
if ("预约队列状态文件" in s or "reservations.json" in s) and (
"失败" in s or "错误" in s
):
self._inc("error_state_file")
self._record_event("error_state_file", {})
# --- 直播间检测错误 ---
if "直播间检测" in s and ("失败" in s or "错误" in s):
self._inc("error_live_room_detect")
self._record_event("error_live_room_detect", {})
# --- 福袋查找错误 ---
if "查找福袋" in s and ("失败" in s or "错误" in s or "未找到" in s):
self._inc("error_fudai_find")
self._record_event("error_fudai_find", {})
# --- 粉丝团门槛 ---
if "需要加入粉丝团才能参与" in s or ("[参与]" in s and "结果=需要粉丝团" in s):
self._inc("fansclub_required")
self._record_event("fansclub_required", self._snapshot_fudai())
if "未启用自动加入粉丝团" in s:
self._inc("fansclub_manual_needed")
self._record_event("fansclub_manual_needed", self._snapshot_fudai())
if "粉丝团门槛仍未解决" in s or ("[参与]" in s and "粉丝团门槛仍未解决" in s):
self._inc("fansclub_unresolved")
self._record_event("fansclub_unresolved", self._snapshot_fudai())
# --- 预约队列/回退校验 ---
if (
"[预约]" in s and "回退校验通过" in s
) or "回退校验通过:已回到目标直播间" in s:
self._inc("reservation_back_verify_ok")
self._record_event("reservation_back_verify_ok", {})
if ("[预约]" in s and "回退校验失败" in s) or "回退校验失败" in s:
self._inc("reservation_back_verify_fail")
self._record_event("reservation_back_verify_fail", {})
if (
"[预约]" in s and "预约队列已满,丢弃最低价值" in s
) or "预约队列已满,丢弃最低价值" in s:
self._inc("reservation_drop_low_value")
self._record_event("reservation_drop_low_value", {})
if ("[预约]" in s and "清空预约队列" in s) or "清空预约队列" in s:
self._inc("reservation_clear")
self._record_event("reservation_clear", {})
# --- 预约记录相关 ---
if (
"[预约]" in s and "已记录高价值福袋" in s
) or "record_high_value_reservation:已记录高价值福袋" in s:
self._inc("reservation_recorded")
# 提取预约价值:支持多种格式
value = None
m = re.search(r"(?:字段_)?(?:价值|价值元|value)[=:]?\s*(\d+(?:\.\d+)?)", s)
if not m:
m = re.search(r"value[=:]?\s*(\d+(?:\.\d+)?)", s)
if m:
try:
value = float(m.group(1))
except Exception:
pass
# 提取开奖时间
future_ts = None
m = re.search(r"(?:字段_)?(?:开奖时间|future|future_ts)[=:]?\s*(\d+)", s)
if m:
try:
future_ts = int(m.group(1))
except Exception:
pass
# 提取直播间名称
room_title = None
m = re.search(
r"(?:字段_)?(?:直播间|直播间名|room_title)[=:]?\s*([^\s]+)", s
)
if m:
room_title = m.group(1).strip()
meta = self._snapshot_fudai()
if value is not None:
meta["prize_value_yuan"] = value
if future_ts is not None:
meta["future_ts"] = future_ts
if room_title:
meta["room_title"] = room_title
self._record_event("reservation_recorded", meta)
if (
"[预约]" in s and "进入预约参与窗口" in s
) or "进入预约参与窗口,准备回退到目标直播间" in s:
self._inc("reservation_window_entered")
self._record_event("reservation_window_entered", {})
if (
("[预约]" in s and "已回退到目标直播间" in s)
or "已回退到目标直播间" in s
or ("[预约]" in s and "已回退到最早开奖的预约直播间" in s)
):
self._inc("reservation_back_success")
# 提取回退信息
meta = {}
m = re.search(r"(?:字段_)?(?:需回退次数|back_times)[=:]?\s*(\d+)", s)
if m:
try:
meta["back_times"] = int(m.group(1))
except Exception:
pass
self._record_event("reservation_back_success", meta)
if ("[预约]" in s and "时间窗口未到" in s) or "时间窗口未到,跳过回退" in s:
self._inc("reservation_window_not_reached")
self._record_event("reservation_window_not_reached", {})
if (
"[预约]" in s and "已明显错过开奖时间" in s
) or "已明显错过开奖时间,清理过期预约" in s:
self._inc("reservation_expired")
self._record_event("reservation_expired", {})
if (
"[预约]" in s and "预约队列为空" in s
) or "process_reservation_attend_window:预约队列为空" in s:
self._inc("reservation_queue_empty")
if ("[预约]" in s and "锁定期未结束" in s) or "锁定期未结束" in s:
self._inc("reservation_locked")
self._record_event("reservation_locked", {})
if "[预约]" in s and "已回退到第一个直播间" in s:
self._inc("reservation_back_to_first")
self._record_event("reservation_back_to_first", {})
if "[预约]" in s and "run_once_basic:检查预约回退触发条件" in s:
self._inc("reservation_check_triggered")
# 预约队列满时等待
if (
("[预约]" in s and "队列已满" in s)
or "handle_queue_full_wait_at_earliest" in s
or ("[预约]" in s and "队列已满,回退到最早开奖的预约直播间" in s)
):
self._inc("reservation_queue_full_wait")
self._record_event("reservation_queue_full_wait", {})
# 回退后直接参与
if ("[预约]" in s and "预约回退后直接参与" in s) or "预约回退后直接参与" in s:
self._inc("reservation_back_direct_attend")
self._record_event("reservation_back_direct_attend", {})
# 队列满回退后设置参与标志
if "[预约]" in s and "队列满回退后,直接设置参与标志" in s:
self._inc("reservation_queue_full_back_attend")
self._record_event("reservation_queue_full_back_attend", {})
# 通过相似度匹配识别重复预约
if "[预约]" in s and "通过相似度匹配识别为重复预约" in s:
self._inc("reservation_duplicate_detected")
self._record_event("reservation_duplicate_detected", {})
# --- 开奖结果 ---
if "没有抽中" in s and "关闭弹窗" in s:
self._inc("fudai_result_no_win")
self._record_event("fudai_result_no_win", self._snapshot_fudai())
if (
"恭喜中奖了" in s
or "检测到中奖结果" in s
or ("[开奖结果]" in s and "中奖" in s)
):
self._inc("fudai_result_win")
# 提取中奖信息
meta = self._snapshot_fudai()
m = re.search(r"(?:奖品|商品)[=:]?\s*([^\s]+)", s)
if m:
meta["prize"] = m.group(1).strip()
self._record_event("fudai_result_win", meta)
self._record_win()
if "福袋商品下单成功" in s or ("[开奖结果]" in s and "下单成功" in s):
self._inc("fudai_order_success")
self._record_event("fudai_order_success", self._snapshot_fudai())
# 等待开奖(只在设置等待开奖标志时计数,避免重复计数)
# 注意:不要匹配"已经参与,等待开奖",因为那已经在参与成功时计数了
if ("[参与]" in s and "参与成功,设置等待开奖标志" in s) or (
"[参与]" in s and "设置等待开奖标志" in s
):
self._inc("fudai_waiting_lottery")
# 提取剩余秒数
meta = self._snapshot_fudai()
m = re.search(r"(?:剩余|倒计时|remain_seconds)[=:]?\s*(\d+)", s)
if m:
try:
meta["remain_seconds"] = int(m.group(1))
except Exception:
pass
self._record_event("fudai_waiting_lottery", meta)
# --- 直播间切换(按原因粗分) ---
if "上划切换直播间" in s or ("[操作]" in s and "上滑切换直播间" in s):
self._inc("switch_room")
meta_reason = "unknown"
if "无福袋" in s:
self._inc("switch_room_no_fudai")
meta_reason = "no_fudai"
elif "参与人数" in s:
self._inc("switch_room_participants")
meta_reason = "participants"
elif "奖品价值" in s:
self._inc("switch_room_value")
meta_reason = "value"
elif "内容不理想" in s:
self._inc("switch_room_content")
meta_reason = "content"
elif "倒计时" in s:
self._inc("switch_room_countdown")
meta_reason = "countdown"
elif "参与抽奖失败" in s:
self._inc("switch_room_attend_fail")
meta_reason = "attend_fail"
elif "记录预约后" in s:
self._inc("switch_room_after_reservation")
meta_reason = "after_reservation"
elif "锁定期内" in s:
self._inc("switch_room_locked")
meta_reason = "locked"
self._record_event(
"switch_room", {"reason": meta_reason, **self._snapshot_fudai()}
)
# --- 阶段诊断统计 ---
if "[阶段诊断]" in s or "阶段诊断" in s:
if "阶段诊断完成" in s:
self._inc("stage_diagnosis_complete")
# 提取阶段和耗时
meta = {}
m = re.search(r"阶段[=:]?\s*(\w+)", s)
if m:
meta["stage"] = m.group(1)
m = re.search(r"耗时[=:]?\s*([0-9]+(?:\.[0-9]+)?)\s*秒", s)
if m:
try:
meta["elapsed_seconds"] = float(m.group(1))
except Exception:
pass
m = re.search(r"分数[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s)
if m:
try:
meta["score"] = float(m.group(1))
except Exception:
pass
self._record_event("stage_diagnosis_complete", meta)
elif "阶段诊断失败" in s or "阶段诊断错误" in s:
self._inc("stage_diagnosis_failed")
self._record_event("stage_diagnosis_failed", {})
# --- OCR识别统计 ---
if "[福袋]" in s and "OCR识别" in s:
self._inc("ocr_attempt")
if "识别成功" in s or "识别完成" in s:
self._inc("ocr_success")
elif "识别失败" in s or "识别错误" in s:
self._inc("ocr_failed")
# --- 性能统计 ---
m = re.search(r"耗时[=:]?\s*([0-9]+(?:\.[0-9]+)?)\s*秒", s)
if m:
try:
elapsed = float(m.group(1))
# 记录耗时较长的操作
if elapsed > 5.0:
self._inc("slow_operation")
self._record_event(
"slow_operation",
{"elapsed_seconds": elapsed, "operation": s[:100]},
)
except Exception:
pass
# --- 详情识别统计 ---
if ("[福袋详情]" in s and "识别" in s) or "识别福袋详情" in s:
self._inc("fudai_detail_read_attempt")
if (
"识别成功" in s
or "识别完成" in s
or "read_fudai_detail_once完成(成功)" in s
):
self._inc("fudai_detail_read_success")
# 提取任务数量
meta = {}
m = re.search(r"(?:任务数量|task_count)[=:]?\s*(\d+)", s)
if m:
try:
meta["task_count"] = int(m.group(1))
except Exception:
pass
self._record_event("fudai_detail_read_success", meta)
elif "识别失败" in s or "识别错误" in s:
self._inc("fudai_detail_read_failed")
self._record_event("fudai_detail_read_failed", {})
# --- 福袋查找统计 ---
if "[福袋查找]" in s or "查找福袋" in s:
if "检测完成" in s and "命中" in s:
self._inc("fudai_find_success")
elif "检测完成" in s and "未找到" in s:
self._inc("fudai_find_not_found")
elif "等待超时" in s:
self._inc("fudai_find_timeout")
# --- 回退操作统计 ---
if ("[预约]" in s and "回退" in s) or "回退到" in s:
if "回退完成" in s or "回退成功" in s:
self._inc("reservation_back_operation")
# 提取回退次数
meta = {}
m = re.search(r"(?:回退|back_times)[=:]?\s*(\d+)", s)
if m:
try:
meta["back_times"] = int(m.group(1))
except Exception:
pass
self._record_event("reservation_back_operation", meta)
"""委托到 gui/gui_core_pkg/stats_log_parser.update_stats_from_line。"""
from gui.gui_core_pkg.stats_log_parser import update_stats_from_line
update_stats_from_line(self, line)
def get_stats(self) -> dict:
with self._lock:
+733
View File
@@ -0,0 +1,733 @@
"""gui/gui_core_pkg/stats_log_parser - 把日志行解析成 Runner 统计计数器更新
从 Runner._update_stats_from_line 抽出的 666 行纯字符串解析逻辑。基本上是
按"如果包含某关键词则 self._inc(counter)"的模式罗列各种业务事件统计。
所有 self.* 调用通过传入的 runner 参数(保持与原 Runner 的方法名一致):
- runner._inc(counter_name)
- runner._record_event(typ, meta)
- runner._make_unique_key()
- runner._snapshot_fudai()
- runner._record_win()
- runner._lock / _last_log_ts / _fudai_last / _current_room_pos
- runner._unique_keys_seen / _unique_keys_open / _unique_keys_attend
- runner._fudai_seen_room_pos / _fudai_attend_ok_room_pos / _fudai_attend_fail_room_pos
- runner._recorded_fudai_seen
入口:update_stats_from_line(runner, line) -> None
"""
from __future__ import annotations
import re
import time
from typing import Any
def update_stats_from_line(runner: Any, line: str) -> None:
"""把日志行解析成各 counter 的累加 + event 记录。"""
s = (line or "").strip()
if not s:
return
with runner._lock:
runner._last_log_ts = time.time()
_parse_fudai_fields(runner, s)
_parse_open_attend_counters(runner, s)
_parse_skip_reasons(runner, s)
_parse_errors(runner, s)
_parse_fansclub(runner, s)
_parse_reservation(runner, s)
_parse_lottery_results(runner, s)
_parse_switch_room(runner, s)
_parse_stage_diag(runner, s)
_parse_ocr_stats(runner, s)
_parse_perf(runner, s)
_parse_detail_read(runner, s)
_parse_fudai_find(runner, s)
_parse_back_operation(runner, s)
# ============================================================
# 福袋字段提取(content / participants / copies / countdown / value)
# ============================================================
def _parse_fudai_fields(runner: Any, s: str) -> None:
content_extracted = False
room_title = ""
if "福袋内容:" in s:
with runner._lock:
runner._fudai_last["content"] = (
s.split("福袋内容:", 1)[1].strip().split()[0]
)
runner._fudai_last["updated_ts"] = time.time()
content_extracted = True
else:
m = re.search(r"(?:字段_)?内容[=:]\s*([^\s]+)", s)
if m:
with runner._lock:
runner._fudai_last["content"] = m.group(1).strip()
runner._fudai_last["updated_ts"] = time.time()
content_extracted = True
m = re.search(r"room_title[=:]\s*([^\s,]+)", s)
if m:
room_title = m.group(1).strip()
if content_extracted:
fudai_content = runner._fudai_last.get("content", "")
key = (room_title, fudai_content)
if key not in runner._recorded_fudai_seen:
runner._recorded_fudai_seen.add(key)
runner._inc("fudai_seen")
runner._record_event("fudai_seen", runner._snapshot_fudai())
try:
if runner._current_room_pos is not None:
try:
rp = int(runner._current_room_pos)
except Exception:
rp = None
if rp is not None and rp not in runner._fudai_seen_room_pos:
runner._fudai_seen_room_pos.add(rp)
runner._inc("fudai_seen_unique")
else:
key2 = runner._make_unique_key()
if key2 and key2 not in runner._unique_keys_seen:
runner._unique_keys_seen.add(key2)
runner._inc("fudai_seen_unique")
except Exception:
pass
# 参与人数 / 份数 / 倒计时 / 价值(只更新 _fudai_last,不计数)
m = re.search(r"(?:字段_)?参与人数[=:]?\s*(\d+)", s) or re.search(
r"参与人数:\s*(\d+)", s
)
if m:
with runner._lock:
runner._fudai_last["participants"] = int(m.group(1))
runner._fudai_last["updated_ts"] = time.time()
m = re.search(r"(?:字段_)?份数[=:]?\s*(\d+)", s) or re.search(
r"福袋份数:\s*(\d+)", s
)
if m:
with runner._lock:
runner._fudai_last["copies"] = int(m.group(1))
runner._fudai_last["updated_ts"] = time.time()
if "倒计时时间:" in s:
with runner._lock:
runner._fudai_last["countdown"] = (
s.split("倒计时时间:", 1)[1].strip().split()[0]
)
runner._fudai_last["updated_ts"] = time.time()
else:
m = re.search(r"(?:字段_)?倒计时[=:]?\s*([^\s]+)", s)
if m:
with runner._lock:
runner._fudai_last["countdown"] = m.group(1).strip()
runner._fudai_last["updated_ts"] = time.time()
m = re.search(
r"(?:字段_)?(?:价值|价值元|奖品价值)[=:]?\s*([0-9]+(?:[.·.。·.。][0-9]+)?)",
s,
) or re.search(
r"奖品价值:\s*([0-9]+(?:[.·.。·.。][0-9]+)?)\s*元", s
)
if m:
try:
with runner._lock:
runner._fudai_last["prize_value_yuan"] = float(m.group(1))
runner._fudai_last["updated_ts"] = time.time()
except Exception:
pass
# ============================================================
# 打开详情 / 点击参与 / 参与成功 / 参与失败
# ============================================================
def _parse_open_attend_counters(runner: Any, s: str) -> None:
if "点击打开福袋详情" in s or ("[流程]" in s and "检测到福袋图标并点击" in s):
runner._inc("fudai_open_detail")
runner._record_event("fudai_open_detail", runner._snapshot_fudai())
try:
key = runner._make_unique_key()
if key and key not in runner._unique_keys_open:
runner._unique_keys_open.add(key)
runner._inc("fudai_open_detail_unique")
except Exception:
pass
if "点击参与抽奖" in s or (
"[参与]" in s and ("动作=点击参与" in s or "动作=参与" in s)
):
runner._inc("fudai_click_attend")
runner._record_event("fudai_click_attend", runner._snapshot_fudai())
try:
key = runner._make_unique_key()
if key and key not in runner._unique_keys_attend:
runner._unique_keys_attend.add(key)
runner._inc("fudai_click_attend_unique")
except Exception:
pass
if (
"已经参与,等待开奖" in s
or "已经参与,等待看播时间凑齐开奖" in s
or "已参与成功(或看播中)" in s
or (
"[参与]" in s
and ("结果=已参与" in s or "结果=看播中" in s or "结果=参与成功" in s)
)
or ("[参与]" in s and "已参与" in s and "等待开奖" in s)
or ("预约回退后直接参与" in s and "参与成功" in s)
):
runner._inc("fudai_attend_ok")
runner._record_event("fudai_attend_ok", runner._snapshot_fudai())
try:
if runner._current_room_pos is not None:
try:
rp = int(runner._current_room_pos)
except Exception:
rp = None
if rp is not None and rp not in runner._fudai_attend_ok_room_pos:
runner._fudai_attend_ok_room_pos.add(rp)
runner._inc("fudai_attend_ok_unique")
else:
key = runner._make_unique_key()
if key and key not in runner._unique_keys_attend:
runner._unique_keys_attend.add(key)
runner._inc("fudai_attend_ok_unique")
except Exception:
pass
if "参与抽奖失败" in s or ("[参与]" in s and "结果=失败" in s):
runner._inc("fudai_attend_fail")
runner._record_event("fudai_attend_fail", runner._snapshot_fudai())
try:
if runner._current_room_pos is not None:
try:
rp = int(runner._current_room_pos)
except Exception:
rp = None
if rp is not None and rp not in runner._fudai_attend_fail_room_pos:
runner._fudai_attend_fail_room_pos.add(rp)
runner._inc("fudai_attend_fail_unique")
else:
try:
key = runner._make_unique_key()
if key and key not in runner._unique_keys_attend:
runner._unique_keys_attend.add(key)
runner._inc("fudai_attend_fail_unique")
except Exception:
pass
except Exception:
pass
# ============================================================
# 跳过原因(参与人数 / 价值 / 内容 / 倒计时 / 看播)
# ============================================================
def _parse_skip_reasons(runner: Any, s: str) -> None:
if "参与人数" in s and "< 阈值" in s and "不参与" in s:
runner._inc("fudai_skip_participants_low")
meta = runner._snapshot_fudai()
m = re.search(r"参与人数[=:]?\s*(\d+)", s)
if m:
try:
meta["participants"] = int(m.group(1))
except Exception:
pass
m = re.search(r"阈值[=:]?\s*(\d+)", s)
if m:
try:
meta["threshold"] = int(m.group(1))
except Exception:
pass
runner._record_event("fudai_skip", {"reason": "participants_low", **meta})
if "参与人数" in s and "> 阈值" in s and "不参与" in s:
runner._inc("fudai_skip_participants_high")
meta = runner._snapshot_fudai()
m = re.search(r"参与人数[=:]?\s*(\d+)", s)
if m:
try:
meta["participants"] = int(m.group(1))
except Exception:
pass
m = re.search(r"阈值[=:]?\s*(\d+)", s)
if m:
try:
meta["threshold"] = int(m.group(1))
except Exception:
pass
runner._record_event("fudai_skip", {"reason": "participants_high", **meta})
if "奖品价值" in s and "< 阈值" in s and "不参与" in s:
runner._inc("fudai_skip_value_low")
meta = runner._snapshot_fudai()
m = re.search(
r"(?:奖品)?价值[=:]?\s*([0-9]+(?:[.·.。·.。][0-9]+)?)", s
)
if m:
try:
meta["prize_value_yuan"] = float(m.group(1))
except Exception:
pass
m = re.search(
r"阈值[=:]?\s*([0-9]+(?:[.·.。·.。][0-9]+)?)", s
)
if m:
try:
meta["threshold"] = float(m.group(1))
except Exception:
pass
runner._record_event("fudai_skip", {"reason": "value_low", **meta})
if "福袋内容不理想" in s or ("[筛选]" in s and "内容" in s and "黑名单" in s):
runner._inc("fudai_skip_content")
runner._record_event(
"fudai_skip", {"reason": "content", **runner._snapshot_fudai()}
)
if "抽奖倒计时时间小于" in s and "不参与" in s:
runner._inc("fudai_skip_countdown_short")
meta = runner._snapshot_fudai()
m = re.search(r"(\d+)\s*秒", s)
if m:
try:
meta["countdown_seconds"] = int(m.group(1))
except Exception:
pass
runner._record_event("fudai_skip", {"reason": "countdown_short", **meta})
if "抽奖倒计时时间大于" in s and "暂不参与" in s:
runner._inc("fudai_skip_countdown_long")
meta = runner._snapshot_fudai()
m = re.search(r"(\d+)\s*秒", s)
if m:
try:
meta["countdown_seconds"] = int(m.group(1))
except Exception:
pass
runner._record_event("fudai_skip", {"reason": "countdown_long", **meta})
if (
"需要看播时长:默认不参与" in s
or "需要开始观看/看播门槛:默认不参与" in s
or ("[参与]" in s and "结果=看播门槛" in s)
):
runner._inc("fudai_skip_watch_required")
runner._record_event(
"fudai_skip", {"reason": "watch_required", **runner._snapshot_fudai()}
)
if "打开福袋异常" in s or ("[流程]" in s and "打开福袋异常" in s):
runner._inc("fudai_open_error")
runner._record_event("fudai_open_error", runner._snapshot_fudai())
if "超过10次点击福袋无法打开详情" in s:
runner._inc("fudai_open_error_too_many")
runner._record_event("fudai_open_error_too_many", runner._snapshot_fudai())
if (
"[流程]" in s and "倒计时大于阈值,但价值达到高价值阈值,记录预约" in s
) or ("[参与]" in s and "倒计时大于阈值,但价值达到高价值阈值,记录预约" in s):
runner._inc("fudai_reserved_high_value")
meta = runner._snapshot_fudai()
m = re.search(
r"(?:价值|价值元)[=:]?\s*([0-9]+(?:[.·.。·.。][0-9]+)?)",
s,
)
if m:
try:
meta["prize_value_yuan"] = float(m.group(1))
except Exception:
pass
m = re.search(r"(?:剩余|倒计时)[=:]?\s*(\d+)\s*秒", s)
if m:
try:
meta["remain_seconds"] = int(m.group(1))
except Exception:
pass
runner._record_event("fudai_reserved_high_value", meta)
# ============================================================
# 错误统计
# ============================================================
def _parse_errors(runner: Any, s: str) -> None:
if "[错误]" in s or "[异常]" in s or "错误=" in s or "异常=" in s:
runner._inc("error_total")
error_type = "unknown"
if "UnboundLocalError" in s:
error_type = "UnboundLocalError"
runner._inc("error_unbound_local")
elif "AttributeError" in s:
error_type = "AttributeError"
runner._inc("error_attribute")
elif "KeyError" in s:
error_type = "KeyError"
runner._inc("error_key")
elif "ValueError" in s:
error_type = "ValueError"
runner._inc("error_value")
elif "TypeError" in s:
error_type = "TypeError"
runner._inc("error_type")
elif "TimeoutError" in s or "超时" in s:
error_type = "TimeoutError"
runner._inc("error_timeout")
elif "ConnectionError" in s or ("连接" in s and "失败" in s):
error_type = "ConnectionError"
runner._inc("error_connection")
elif "OCR" in s and ("失败" in s or "错误" in s):
error_type = "OCR_Error"
runner._inc("error_ocr")
elif "截图" in s and ("失败" in s or "错误" in s):
error_type = "Screenshot_Error"
runner._inc("error_screenshot")
elif "识别" in s and ("失败" in s or "错误" in s):
error_type = "Detection_Error"
runner._inc("error_detection")
runner._record_event("error", {"error_type": error_type})
if "阶段诊断" in s and ("失败" in s or "错误" in s or "异常" in s):
runner._inc("error_stage_diagnosis")
runner._record_event("error_stage_diagnosis", {})
if "读取福袋详情" in s and ("失败" in s or "错误" in s or "异常" in s):
runner._inc("error_read_detail")
runner._record_event("error_read_detail", {})
if "load_config" in s and ("失败" in s or "错误" in s or "异常" in s):
runner._inc("error_config_load")
runner._record_event("error_config_load", {})
if ("预约队列状态文件" in s or "reservations.json" in s) and (
"失败" in s or "错误" in s
):
runner._inc("error_state_file")
runner._record_event("error_state_file", {})
if "直播间检测" in s and ("失败" in s or "错误" in s):
runner._inc("error_live_room_detect")
runner._record_event("error_live_room_detect", {})
if "查找福袋" in s and ("失败" in s or "错误" in s or "未找到" in s):
runner._inc("error_fudai_find")
runner._record_event("error_fudai_find", {})
# ============================================================
# 粉丝团门槛
# ============================================================
def _parse_fansclub(runner: Any, s: str) -> None:
if "需要加入粉丝团才能参与" in s or ("[参与]" in s and "结果=需要粉丝团" in s):
runner._inc("fansclub_required")
runner._record_event("fansclub_required", runner._snapshot_fudai())
if "未启用自动加入粉丝团" in s:
runner._inc("fansclub_manual_needed")
runner._record_event("fansclub_manual_needed", runner._snapshot_fudai())
if "粉丝团门槛仍未解决" in s or ("[参与]" in s and "粉丝团门槛仍未解决" in s):
runner._inc("fansclub_unresolved")
runner._record_event("fansclub_unresolved", runner._snapshot_fudai())
# ============================================================
# 预约队列 / 回退校验 / 预约记录
# ============================================================
def _parse_reservation(runner: Any, s: str) -> None:
if (
"[预约]" in s and "回退校验通过" in s
) or "回退校验通过:已回到目标直播间" in s:
runner._inc("reservation_back_verify_ok")
runner._record_event("reservation_back_verify_ok", {})
if ("[预约]" in s and "回退校验失败" in s) or "回退校验失败" in s:
runner._inc("reservation_back_verify_fail")
runner._record_event("reservation_back_verify_fail", {})
if (
"[预约]" in s and "预约队列已满,丢弃最低价值" in s
) or "预约队列已满,丢弃最低价值" in s:
runner._inc("reservation_drop_low_value")
runner._record_event("reservation_drop_low_value", {})
if ("[预约]" in s and "清空预约队列" in s) or "清空预约队列" in s:
runner._inc("reservation_clear")
runner._record_event("reservation_clear", {})
if (
"[预约]" in s and "已记录高价值福袋" in s
) or "record_high_value_reservation:已记录高价值福袋" in s:
runner._inc("reservation_recorded")
value = None
m = re.search(r"(?:字段_)?(?:价值|价值元|value)[=:]?\s*(\d+(?:\.\d+)?)", s)
if not m:
m = re.search(r"value[=:]?\s*(\d+(?:\.\d+)?)", s)
if m:
try:
value = float(m.group(1))
except Exception:
pass
future_ts = None
m = re.search(r"(?:字段_)?(?:开奖时间|future|future_ts)[=:]?\s*(\d+)", s)
if m:
try:
future_ts = int(m.group(1))
except Exception:
pass
room_title = None
m = re.search(
r"(?:字段_)?(?:直播间|直播间名|room_title)[=:]?\s*([^\s]+)", s
)
if m:
room_title = m.group(1).strip()
meta = runner._snapshot_fudai()
if value is not None:
meta["prize_value_yuan"] = value
if future_ts is not None:
meta["future_ts"] = future_ts
if room_title:
meta["room_title"] = room_title
runner._record_event("reservation_recorded", meta)
if (
"[预约]" in s and "进入预约参与窗口" in s
) or "进入预约参与窗口,准备回退到目标直播间" in s:
runner._inc("reservation_window_entered")
runner._record_event("reservation_window_entered", {})
if (
("[预约]" in s and "已回退到目标直播间" in s)
or "已回退到目标直播间" in s
or ("[预约]" in s and "已回退到最早开奖的预约直播间" in s)
):
runner._inc("reservation_back_success")
meta = {}
m = re.search(r"(?:字段_)?(?:需回退次数|back_times)[=:]?\s*(\d+)", s)
if m:
try:
meta["back_times"] = int(m.group(1))
except Exception:
pass
runner._record_event("reservation_back_success", meta)
if ("[预约]" in s and "时间窗口未到" in s) or "时间窗口未到,跳过回退" in s:
runner._inc("reservation_window_not_reached")
runner._record_event("reservation_window_not_reached", {})
if (
"[预约]" in s and "已明显错过开奖时间" in s
) or "已明显错过开奖时间,清理过期预约" in s:
runner._inc("reservation_expired")
runner._record_event("reservation_expired", {})
if (
"[预约]" in s and "预约队列为空" in s
) or "process_reservation_attend_window:预约队列为空" in s:
runner._inc("reservation_queue_empty")
if ("[预约]" in s and "锁定期未结束" in s) or "锁定期未结束" in s:
runner._inc("reservation_locked")
runner._record_event("reservation_locked", {})
if "[预约]" in s and "已回退到第一个直播间" in s:
runner._inc("reservation_back_to_first")
runner._record_event("reservation_back_to_first", {})
if "[预约]" in s and "run_once_basic:检查预约回退触发条件" in s:
runner._inc("reservation_check_triggered")
if (
("[预约]" in s and "队列已满" in s)
or "handle_queue_full_wait_at_earliest" in s
or ("[预约]" in s and "队列已满,回退到最早开奖的预约直播间" in s)
):
runner._inc("reservation_queue_full_wait")
runner._record_event("reservation_queue_full_wait", {})
if ("[预约]" in s and "预约回退后直接参与" in s) or "预约回退后直接参与" in s:
runner._inc("reservation_back_direct_attend")
runner._record_event("reservation_back_direct_attend", {})
if "[预约]" in s and "队列满回退后,直接设置参与标志" in s:
runner._inc("reservation_queue_full_back_attend")
runner._record_event("reservation_queue_full_back_attend", {})
if "[预约]" in s and "通过相似度匹配识别为重复预约" in s:
runner._inc("reservation_duplicate_detected")
runner._record_event("reservation_duplicate_detected", {})
# ============================================================
# 开奖结果 + 等待开奖
# ============================================================
def _parse_lottery_results(runner: Any, s: str) -> None:
if "没有抽中" in s and "关闭弹窗" in s:
runner._inc("fudai_result_no_win")
runner._record_event("fudai_result_no_win", runner._snapshot_fudai())
if (
"恭喜中奖了" in s
or "检测到中奖结果" in s
or ("[开奖结果]" in s and "中奖" in s)
):
runner._inc("fudai_result_win")
meta = runner._snapshot_fudai()
m = re.search(r"(?:奖品|商品)[=:]?\s*([^\s]+)", s)
if m:
meta["prize"] = m.group(1).strip()
runner._record_event("fudai_result_win", meta)
runner._record_win()
if "福袋商品下单成功" in s or ("[开奖结果]" in s and "下单成功" in s):
runner._inc("fudai_order_success")
runner._record_event("fudai_order_success", runner._snapshot_fudai())
# 等待开奖
if ("[参与]" in s and "参与成功,设置等待开奖标志" in s) or (
"[参与]" in s and "设置等待开奖标志" in s
):
runner._inc("fudai_waiting_lottery")
meta = runner._snapshot_fudai()
m = re.search(r"(?:剩余|倒计时|remain_seconds)[=:]?\s*(\d+)", s)
if m:
try:
meta["remain_seconds"] = int(m.group(1))
except Exception:
pass
runner._record_event("fudai_waiting_lottery", meta)
# ============================================================
# 直播间切换
# ============================================================
def _parse_switch_room(runner: Any, s: str) -> None:
if "上划切换直播间" in s or ("[操作]" in s and "上滑切换直播间" in s):
runner._inc("switch_room")
meta_reason = "unknown"
if "无福袋" in s:
runner._inc("switch_room_no_fudai")
meta_reason = "no_fudai"
elif "参与人数" in s:
runner._inc("switch_room_participants")
meta_reason = "participants"
elif "奖品价值" in s:
runner._inc("switch_room_value")
meta_reason = "value"
elif "内容不理想" in s:
runner._inc("switch_room_content")
meta_reason = "content"
elif "倒计时" in s:
runner._inc("switch_room_countdown")
meta_reason = "countdown"
elif "参与抽奖失败" in s:
runner._inc("switch_room_attend_fail")
meta_reason = "attend_fail"
elif "记录预约后" in s:
runner._inc("switch_room_after_reservation")
meta_reason = "after_reservation"
elif "锁定期内" in s:
runner._inc("switch_room_locked")
meta_reason = "locked"
runner._record_event(
"switch_room", {"reason": meta_reason, **runner._snapshot_fudai()}
)
# ============================================================
# 阶段诊断 / OCR / 性能 / 详情识别 / 福袋查找 / 回退操作
# ============================================================
def _parse_stage_diag(runner: Any, s: str) -> None:
if "[阶段诊断]" in s or "阶段诊断" in s:
if "阶段诊断完成" in s:
runner._inc("stage_diagnosis_complete")
meta = {}
m = re.search(r"阶段[=:]?\s*(\w+)", s)
if m:
meta["stage"] = m.group(1)
m = re.search(r"耗时[=:]?\s*([0-9]+(?:\.[0-9]+)?)\s*秒", s)
if m:
try:
meta["elapsed_seconds"] = float(m.group(1))
except Exception:
pass
m = re.search(r"分数[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s)
if m:
try:
meta["score"] = float(m.group(1))
except Exception:
pass
runner._record_event("stage_diagnosis_complete", meta)
elif "阶段诊断失败" in s or "阶段诊断错误" in s:
runner._inc("stage_diagnosis_failed")
runner._record_event("stage_diagnosis_failed", {})
def _parse_ocr_stats(runner: Any, s: str) -> None:
if "[福袋]" in s and "OCR识别" in s:
runner._inc("ocr_attempt")
if "识别成功" in s or "识别完成" in s:
runner._inc("ocr_success")
elif "识别失败" in s or "识别错误" in s:
runner._inc("ocr_failed")
def _parse_perf(runner: Any, s: str) -> None:
m = re.search(r"耗时[=:]?\s*([0-9]+(?:\.[0-9]+)?)\s*秒", s)
if m:
try:
elapsed = float(m.group(1))
if elapsed > 5.0:
runner._inc("slow_operation")
runner._record_event(
"slow_operation",
{"elapsed_seconds": elapsed, "operation": s[:100]},
)
except Exception:
pass
def _parse_detail_read(runner: Any, s: str) -> None:
if ("[福袋详情]" in s and "识别" in s) or "识别福袋详情" in s:
runner._inc("fudai_detail_read_attempt")
if (
"识别成功" in s
or "识别完成" in s
or "read_fudai_detail_once完成(成功)" in s
):
runner._inc("fudai_detail_read_success")
meta = {}
m = re.search(r"(?:任务数量|task_count)[=:]?\s*(\d+)", s)
if m:
try:
meta["task_count"] = int(m.group(1))
except Exception:
pass
runner._record_event("fudai_detail_read_success", meta)
elif "识别失败" in s or "识别错误" in s:
runner._inc("fudai_detail_read_failed")
runner._record_event("fudai_detail_read_failed", {})
def _parse_fudai_find(runner: Any, s: str) -> None:
if "[福袋查找]" in s or "查找福袋" in s:
if "检测完成" in s and "命中" in s:
runner._inc("fudai_find_success")
elif "检测完成" in s and "未找到" in s:
runner._inc("fudai_find_not_found")
elif "等待超时" in s:
runner._inc("fudai_find_timeout")
def _parse_back_operation(runner: Any, s: str) -> None:
if ("[预约]" in s and "回退" in s) or "回退到" in s:
if "回退完成" in s or "回退成功" in s:
runner._inc("reservation_back_operation")
meta = {}
m = re.search(r"(?:回退|back_times)[=:]?\s*(\d+)", s)
if m:
try:
meta["back_times"] = int(m.group(1))
except Exception:
pass
runner._record_event("reservation_back_operation", meta)