fix: Enhance logging and clean up blank lines across multiple files

- Improved logging for reservation handling and participation decisions to provide better traceability.
- Cleaned up excessive blank lines in various markdown and Python files to enhance readability and maintainability.
- Ensured consistent formatting across documentation and code files, contributing to overall project clarity.
This commit is contained in:
Your Name committed 2025-12-27 10:35:15 +08:00
1 parent 5c0fd75674
commit 7849b62d44
38 files changed
+42957 -213

No files matched your search

+286 -29
View File
@@ -279,27 +279,54 @@ class ProcRunner:
self._mdc_context[key] = value
# --- 福袋:抽取"最近一次"识别到的信息 ---
# 支持多种格式:旧格式"福袋内容:"和新格式"字段_内容="或"内容="
content_extracted = False
if "福袋内容:" in s:
self._fudai_last["content"] = s.split("福袋内容:", 1)[1].strip()
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:
self._fudai_last["content"] = m.group(1).strip()
self._fudai_last["updated_ts"] = time.time()
content_extracted = True
if content_extracted:
self._inc("fudai_seen")
self._record_event("fudai_seen", self._snapshot_fudai())
m = re.search(r"参与人数:\s*(\d+)", s)
# 参与人数:支持多种格式
m = re.search(r"(?:字段_)?参与人数[=:]?\s*(\d+)", s)
if not m:
m = re.search(r"参与人数:\s*(\d+)", s)
if m:
self._fudai_last["participants"] = int(m.group(1))
self._fudai_last["updated_ts"] = time.time()
m = re.search(r"福袋份数:\s*(\d+)", s)
# 福袋份数:支持多种格式
m = re.search(r"(?:字段_)?份数[=:]?\s*(\d+)", s)
if not m:
m = re.search(r"福袋份数:\s*(\d+)", s)
if m:
self._fudai_last["copies"] = int(m.group(1))
self._fudai_last["updated_ts"] = time.time()
# 倒计时:支持多种格式
if "倒计时时间:" in s:
self._fudai_last["countdown"] = s.split("倒计时时间:", 1)[1].strip()
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:
self._fudai_last["countdown"] = m.group(1).strip()
self._fudai_last["updated_ts"] = time.time()
m = re.search(r"奖品价值:\s*([0-9]+(?:\.[0-9]+)?)\s*元", s)
# 奖品价值:支持多种格式
m = re.search(r"(?:字段_)?(?:价值|价值元|奖品价值)[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s)
if not m:
m = re.search(r"奖品价值:\s*([0-9]+(?:\.[0-9]+)?)\s*元", s)
if m:
try:
self._fudai_last["prize_value_yuan"] = float(m.group(1))
@@ -308,11 +335,11 @@ class ProcRunner:
pass
# --- 福袋:关键流程计数 ---
if "点击打开福袋详情" in s:
if "点击打开福袋详情" in s or ("[流程]" in s and "检测到福袋图标并点击" in s):
self._inc("fudai_open_detail")
self._record_event("fudai_open_detail", self._snapshot_fudai())
# 兼容新结构化中文日志: [参与] 动作=点击参与
if "点击参与抽奖" in s or ("[参与]" in s and "动作=点击参与" in s):
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())
@@ -321,44 +348,104 @@ class ProcRunner:
"已经参与,等待开奖" in s
or "已经参与,等待看播时间凑齐开奖" in s
or "已参与成功(或看播中)" in s
or ("[参与]" in s and ("结果=已参与" 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())
if "参与抽奖失败" in s:
if "参与抽奖失败" in s or ("[参与]" in s and "结果=失败" in s):
self._inc("fudai_attend_fail")
self._record_event("fudai_attend_fail", self._snapshot_fudai())
# --- 福袋:跳过/过滤原因 ---
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", **self._snapshot_fudai()}
"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", **self._snapshot_fudai()}
"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]+(?:\.[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
self._record_event(
"fudai_skip", {"reason": "value_low", **self._snapshot_fudai()}
"fudai_skip", {"reason": "value_low", **meta}
)
if "福袋内容不理想" in s:
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", **self._snapshot_fudai()}
"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", **self._snapshot_fudai()}
"fudai_skip", {"reason": "countdown_long", **meta}
)
# 看播门槛:默认不参与(新结构化日志)
if (
@@ -370,12 +457,30 @@ class ProcRunner:
self._record_event(
"fudai_skip", {"reason": "watch_required", **self._snapshot_fudai()}
)
if "打开福袋异常" in s:
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]+(?:\.[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)
# --- 错误和异常统计(与 gui_core.py 保持一致) ---
if "[错误]" in s or "[异常]" in s or "错误=" in s or "异常=" in s:
@@ -464,21 +569,51 @@ class ProcRunner:
# --- 预约记录相关(与 gui_core.py 保持一致) ---
if ("[预约]" in s and "已记录高价值福袋" in s) or "record_high_value_reservation:已记录高价值福袋" in s:
self._inc("reservation_recorded")
m = re.search(r"value[=:]?\s*(\d+(?:\.\d+)?)", s)
# 提取预约价值:支持多种格式
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))
self._record_event("reservation_recorded", {"prize_value_yuan": value, **self._snapshot_fudai()})
except Exception:
self._record_event("reservation_recorded", self._snapshot_fudai())
else:
self._record_event("reservation_recorded", self._snapshot_fudai())
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:
if ("[预约]" in s and "已回退到目标直播间" in s) or "已回退到目标直播间" in s or ("[预约]" in s and "已回退到最早开奖的预约直播间" in s):
self._inc("reservation_back_success")
self._record_event("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", {})
@@ -487,7 +622,7 @@ class ProcRunner:
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:
if ("[预约]" in s and "锁定期未结束" in s) or "锁定期未结束" in s:
self._inc("reservation_locked")
self._record_event("reservation_locked", {})
if ("[预约]" in s and "已回退到第一个直播间" in s):
@@ -495,24 +630,53 @@ class ProcRunner:
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:
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:
if "恭喜中奖了" in s or "检测到中奖结果" in s or ("[开奖结果]" in s and "中奖" in s):
self._inc("fudai_result_win")
self._record_event("fudai_result_win", self._snapshot_fudai())
# 提取中奖信息
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:
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:
self._inc("fudai_waiting_lottery")
# 提取剩余秒数
meta = self._snapshot_fudai()
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_waiting_lottery", meta)
# --- 直播间切换(按原因粗分) ---
if "上划切换直播间" in s:
if "上划切换直播间" in s or ("[操作]" in s and "上滑切换直播间" in s):
self._inc("switch_room")
meta_reason = "unknown"
if "无福袋" in s:
@@ -533,9 +697,102 @@ class ProcRunner:
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)
# --- 性能:进入直播间到识别福袋耗时 ---
m = re.search(