Add lightweight fudai flow diagnostics
This commit is contained in:
1 parent
dbf9b14fac
commit
1adaefdce6
5 files changed
+233
-4
No files matched your search
@@ -40,6 +40,23 @@ def _log_detail_open_verdict(analyser: Any, verdict: str, **extra) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def _detail_probe_after_click(analyser: Any) -> dict[str, Any]:
|
||||
"""Lightweight detail evidence produced by stage diagnosis, without extra OCR."""
|
||||
task_count = getattr(analyser, "_fudai_detail_task_count_from_stage", None)
|
||||
try:
|
||||
task_count_int = int(task_count or 0)
|
||||
except Exception:
|
||||
task_count_int = 0
|
||||
screenshot_ready = bool(getattr(analyser, "_screenshot_ready_for_ocr", False))
|
||||
probe_result = "detail_likely" if (task_count_int > 0 or screenshot_ready) else "not_enough_evidence"
|
||||
return {
|
||||
"task_count_from_stage": task_count_int,
|
||||
"screenshot_ready_for_ocr": screenshot_ready,
|
||||
"detail_probe_result": probe_result,
|
||||
"detail_probe_confident": bool(task_count_int > 0 or screenshot_ready),
|
||||
}
|
||||
|
||||
|
||||
def find_and_open_fudai_detail(
|
||||
analyser: Any,
|
||||
stage: Any = "",
|
||||
@@ -385,6 +402,10 @@ def find_and_open_fudai_detail(
|
||||
"流程",
|
||||
"find_and_open_fudai_detail:点击后固定等待",
|
||||
wait_seconds=wait_seconds,
|
||||
click_x=click_x,
|
||||
click_y=click_y,
|
||||
fudai_x=int(x or 0),
|
||||
room_pos=int(getattr(analyser, "room_pos", 0) or 0),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -403,6 +424,10 @@ def find_and_open_fudai_detail(
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"find_and_open_fudai_detail:点击后截图文件不存在,无法验证",
|
||||
decision="fail_no_after_click_screenshot",
|
||||
click_x=click_x,
|
||||
click_y=click_y,
|
||||
screenshot_path=pic_path,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -420,11 +445,21 @@ def find_and_open_fudai_detail(
|
||||
else:
|
||||
stage, reason = result
|
||||
try:
|
||||
probe = _detail_probe_after_click(analyser)
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"find_and_open_fudai_detail:点击后阶段检测",
|
||||
stage=stage,
|
||||
reason=reason,
|
||||
click_x=click_x,
|
||||
click_y=click_y,
|
||||
wait_seconds=wait_seconds,
|
||||
decision=(
|
||||
"success_stage_detail"
|
||||
if stage == "FUDai_DETAIL"
|
||||
else "needs_detail_probe"
|
||||
),
|
||||
**probe,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -445,6 +480,9 @@ def find_and_open_fudai_detail(
|
||||
"find_and_open_fudai_detail:点击后阶段检测确认在福袋详情页",
|
||||
stage=stage,
|
||||
reason=reason,
|
||||
click_x=click_x,
|
||||
click_y=click_y,
|
||||
decision="success",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -500,14 +538,60 @@ def find_and_open_fudai_detail(
|
||||
)
|
||||
return True
|
||||
else:
|
||||
probe = _detail_probe_after_click(analyser)
|
||||
if probe.get("detail_probe_confident"):
|
||||
_log_detail_open_verdict(
|
||||
analyser,
|
||||
"stage_false_negative_detail_likely",
|
||||
stage=stage,
|
||||
reason=str(reason or ""),
|
||||
click_x=click_x,
|
||||
click_y=click_y,
|
||||
**probe,
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"诊断",
|
||||
"点击后阶段检测=非详情,但详情轻量探测命中,疑似阶段误判,按已打开详情继续",
|
||||
stage=stage,
|
||||
reason=reason,
|
||||
click_x=click_x,
|
||||
click_y=click_y,
|
||||
decision="continue_as_detail",
|
||||
**probe,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
setattr(analyser, "_consecutive_no_fudai_count", 0)
|
||||
except Exception:
|
||||
pass
|
||||
elapsed = time.time() - func_start_time
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"find_and_open_fudai_detail完成(轻量探测确认详情)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
stage=stage,
|
||||
reason=str(reason or ""),
|
||||
)
|
||||
_emit_flow_flag(
|
||||
analyser,
|
||||
"fudai_find_open",
|
||||
"open_success_by_probe",
|
||||
stage=stage,
|
||||
reason=str(reason or ""),
|
||||
**probe,
|
||||
)
|
||||
return True
|
||||
|
||||
_log_detail_open_verdict(
|
||||
analyser,
|
||||
"detail_not_recognized",
|
||||
stage=stage,
|
||||
reason=str(reason or ""),
|
||||
task_count_from_stage=getattr(
|
||||
analyser, "_fudai_detail_task_count_from_stage", None
|
||||
),
|
||||
click_x=click_x,
|
||||
click_y=click_y,
|
||||
**probe,
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
@@ -515,6 +599,10 @@ def find_and_open_fudai_detail(
|
||||
"find_and_open_fudai_detail:点击后阶段检测未在福袋详情页,可能误点击",
|
||||
stage=stage,
|
||||
reason=reason,
|
||||
click_x=click_x,
|
||||
click_y=click_y,
|
||||
decision="misclick_close_detail_area",
|
||||
**probe,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -549,6 +637,10 @@ def find_and_open_fudai_detail(
|
||||
"流程",
|
||||
"find_and_open_fudai_detail完成(误点击)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
stage=stage,
|
||||
reason=str(reason or ""),
|
||||
click_x=click_x,
|
||||
click_y=click_y,
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
|
||||
@@ -193,10 +193,31 @@ def attend_choujiang(analyser) -> bool:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"参与按钮决策输入",
|
||||
room_pos=current_room_pos,
|
||||
cached_room_pos=cached_room_pos,
|
||||
button_text=(attend_button_text[:120] if attend_button_text else ""),
|
||||
button_status=str(button_status or ""),
|
||||
click_attempt_index=click_times + 1,
|
||||
run_id=getattr(analyser, "_run_id", ""),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 如果并行OCR结果不可用,直接放弃参与(决策已由福袋详情中的并行OCR进行)
|
||||
if not attend_button_text:
|
||||
analyser.last_attend_fail_reason = "no_parallel_ocr_result"
|
||||
analyser._log_kv("参与", "并行OCR结果不可用,放弃参与", result="不参与")
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"并行OCR结果不可用,放弃参与",
|
||||
result="不参与",
|
||||
reason="no_parallel_ocr_result",
|
||||
decision="close_detail_without_attend",
|
||||
room_pos=current_room_pos,
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"统计",
|
||||
@@ -461,9 +482,12 @@ def attend_choujiang(analyser) -> bool:
|
||||
"点击参与抽奖(基于截图优化坐标)",
|
||||
action="点击参与",
|
||||
mode="评论",
|
||||
button_text=(attend_button_text[:120] if attend_button_text else ""),
|
||||
button_status=str(button_status or ""),
|
||||
base_x=543,
|
||||
base_y=2070,
|
||||
region="(306,2030)-(780,2110)",
|
||||
decision="attend_click_sent",
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
@@ -486,9 +510,12 @@ def attend_choujiang(analyser) -> bool:
|
||||
"点击参与抽奖(基于截图优化坐标)",
|
||||
action="点击参与",
|
||||
mode="普通",
|
||||
button_text=(attend_button_text[:120] if attend_button_text else ""),
|
||||
button_status=str(button_status or ""),
|
||||
base_x=543,
|
||||
base_y=2070,
|
||||
region="(306,2030)-(780,2110)",
|
||||
decision="attend_click_sent",
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
@@ -632,9 +659,12 @@ def attend_choujiang(analyser) -> bool:
|
||||
"参与",
|
||||
"点击开始观看(基于截图优化坐标)",
|
||||
action="点击观看",
|
||||
button_text=(attend_button_text[:120] if attend_button_text else ""),
|
||||
button_status=str(button_status or ""),
|
||||
base_x=543,
|
||||
base_y=2070,
|
||||
region="(306,2030)-(780,2110)",
|
||||
decision="watch_click_sent",
|
||||
)
|
||||
return True
|
||||
elif attend_button_text and "参与" in attend_button_text:
|
||||
@@ -645,9 +675,12 @@ def attend_choujiang(analyser) -> bool:
|
||||
"参与",
|
||||
"点击参与(基于截图优化坐标)",
|
||||
action="点击参与",
|
||||
button_text=(attend_button_text[:120] if attend_button_text else ""),
|
||||
button_status=str(button_status or ""),
|
||||
base_x=543,
|
||||
base_y=2070,
|
||||
region="(306,2030)-(780,2110)",
|
||||
decision="attend_click_sent",
|
||||
)
|
||||
return True
|
||||
|
||||
@@ -661,6 +694,10 @@ def attend_choujiang(analyser) -> bool:
|
||||
action="点击参与",
|
||||
mode="兜底",
|
||||
button_text=(attend_button_text[:100] if attend_button_text else ""),
|
||||
button_status=str(button_status or ""),
|
||||
base_x=543,
|
||||
base_y=2070,
|
||||
decision="unknown_text_fallback_click_sent",
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
@@ -688,6 +725,10 @@ def attend_choujiang(analyser) -> bool:
|
||||
"参与抽奖失败:并行OCR结果无效",
|
||||
last_text=attend_button_text or "",
|
||||
result="参与失败",
|
||||
reason="parallel_ocr_invalid",
|
||||
button_status=str(button_status or ""),
|
||||
click_attempts=click_times,
|
||||
decision="no_attend_click_sent",
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
|
||||
@@ -424,6 +424,13 @@ def process_reservation_attend_window(
|
||||
expected_focus_until=int(expected_focus_until),
|
||||
target_future_ts=int(ft),
|
||||
lock_period_remain_seconds=int(focus_until - now_ts),
|
||||
reason="lock_active_other_reservation",
|
||||
decision="skip_reservation_back",
|
||||
queue_len=len(reservations),
|
||||
target_pos=int(target.get("pos_seen", 0) or 0),
|
||||
current_room_pos=int(
|
||||
getattr(analyser, "room_pos", room_pos) or room_pos
|
||||
),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -514,6 +521,9 @@ def process_reservation_attend_window(
|
||||
now_ts=int(now_ts),
|
||||
time_window_start=int(ft - dynamic_ahead),
|
||||
time_window_end=int(ft + max(0.0, poll_before)),
|
||||
reason="same_reservation_at_target_but_window_not_reached",
|
||||
decision="skip_reservation_back",
|
||||
remain_seconds_to_window=max(0, int((ft - dynamic_ahead) - now_ts)),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -580,6 +590,11 @@ def process_reservation_attend_window(
|
||||
remain_seconds=int((ft - dynamic_ahead) - now_ts),
|
||||
target_future_ts=int(ft),
|
||||
dynamic_ahead=dynamic_ahead,
|
||||
reason="time_window_not_reached",
|
||||
decision="skip_reservation_back",
|
||||
queue_len=len(reservations),
|
||||
target_pos=int(target.get("pos_seen", 0) or 0),
|
||||
current_room_pos=int(getattr(analyser, "room_pos", room_pos) or room_pos),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -595,6 +610,9 @@ def process_reservation_attend_window(
|
||||
now_ts=int(now_ts),
|
||||
poll_before=poll_before,
|
||||
missed_seconds=int(now_ts - (ft + max(0.0, poll_before))),
|
||||
reason="reservation_expired",
|
||||
decision="cleanup_expired_reservation",
|
||||
queue_len=len(reservations),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -640,6 +658,11 @@ def process_reservation_attend_window(
|
||||
target_pos_seen=target_pos,
|
||||
current_room_pos=current_room_pos,
|
||||
pos_diff=pos_diff,
|
||||
target_room_title=target_room_title[:50] if target_room_title else "",
|
||||
target_content=target_content[:50] if target_content else "",
|
||||
future_ts=int(ft),
|
||||
remain_seconds_to_open=int(ft - now_ts),
|
||||
decision="seek_reservation_room",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -161,6 +161,11 @@ def handle_back_verify(
|
||||
"[预约] process_reservation_attend_window:回退校验函数返回",
|
||||
verify_ok=verify_ok,
|
||||
verify_detail_exists=verify_detail is not None,
|
||||
verify_detail_preview=(
|
||||
str(verify_detail)[:300] if verify_detail is not None else ""
|
||||
),
|
||||
target_pos=int(target.get("pos_seen", 0)),
|
||||
target_room_title=target_room_title[:50] if target_room_title else "",
|
||||
level="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
@@ -180,6 +185,23 @@ def handle_back_verify(
|
||||
pass
|
||||
return None # 校验通过,主函数继续设锁定期
|
||||
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 回退校验失败:准备进行映射表二次定位",
|
||||
target_pos=int(target.get("pos_seen", 0)),
|
||||
target_room_title=target_room_title[:50] if target_room_title else "",
|
||||
target_room_title_raw=(
|
||||
target_room_title_raw[:50] if target_room_title_raw else ""
|
||||
),
|
||||
verify_detail_preview=(
|
||||
str(verify_detail)[:300] if verify_detail is not None else ""
|
||||
),
|
||||
decision="retry_seek_by_room_map",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 校验失败 → 走二次回退逻辑
|
||||
return _handle_verify_failure(
|
||||
analyser, target, reservations,
|
||||
|
||||
@@ -282,6 +282,31 @@ def record_high_value_reservation(
|
||||
created_str = datetime.fromtimestamp(item["created_ts"]).strftime(
|
||||
"%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
now_ts = time.time()
|
||||
seconds_until_lottery = int(float(item["future_ts"] or 0.0) - now_ts)
|
||||
try:
|
||||
poll_before_seconds = float(
|
||||
getattr(analyser, "high_value_fudai_poll_before_seconds", 10.0)
|
||||
or 10.0
|
||||
)
|
||||
except Exception:
|
||||
poll_before_seconds = 10.0
|
||||
try:
|
||||
join_ahead_seconds = float(
|
||||
getattr(analyser, "high_value_fudai_join_ahead_seconds", 100.0)
|
||||
or 100.0
|
||||
)
|
||||
except Exception:
|
||||
join_ahead_seconds = 100.0
|
||||
planned_seek_ts = max(
|
||||
float(item["future_ts"] or 0.0) - join_ahead_seconds,
|
||||
now_ts,
|
||||
)
|
||||
planned_seek_str = (
|
||||
datetime.fromtimestamp(planned_seek_ts).strftime("%Y-%m-%d %H:%M:%S")
|
||||
if planned_seek_ts > 0
|
||||
else ""
|
||||
)
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] record_high_value_reservation:已记录高价值福袋",
|
||||
@@ -296,7 +321,33 @@ def record_high_value_reservation(
|
||||
participants=participants,
|
||||
copies=copies,
|
||||
queue_len=len(reservations),
|
||||
future_ts=int(float(item["future_ts"] or 0.0)),
|
||||
seconds_until_lottery=seconds_until_lottery,
|
||||
poll_before_seconds=poll_before_seconds,
|
||||
join_ahead_seconds=join_ahead_seconds,
|
||||
planned_seek_ts=int(planned_seek_ts),
|
||||
planned_seek_str=planned_seek_str,
|
||||
planned_seek_after_seconds=max(0, int(planned_seek_ts - now_ts)),
|
||||
target_room_pos=room_pos,
|
||||
state_file_hint="douyin/core/state/reservations.json",
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 已记录预约计划",
|
||||
future_ts=int(float(item["future_ts"] or 0.0)),
|
||||
future_str=future_str if future_str else "未知",
|
||||
planned_seek_ts=int(planned_seek_ts),
|
||||
planned_seek_str=planned_seek_str,
|
||||
planned_seek_after_seconds=max(0, int(planned_seek_ts - now_ts)),
|
||||
seconds_until_lottery=seconds_until_lottery,
|
||||
target_room_pos=room_pos,
|
||||
target_room_title=room_title[:50] if room_title else "",
|
||||
content=fudai_content_text[:50] if fudai_content_text else "",
|
||||
queue_len=len(reservations),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
|
||||
Reference in new issue
Block a user