feat: Enhance logging and parameter tracking capabilities
- Refactor `gui_core.py` to improve code readability and maintainability by adding line breaks for long statements. - Introduce `inspect_lines.py` script for inspecting specific line ranges in files. - Add `generate_param_locations.py` to scan the repository and generate a report of function definitions, argparse parameters, and tracking calls. - Implement `param_usage_tool.py` for analyzing `param_usage.json` records and scanning code for tracking calls. - Create `simulate_reservation_preempted_flow.py` and `simulate_reservation_preempted_flow_dynamic.py` to validate behavior of reservation logic under specific conditions. - Add global parameter tracking feature in `run_cli.py` to enable detailed usage tracing.
This commit is contained in:
1 parent
68c8ccea66
commit
95b4517bdd
23 files changed
+1560
-849
No files matched your search
+109
-36
@@ -30,7 +30,9 @@ def find_adb_executable() -> str:
|
||||
# 兼容某些人手动放到用户目录的情况
|
||||
userprofile = os.environ.get("USERPROFILE") or ""
|
||||
if userprofile:
|
||||
candidates.append(os.path.join(userprofile, "AppData", "Local", "platform-tools", "adb.exe"))
|
||||
candidates.append(
|
||||
os.path.join(userprofile, "AppData", "Local", "platform-tools", "adb.exe")
|
||||
)
|
||||
|
||||
for p in candidates:
|
||||
if os.path.exists(p):
|
||||
@@ -137,7 +139,7 @@ class Runner:
|
||||
with self._lock:
|
||||
self._events.append(ev)
|
||||
if len(self._events) > self._events_cap:
|
||||
self._events = self._events[-self._events_cap:]
|
||||
self._events = self._events[-self._events_cap :]
|
||||
|
||||
def _record_win(self) -> None:
|
||||
item = {
|
||||
@@ -147,7 +149,7 @@ class Runner:
|
||||
with self._lock:
|
||||
self._wins.append(item)
|
||||
if len(self._wins) > self._wins_cap:
|
||||
self._wins = self._wins[-self._wins_cap:]
|
||||
self._wins = self._wins[-self._wins_cap :]
|
||||
|
||||
def _snapshot_fudai(self) -> dict:
|
||||
with self._lock:
|
||||
@@ -172,7 +174,9 @@ class Runner:
|
||||
content_extracted = False
|
||||
if "福袋内容:" in s:
|
||||
with self._lock:
|
||||
self._fudai_last["content"] = s.split("福袋内容:", 1)[1].strip().split()[0] # 只取第一个词,避免包含后续字段
|
||||
self._fudai_last["content"] = (
|
||||
s.split("福袋内容:", 1)[1].strip().split()[0]
|
||||
) # 只取第一个词,避免包含后续字段
|
||||
self._fudai_last["updated_ts"] = time.time()
|
||||
content_extracted = True
|
||||
else:
|
||||
@@ -209,7 +213,9 @@ class Runner:
|
||||
# 倒计时:支持多种格式
|
||||
if "倒计时时间:" in s:
|
||||
with self._lock:
|
||||
self._fudai_last["countdown"] = s.split("倒计时时间:", 1)[1].strip().split()[0]
|
||||
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)
|
||||
@@ -219,7 +225,9 @@ class Runner:
|
||||
self._fudai_last["updated_ts"] = time.time()
|
||||
|
||||
# 奖品价值:支持多种格式
|
||||
m = re.search(r"(?:字段_)?(?:价值|价值元|奖品价值)[=:]?\s*([0-9]+(?:\.[0-9]+)?)", 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:
|
||||
@@ -234,7 +242,9 @@ class Runner:
|
||||
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 or "动作=参与" 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())
|
||||
|
||||
@@ -243,7 +253,10 @@ class Runner:
|
||||
"已经参与,等待开奖" 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 or "结果=看播中" in s or "结果=参与成功" in s)
|
||||
)
|
||||
or ("[参与]" in s and "已参与" in s and "等待开奖" in s)
|
||||
or ("预约回退后直接参与" in s and "参与成功" in s)
|
||||
):
|
||||
@@ -307,7 +320,9 @@ class Runner:
|
||||
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()})
|
||||
self._record_event(
|
||||
"fudai_skip", {"reason": "content", **self._snapshot_fudai()}
|
||||
)
|
||||
if "抽奖倒计时时间小于" in s and "不参与" in s:
|
||||
self._inc("fudai_skip_countdown_short")
|
||||
# 提取倒计时秒数
|
||||
@@ -336,7 +351,9 @@ class Runner:
|
||||
or ("[参与]" in s and "结果=看播门槛" in s)
|
||||
):
|
||||
self._inc("fudai_skip_watch_required")
|
||||
self._record_event("fudai_skip", {"reason": "watch_required", **self._snapshot_fudai()})
|
||||
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())
|
||||
@@ -344,7 +361,9 @@ class Runner:
|
||||
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):
|
||||
if (
|
||||
"[流程]" in s and "倒计时大于阈值,但价值达到高价值阈值,记录预约" in s
|
||||
) or ("[参与]" in s and "倒计时大于阈值,但价值达到高价值阈值,记录预约" in s):
|
||||
self._inc("fudai_reserved_high_value")
|
||||
# 提取价值和倒计时信息
|
||||
meta = self._snapshot_fudai()
|
||||
@@ -415,7 +434,9 @@ class Runner:
|
||||
self._record_event("error_config_load", {})
|
||||
|
||||
# --- 状态文件错误 ---
|
||||
if ("预约队列状态文件" in s or "reservations.json" in s) and ("失败" in s or "错误" in s):
|
||||
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", {})
|
||||
|
||||
@@ -441,13 +462,17 @@ class Runner:
|
||||
self._record_event("fansclub_unresolved", self._snapshot_fudai())
|
||||
|
||||
# --- 预约队列/回退校验 ---
|
||||
if ("[预约]" in s and "回退校验通过" in s) or "回退校验通过:已回到目标直播间" in s:
|
||||
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:
|
||||
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:
|
||||
@@ -455,7 +480,9 @@ class Runner:
|
||||
self._record_event("reservation_clear", {})
|
||||
|
||||
# --- 预约记录相关 ---
|
||||
if ("[预约]" in s and "已记录高价值福袋" in s) or "record_high_value_reservation:已记录高价值福袋" in s:
|
||||
if (
|
||||
"[预约]" in s and "已记录高价值福袋" in s
|
||||
) or "record_high_value_reservation:已记录高价值福袋" in s:
|
||||
self._inc("reservation_recorded")
|
||||
# 提取预约价值:支持多种格式
|
||||
value = None
|
||||
@@ -477,7 +504,9 @@ class Runner:
|
||||
pass
|
||||
# 提取直播间名称
|
||||
room_title = None
|
||||
m = re.search(r"(?:字段_)?(?:直播间|直播间名|room_title)[=:]?\s*([^\s]+)", s)
|
||||
m = re.search(
|
||||
r"(?:字段_)?(?:直播间|直播间名|room_title)[=:]?\s*([^\s]+)", s
|
||||
)
|
||||
if m:
|
||||
room_title = m.group(1).strip()
|
||||
meta = self._snapshot_fudai()
|
||||
@@ -488,10 +517,16 @@ class Runner:
|
||||
if room_title:
|
||||
meta["room_title"] = room_title
|
||||
self._record_event("reservation_recorded", meta)
|
||||
if ("[预约]" in s and "进入预约参与窗口" in s) or "进入预约参与窗口,准备回退到目标直播间" in s:
|
||||
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):
|
||||
if (
|
||||
("[预约]" in s and "已回退到目标直播间" in s)
|
||||
or "已回退到目标直播间" in s
|
||||
or ("[预约]" in s and "已回退到最早开奖的预约直播间" in s)
|
||||
):
|
||||
self._inc("reservation_back_success")
|
||||
# 提取回退信息
|
||||
meta = {}
|
||||
@@ -505,21 +540,29 @@ class Runner:
|
||||
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:
|
||||
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:
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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", {})
|
||||
# 回退后直接参与
|
||||
@@ -527,11 +570,11 @@ class Runner:
|
||||
self._inc("reservation_back_direct_attend")
|
||||
self._record_event("reservation_back_direct_attend", {})
|
||||
# 队列满回退后设置参与标志
|
||||
if ("[预约]" in s and "队列满回退后,直接设置参与标志" in s):
|
||||
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):
|
||||
if "[预约]" in s and "通过相似度匹配识别为重复预约" in s:
|
||||
self._inc("reservation_duplicate_detected")
|
||||
self._record_event("reservation_duplicate_detected", {})
|
||||
|
||||
@@ -539,7 +582,11 @@ class Runner:
|
||||
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):
|
||||
if (
|
||||
"恭喜中奖了" in s
|
||||
or "检测到中奖结果" in s
|
||||
or ("[开奖结果]" in s and "中奖" in s)
|
||||
):
|
||||
self._inc("fudai_result_win")
|
||||
# 提取中奖信息
|
||||
meta = self._snapshot_fudai()
|
||||
@@ -553,7 +600,9 @@ class Runner:
|
||||
self._record_event("fudai_order_success", self._snapshot_fudai())
|
||||
# 等待开奖(只在设置等待开奖标志时计数,避免重复计数)
|
||||
# 注意:不要匹配"已经参与,等待开奖",因为那已经在参与成功时计数了
|
||||
if ("[参与]" in s and "参与成功,设置等待开奖标志" in s) or ("[参与]" in s and "设置等待开奖标志" in s):
|
||||
if ("[参与]" in s and "参与成功,设置等待开奖标志" in s) or (
|
||||
"[参与]" in s and "设置等待开奖标志" in s
|
||||
):
|
||||
self._inc("fudai_waiting_lottery")
|
||||
# 提取剩余秒数
|
||||
meta = self._snapshot_fudai()
|
||||
@@ -593,7 +642,9 @@ class Runner:
|
||||
elif "锁定期内" in s:
|
||||
self._inc("switch_room_locked")
|
||||
meta_reason = "locked"
|
||||
self._record_event("switch_room", {"reason": meta_reason, **self._snapshot_fudai()})
|
||||
self._record_event(
|
||||
"switch_room", {"reason": meta_reason, **self._snapshot_fudai()}
|
||||
)
|
||||
|
||||
# --- 阶段诊断统计 ---
|
||||
if "[阶段诊断]" in s or "阶段诊断" in s:
|
||||
@@ -637,14 +688,21 @@ class Runner:
|
||||
# 记录耗时较长的操作
|
||||
if elapsed > 5.0:
|
||||
self._inc("slow_operation")
|
||||
self._record_event("slow_operation", {"elapsed_seconds": elapsed, "operation": s[:100]})
|
||||
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:
|
||||
if (
|
||||
"识别成功" in s
|
||||
or "识别完成" in s
|
||||
or "read_fudai_detail_once完成(成功)" in s
|
||||
):
|
||||
self._inc("fudai_detail_read_success")
|
||||
# 提取任务数量
|
||||
meta = {}
|
||||
@@ -741,7 +799,10 @@ class Runner:
|
||||
cmd += ["--min-prize-value-yuan", str(params.min_prize_value_yuan)]
|
||||
|
||||
# 这些参数是新增可调节项:倒计时太短跳过、参与人数范围
|
||||
cmd += ["--skip-if-countdown-gt-seconds", str(int(params.skip_if_countdown_gt_seconds or 900))]
|
||||
cmd += [
|
||||
"--skip-if-countdown-gt-seconds",
|
||||
str(int(params.skip_if_countdown_gt_seconds or 900)),
|
||||
]
|
||||
if params.reset_after_swipes_enabled:
|
||||
cmd.append("--reset-after-swipes-enabled")
|
||||
cmd += ["--reset-after-swipes", str(int(params.reset_after_swipes or 10))]
|
||||
@@ -771,11 +832,17 @@ class Runner:
|
||||
else:
|
||||
cmd.append("--reservation-back-verify-disabled")
|
||||
if params.reservation_back_swipe_delay > 0:
|
||||
cmd += ["--reservation-back-swipe-delay", str(params.reservation_back_swipe_delay)]
|
||||
cmd += [
|
||||
"--reservation-back-swipe-delay",
|
||||
str(params.reservation_back_swipe_delay),
|
||||
]
|
||||
|
||||
# 预约抢占最小价值
|
||||
if params.reservation_preempt_min_value > 0:
|
||||
cmd += ["--reservation-preempt-min-value", str(params.reservation_preempt_min_value)]
|
||||
cmd += [
|
||||
"--reservation-preempt-min-value",
|
||||
str(params.reservation_preempt_min_value),
|
||||
]
|
||||
|
||||
# 找福袋最大尝试次数
|
||||
if params.fudai_find_max_attempts > 0:
|
||||
@@ -794,7 +861,9 @@ class Runner:
|
||||
cmd.append("--fudai-template-disabled")
|
||||
|
||||
# 添加福袋模板匹配阈值参数
|
||||
cmd.extend(["--fudai-template-threshold", str(params.fudai_template_match_threshold)])
|
||||
cmd.extend(
|
||||
["--fudai-template-threshold", str(params.fudai_template_match_threshold)]
|
||||
)
|
||||
|
||||
# 继承当前环境,并确保 adb 在 PATH(即使用户没手动刷新 PATH)
|
||||
env = os.environ.copy()
|
||||
@@ -806,7 +875,9 @@ class Runner:
|
||||
env["PATH"] = adb_dir + os.pathsep + env.get("PATH", "")
|
||||
env["ADB_EXECUTABLE"] = adb_exe
|
||||
else:
|
||||
self._on_line("[警告] 未找到 adb.exe:请安装 platform-tools 或将 adb 加入 PATH")
|
||||
self._on_line(
|
||||
"[警告] 未找到 adb.exe:请安装 platform-tools 或将 adb 加入 PATH"
|
||||
)
|
||||
|
||||
try:
|
||||
p = subprocess.Popen(
|
||||
@@ -876,7 +947,9 @@ class Runner:
|
||||
# 如果进程立即退出且没有输出,说明可能有问题
|
||||
if not has_output and rc != 0:
|
||||
self._on_line(f"[警告] 进程立即退出,退出码={rc},没有输出")
|
||||
self._on_line("[提示] 可能的原因:run_cli.py启动失败、导入错误或配置错误")
|
||||
self._on_line(
|
||||
"[提示] 可能的原因:run_cli.py启动失败、导入错误或配置错误"
|
||||
)
|
||||
else:
|
||||
self._on_line(f"[进程结束] exit_code={rc}")
|
||||
except Exception as e:
|
||||
|
||||
Reference in new issue
Block a user