优化:调整basic_join_decision函数中的失败计数逻辑,提升代码可读性

This commit is contained in:
Your Name committed 2026-01-18 14:22:40 +08:00
1 parent 96c5cd50ec
commit d31a3ffee3
4 files changed
+141 -29

No files matched your search

+29 -13
View File
@@ -2122,19 +2122,33 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
}
)
# 并行OCR 已生成完整的 fudai_detail,本处不再自动写入运行时映射表或落盘,
# 以避免在详情页关闭前产生多余的映射写入。映射的写入由
# ReservationHandler.record_room_title_and_pos / SwipeHandler 在切换时负责。
# 并行OCR 已生成完整的 fudai_detail,写入运行时映射表并落盘
try:
analyser._log_kv(
"预约",
"[预约] 并行OCR完成(不写入映射表,等待后续时机写盘)",
room_pos=room_pos,
title=(title_for_map[:30] if title_for_map else ""),
fudai_content=fudai_content_text[:30] if fudai_content_text else "",
prize_value_yuan=prize_value_yuan,
log_type="DEBUG",
)
room_pos_map[room_pos] = room_info
try:
analyser._room_pos_to_title_map = room_pos_map
except Exception:
pass
try:
from douyin.reservation import douyin_reservation_handler
douyin_reservation_handler._dump_room_pos_map_to_state(analyser)
except Exception:
pass
try:
analyser._log_kv(
"预约",
"[预约] 并行OCR完成(已写入映射表并写盘)",
room_pos=room_pos,
title=(title_for_map[:30] if title_for_map else ""),
fudai_content=(
fudai_content_text[:30] if fudai_content_text else ""
),
prize_value_yuan=prize_value_yuan,
log_type="DEBUG",
)
except Exception:
pass
except Exception:
pass
@@ -6225,7 +6239,9 @@ def basic_join_decision(
analyser._consecutive_attend_failures = 0
else:
# 参与失败,增加计数器
analyser._consecutive_attend_failures = getattr(analyser, "_consecutive_attend_failures", 0) + 1
analyser._consecutive_attend_failures = (
getattr(analyser, "_consecutive_attend_failures", 0) + 1
)
# 如果参与成功,记录参与结果(不再使用已废弃的强制参与标志)
if result:
+2 -3
View File
@@ -107,18 +107,17 @@ class SwipeHandler:
except Exception:
pass
# 如果因为当前位置已有福袋信息而跳过了记录,则无需继续上滑切换(避免多余的切换)
# 如果当前位置已有福袋信息,仍允许上滑切换(避免因提前写盘导致无法切房)
try:
if should_skip_due_to_fudai:
try:
analyser._log_kv( # type: ignore[attr-defined]
"预约",
"[预约] 已跳过重复记录,暂停上滑切换以完成后续流程",
"[预约] 已跳过重复记录,继续上滑切换直播间",
room_pos=room_pos,
)
except Exception:
pass
return
except Exception:
pass
@@ -615,6 +615,57 @@ class ReservationHandler:
)
except Exception:
pass
# 若有方向提示,则执行一次纠偏切换,避免二次回退未触发滑动
try:
direction_hint = str(
item.get("_seek_direction_hint", "")
).lower()
except Exception:
direction_hint = ""
try:
already_done = bool(
item.get("_seek_mismatch_realign_done", False)
)
except Exception:
already_done = False
if direction_hint in ("up", "down") and not already_done:
try:
item["_seek_mismatch_realign_done"] = True
except Exception:
pass
try:
analyser._log_kv(
operation_type,
f"[{operation_type}] _seek_reservation_room:标题不匹配,执行一次纠偏切换",
direction=direction_hint,
target_pos=target_pos,
)
except Exception:
pass
try:
analyser._skip_record_title_during_seek = True
except Exception:
pass
try:
if direction_hint == "down":
douyin_swipe_handler.SwipeHandler.swipe_down_back_from_live(
analyser
)
else:
douyin_swipe_handler.SwipeHandler.swipe_up_to_next_live(
analyser
)
try:
analyser.operation.delay(0.1)
except Exception:
time.sleep(0.1)
except Exception:
pass
try:
analyser._skip_record_title_during_seek = False
except Exception:
pass
return False
except Exception:
# 若验证流程异常,返回 False 以避免误判
+59 -13
View File
@@ -1871,6 +1871,12 @@ def process_reservation_attend_window(
# 校验失败意味着位置信息可能不准确,尝试用映射表识别“当前/目标”位置差
updated_target = dict(target)
try:
room_pos_before_map = int(
getattr(analyser, "room_pos", 0) or 0
)
except Exception:
room_pos_before_map = 0
mapped_target_pos = None
mapped_current_pos = None
try:
@@ -2040,20 +2046,60 @@ def process_reservation_attend_window(
except Exception:
pass
if mapped_pos_diff == 0:
should_retry_seek = False
try:
analyser._log_kv(
"预约",
"[预约] 映射表显示已在目标位置,但校验失败,跳过二次回退",
mapped_current_pos=int(
mapped_current_pos
),
mapped_target_pos=int(
# 若映射表显示已在目标位置但校验失败,尝试根据回退前位置进行一次纠偏回退
if (
mapped_target_pos is not None
and room_pos_before_map != mapped_target_pos
):
try:
if room_pos_before_map > int(
mapped_target_pos
),
)
except Exception:
pass
):
updated_target[
"_seek_direction_hint"
] = "down"
elif room_pos_before_map < int(
mapped_target_pos
):
updated_target[
"_seek_direction_hint"
] = "up"
except Exception:
pass
try:
analyser._log_kv(
"预约",
"[预约] 映射表显示已在目标位置但校验失败,启用纠偏回退",
mapped_current_pos=int(
mapped_current_pos
),
mapped_target_pos=int(
mapped_target_pos
),
room_pos_before_map=int(
room_pos_before_map
),
direction_hint=updated_target.get(
"_seek_direction_hint", ""
),
)
except Exception:
pass
else:
should_retry_seek = False
try:
analyser._log_kv(
"预约",
"[预约] 映射表显示已在目标位置,但校验失败,跳过二次回退",
mapped_current_pos=int(
mapped_current_pos
),
mapped_target_pos=int(
mapped_target_pos
),
)
except Exception:
pass
if should_retry_seek:
try: