优化预约和滑动处理逻辑
This commit is contained in:
1 parent
5bf07f60c6
commit
4b9b6cdf8f
3 files changed
+112
-112
No files matched your search
@@ -3044,63 +3044,8 @@ class fudai_analyse:
|
||||
self, detail, (skip, skip_reason)
|
||||
)
|
||||
if not result:
|
||||
# 记录预约成功,需要切换直播间
|
||||
try:
|
||||
needswitch = bool(
|
||||
getattr(self, "needswitch", True)
|
||||
)
|
||||
except Exception:
|
||||
needswitch = True
|
||||
if needswitch:
|
||||
try:
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail:记录预约后切换直播间",
|
||||
reason="high_value_reservation",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
# 优先使用封装好的上滑切房方法
|
||||
if hasattr(
|
||||
self, "swipe_up_to_next_live"
|
||||
):
|
||||
self.swipe_up_to_next_live()
|
||||
else:
|
||||
# 兜底:直接调用底层 swipe(基于 1080x2400 基准坐标)
|
||||
try:
|
||||
rx = int(
|
||||
getattr(
|
||||
self,
|
||||
"resolution_ratio_x",
|
||||
1080,
|
||||
)
|
||||
or 1080
|
||||
)
|
||||
ry = int(
|
||||
getattr(
|
||||
self,
|
||||
"resolution_ratio_y",
|
||||
2400,
|
||||
)
|
||||
or 2400
|
||||
)
|
||||
except Exception:
|
||||
rx, ry = 1080, 2400
|
||||
start_x = 540 * rx // 1080
|
||||
start_y = 1200 * ry // 2400
|
||||
end_x = 540 * rx // 1080
|
||||
end_y = 600 * ry // 2400
|
||||
self.operation.swipe(
|
||||
self.device_id,
|
||||
start_x,
|
||||
start_y,
|
||||
end_x,
|
||||
end_y,
|
||||
300,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# basic_join_decision 已经处理了记录与是否切换的逻辑,
|
||||
# 此处不再重复进行上滑切换以避免多次触发
|
||||
elapsed = time.time() - start_time
|
||||
self._log_kv(
|
||||
"流程",
|
||||
|
||||
@@ -2122,27 +2122,19 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
}
|
||||
)
|
||||
|
||||
room_pos_map[room_pos] = room_info
|
||||
analyser._room_pos_to_title_map = room_pos_map
|
||||
|
||||
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",
|
||||
)
|
||||
|
||||
# 序列化运行时映射表到文件,供 GUI 刷新使用
|
||||
# 并行OCR 已生成完整的 fudai_detail,本处不再自动写入运行时映射表或落盘,
|
||||
# 以避免在详情页关闭前产生多余的映射写入。映射的写入由
|
||||
# ReservationHandler.record_room_title_and_pos / SwipeHandler 在切换时负责。
|
||||
try:
|
||||
from douyin.reservation import (
|
||||
douyin_reservation_handler as _rh,
|
||||
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",
|
||||
)
|
||||
|
||||
if hasattr(_rh, "_dump_room_pos_map_to_state"):
|
||||
_rh._dump_room_pos_map_to_state(analyser)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -4869,33 +4861,91 @@ def basic_join_decision(
|
||||
pass
|
||||
try:
|
||||
# 优先使用封装好的上滑切房方法
|
||||
if hasattr(analyser, "swipe_up_to_next_live"):
|
||||
analyser.swipe_up_to_next_live()
|
||||
else:
|
||||
# 兜底:直接调用底层 swipe(基于 1080x2400 基准坐标)
|
||||
try:
|
||||
rx = int(
|
||||
getattr(analyser, "resolution_ratio_x", 1080)
|
||||
or 1080
|
||||
)
|
||||
ry = int(
|
||||
getattr(analyser, "resolution_ratio_y", 2400)
|
||||
or 2400
|
||||
)
|
||||
except Exception:
|
||||
rx, ry = 1080, 2400
|
||||
start_x = 540 * rx // 1080
|
||||
start_y = 1200 * ry // 2400
|
||||
end_x = 540 * rx // 1080
|
||||
end_y = 600 * ry // 2400
|
||||
analyser.operation.swipe(
|
||||
analyser.device_id,
|
||||
start_x,
|
||||
start_y,
|
||||
end_x,
|
||||
end_y,
|
||||
300,
|
||||
try:
|
||||
# 在调用切换前再次检查:如果当前位置映射已经包含福袋信息,
|
||||
# 则跳过切换以避免重复/多余的上滑操作(与 SwipeHandler 中的跳过保持一致)
|
||||
room_pos = int(getattr(analyser, "room_pos", 0) or 0)
|
||||
room_pos_map = (
|
||||
getattr(analyser, "_room_pos_to_title_map", {}) or {}
|
||||
)
|
||||
entry = None
|
||||
if isinstance(room_pos_map, dict):
|
||||
entry = (
|
||||
room_pos_map.get(room_pos)
|
||||
if room_pos in room_pos_map
|
||||
else room_pos_map.get(str(room_pos))
|
||||
)
|
||||
if isinstance(entry, dict) and bool(
|
||||
entry.get("has_fudai", False)
|
||||
):
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 切换前检测到当前位置已有福袋信息,跳过切换",
|
||||
room_pos=room_pos,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
if hasattr(analyser, "swipe_up_to_next_live"):
|
||||
analyser.swipe_up_to_next_live()
|
||||
else:
|
||||
# 兜底:直接调用底层 swipe(基于 1080x2400 基准坐标)
|
||||
try:
|
||||
rx = int(
|
||||
getattr(
|
||||
analyser, "resolution_ratio_x", 1080
|
||||
)
|
||||
or 1080
|
||||
)
|
||||
ry = int(
|
||||
getattr(
|
||||
analyser, "resolution_ratio_y", 2400
|
||||
)
|
||||
or 2400
|
||||
)
|
||||
except Exception:
|
||||
rx, ry = 1080, 2400
|
||||
start_x = 540 * rx // 1080
|
||||
start_y = 1200 * ry // 2400
|
||||
end_x = 540 * rx // 1080
|
||||
end_y = 600 * ry // 2400
|
||||
analyser.operation.swipe(
|
||||
analyser.device_id,
|
||||
start_x,
|
||||
start_y,
|
||||
end_x,
|
||||
end_y,
|
||||
300,
|
||||
)
|
||||
except Exception:
|
||||
# 如果内部检查或调用失败,尝试直接调用封装方法或兜底 swipe
|
||||
try:
|
||||
if hasattr(analyser, "swipe_up_to_next_live"):
|
||||
analyser.swipe_up_to_next_live()
|
||||
else:
|
||||
rx = int(
|
||||
getattr(analyser, "resolution_ratio_x", 1080)
|
||||
or 1080
|
||||
)
|
||||
ry = int(
|
||||
getattr(analyser, "resolution_ratio_y", 2400)
|
||||
or 2400
|
||||
)
|
||||
start_x = 540 * rx // 1080
|
||||
start_y = 1200 * ry // 2400
|
||||
end_x = 540 * rx // 1080
|
||||
end_y = 600 * ry // 2400
|
||||
analyser.operation.swipe(
|
||||
analyser.device_id,
|
||||
start_x,
|
||||
start_y,
|
||||
end_x,
|
||||
end_y,
|
||||
300,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
# 切房失败不影响主流程,直接返回
|
||||
pass
|
||||
|
||||
@@ -104,16 +104,21 @@ class SwipeHandler:
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 如果当前位置已含有福袋信息,跳过立即上滑切换,让后续流程继续执行
|
||||
try:
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 已跳过重复记录,暂停上滑切换以完成后续流程",
|
||||
room_pos=room_pos,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return
|
||||
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
|
||||
|
||||
|
||||
Reference in new issue
Block a user