fix: avoid live-room back on fudai retry
This commit is contained in:
1 parent
5c7d341d9b
commit
f95832579a
6 files changed
+98
-18
No files matched your search
@@ -77,20 +77,23 @@ def _close_wrong_fudai_target(
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
analyser.operation.click_back(device_id)
|
||||
except Exception:
|
||||
stage_text = str(stage or "")
|
||||
if stage_text in ("IN_LIVE_ROOM", "UNKNOWN", ""):
|
||||
try:
|
||||
analyser.operation.back(device_id)
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"find_and_open_fudai_detail:误入口仍处于直播间,不执行关闭点击或返回键",
|
||||
stage=stage_text,
|
||||
decision="skip_close_action_same_live_room",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
analyser.operation.click_back(device_id)
|
||||
except Exception:
|
||||
try:
|
||||
rx = int(getattr(analyser, "resolution_ratio_x", 1080) or 1080)
|
||||
ry = int(getattr(analyser, "resolution_ratio_y", 2400) or 2400)
|
||||
analyser.operation.click(
|
||||
device_id,
|
||||
int(520 * rx / 1080),
|
||||
int(505 * ry / 2400),
|
||||
)
|
||||
analyser.operation.back(device_id)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
|
||||
@@ -67,8 +67,7 @@ class FudaiDetector:
|
||||
真机样本显示可点击入口集中在左侧;右侧福利/消费券横幅也会出现相同礼物色,
|
||||
不能进入福袋详情,避免纳入搜索。
|
||||
"""
|
||||
# 旧区域 X=153..561/Y=348..451 里右侧已被直播间营销券横幅污染。
|
||||
# 2026-06-18 真机 light6 成功点击集中在 x=83..209,失败券条候选出现在 x=366。
|
||||
# 只扫描左上真实小福袋入口热区;下方大福袋动画/背景挂件不能参与入口判断。
|
||||
self.search_regions = [
|
||||
{
|
||||
"name": "实际福袋区域",
|
||||
@@ -76,9 +75,9 @@ class FudaiDetector:
|
||||
"x1": 20 * self.rx // 1080,
|
||||
"x2": 280 * self.rx // 1080,
|
||||
"y_top": 348 * self.ry // 2400 + self.y_pianyi,
|
||||
"y_bottom": 540 * self.ry // 2400 + self.y_pianyi,
|
||||
"y": (348 + 540) // 2 * self.ry // 2400 + self.y_pianyi,
|
||||
"y_range": (540 - 348) // 2 + 1,
|
||||
"y_bottom": 455 * self.ry // 2400 + self.y_pianyi,
|
||||
"y": (348 + 455) // 2 * self.ry // 2400 + self.y_pianyi,
|
||||
"y_range": (455 - 348) // 2 + 1,
|
||||
},
|
||||
]
|
||||
|
||||
@@ -557,7 +556,7 @@ class FudaiDetector:
|
||||
x1 = max(0, detected_x_scaled - 180)
|
||||
x2 = min(width, detected_x_scaled + 180)
|
||||
y1 = max(0, int(300 * self.ry / 2400) + self.y_pianyi)
|
||||
y2 = min(height, int(540 * self.ry / 2400) + self.y_pianyi)
|
||||
y2 = min(height, int(455 * self.ry / 2400) + self.y_pianyi)
|
||||
if x1 >= x2 or y1 >= y2:
|
||||
return False
|
||||
roi_gray = cv2.cvtColor( # type: ignore[attr-defined]
|
||||
|
||||
@@ -47,6 +47,28 @@ def _emit_flow_flag(analyser: Any, flag: str, status: str, **extra) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def _looks_like_non_live_tab_title(title: str, raw_title: str = "") -> bool:
|
||||
"""Detect recommendation/top-tab OCR text that must not pollute room_pos_map."""
|
||||
text = f"{title or ''}{raw_title or ''}"
|
||||
normalized = (
|
||||
str(text or "")
|
||||
.replace(" ", "")
|
||||
.replace("·", "")
|
||||
.replace(".", "")
|
||||
.replace("。", "")
|
||||
.replace("=", "")
|
||||
.strip()
|
||||
)
|
||||
if not normalized:
|
||||
return False
|
||||
tab_keywords = ("购精选", "精选商城", "商城关注", "关注直播推荐", "商城关注直播推荐")
|
||||
if any(keyword in normalized for keyword in tab_keywords):
|
||||
return True
|
||||
if normalized in ("购精选商城", "精选商城关注直播推荐", "商城关注直播推荐"):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _merge_room_info(base: dict[str, Any], extra: dict[str, Any]) -> dict[str, Any]:
|
||||
"""把 extra 信息合并到 base,优先保留已有强信息。"""
|
||||
try:
|
||||
@@ -402,6 +424,30 @@ def record_room_title_and_pos(analyser: Any) -> bool:
|
||||
room_title = str(existing_info.get("title", "") or "").strip()
|
||||
room_title_raw = str(existing_info.get("title_raw", "") or "").strip()
|
||||
|
||||
if _looks_like_non_live_tab_title(room_title, room_title_raw):
|
||||
try:
|
||||
analyser.current_room_title = ""
|
||||
analyser.current_room_title_raw = ""
|
||||
except Exception:
|
||||
pass
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 跳过映射表记录:识别到非直播间标签栏标题",
|
||||
room_pos=room_pos,
|
||||
room_title=room_title,
|
||||
room_title_raw=room_title_raw,
|
||||
reason="non_live_tab_title",
|
||||
level="WARNING",
|
||||
)
|
||||
_emit_flow_flag(
|
||||
analyser,
|
||||
"room_map_record",
|
||||
"skip_non_live_tab_title",
|
||||
room_pos=room_pos,
|
||||
room_title=room_title[:50],
|
||||
)
|
||||
return False
|
||||
|
||||
room_info["title"] = room_title
|
||||
room_info["title_raw"] = room_title_raw
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ def test_find_open_retries_same_room_after_wrong_target(tmp_path):
|
||||
assert find_and_open_fudai_detail(analyser) is True
|
||||
|
||||
assert analyser.operation.click.call_count == 2
|
||||
analyser.operation.click_back.assert_called_once_with("MOCK")
|
||||
analyser.operation.click_back.assert_not_called()
|
||||
verdicts = [
|
||||
kwargs.get("verdict")
|
||||
for args, kwargs in analyser._log_kv.call_args_list
|
||||
@@ -88,3 +88,5 @@ def test_find_open_retries_same_room_after_wrong_target(tmp_path):
|
||||
]
|
||||
assert "wrong_target_retry_same_room" in verdicts
|
||||
assert "detail_recognized" in verdicts
|
||||
flow_msgs = [args[1] for args, _kwargs in analyser._log_kv.call_args_list if args and args[0] == "流程"]
|
||||
assert "find_and_open_fudai_detail:误入口仍处于直播间,不执行关闭点击或返回键" in flow_msgs
|
||||
@@ -104,6 +104,15 @@ class TestFudaiDetector:
|
||||
assert hasattr(d, "search_regions")
|
||||
assert isinstance(d.search_regions, list)
|
||||
|
||||
def test_search_region_stays_on_small_top_left_icon_height(self):
|
||||
d = FudaiDetector(FakeAnalyser())
|
||||
region = d.search_regions[0]
|
||||
|
||||
assert region["x1"] == 20
|
||||
assert region["x2"] == 280
|
||||
assert region["y_top"] == 348
|
||||
assert region["y_bottom"] == 455
|
||||
|
||||
def test_detect_methods_callable(self):
|
||||
d = FudaiDetector(FakeAnalyser())
|
||||
for name in (
|
||||
|
||||
@@ -89,6 +89,27 @@ def test_similar_long_titles_are_merged_to_smaller_pos():
|
||||
assert a._room_pos_to_title_map[3]["merged_positions"] == [3, 4]
|
||||
|
||||
|
||||
def test_recommend_tab_title_is_not_recorded_to_room_map():
|
||||
from douyin.reservation.douyin_reservation_handler_pkg import record_title as mod
|
||||
|
||||
a = _mk_analyser()
|
||||
a.room_pos = 15
|
||||
a.current_room_title = "购精选商城"
|
||||
a.current_room_title_raw = "购·精选·商城."
|
||||
a._room_title_identified_positions = {15}
|
||||
a._room_pos_to_title_map = {13: {"title": "聚亿奢首", "title_raw": "聚亿奢首"}}
|
||||
|
||||
with patch.object(mod, "_dump_room_pos_map_to_state", return_value=None):
|
||||
consumed = mod.record_room_title_and_pos(a)
|
||||
|
||||
assert consumed is False
|
||||
assert 15 not in a._room_pos_to_title_map
|
||||
assert str(15) not in a._room_pos_to_title_map
|
||||
assert a._room_pos_to_title_map[13]["title"] == "聚亿奢首"
|
||||
assert a.current_room_title == ""
|
||||
assert a.current_room_title_raw == ""
|
||||
|
||||
|
||||
def test_merge_room_info_keeps_explicit_no_fudai_state():
|
||||
from douyin.reservation.douyin_reservation_handler_pkg import record_title as mod
|
||||
|
||||
|
||||
Reference in new issue
Block a user