Fix v2 fudai detail recognition

This commit is contained in:
Your Name committed 2026-06-18 13:27:27 +08:00
1 parent fc96549bd2
commit 8dbaab9d27
6 files changed
+106 -12

No files matched your search

@@ -0,0 +1,9 @@
# 2026-06-18 真机福袋诊断 handoff
- 设备:`192.168.10.100:45967`,前台为 `com.ss.android.ugc.aweme/.live.LivePlayActivity`。
- 已修 1:无福袋房间继承旧 `_current_fudai_content`,提交 `22e2ed1`,复测 `artifacts/live_fudai_flow_20260618_124737` 里无福袋位置 `2/3/6/8/9` 均为空内容。
- 已修 2:v2 双任务详情区域偏低,导致巴图 4999 福袋倒计时/内容裁剪到标题行;样本已保存到 `tests/fixtures/fudai_detail_v2_two_task_batu_4999_regions.png`。
- 已修 3:`0元带走¥999参考价值` 被价值校验器误判为 `value_raw_mismatch_parsed_value`。
- 复测证据:`artifacts/live_fudai_flow_20260618_130639` 中 13:10:20 识别 `【粉丝专享】左上角领取散热风`、`07:59`、`999元`,并写入预约,优惠券弹窗出现时日志为跳过福袋点击。
- 未充分覆盖:预约回退未进入实际执行窗口,日志均为 `时间窗口未到`;需后续更长轮验证。
- 待盯:关注列表当前可能直播间数量少或滑动未换房,短轮 `artifacts/live_fudai_flow_20260618_131658` 多次触发同房三连/回顶。
+24 -3
View File
@@ -123,9 +123,9 @@ DETAIL_UI_LEGACY = {
DETAIL_UI_V2_0 = {
"version": "v2_0",
"content": (360, 1410, 1035, 1495),
"value": (300, 1585, 650, 1685),
"countdown_full": (760, 1328, 1038, 1398),
"content": (365, 1368, 1040, 1465),
"value": (300, 1518, 650, 1615),
"countdown_full": (760, 1265, 1040, 1345),
"task_list": (60, 1840, 1030, 2005),
"task_count": (860, 1770, 1035, 1875),
"participants": (520, 1325, 760, 1415),
@@ -153,6 +153,14 @@ FUDAI_DETAIL_REGION_DEFAULTS = {
"v2_0_one_task": DETAIL_UI_V2_0_ONE_TASK,
}
STALE_DETAIL_REGION_DEFAULTS = {
"v2_0_two_task": {
"content": (360, 1410, 1035, 1495),
"value": (300, 1585, 650, 1685),
"countdown_full": (760, 1328, 1038, 1398),
}
}
PIXEL_REGION_DEFAULTS = {
"lottery_result": {
"button": LOTTERY_RESULT_CONFIRM_BUTTON_V2,
@@ -208,6 +216,18 @@ def _apply_region_overrides(defaults: dict[str, Any], overrides: Any) -> dict[st
return merged
def _drop_stale_region_overrides(profile_key: str, overrides: dict[str, Any]) -> dict[str, Any]:
stale = STALE_DETAIL_REGION_DEFAULTS.get(profile_key, {})
if not stale:
return dict(overrides)
cleaned = dict(overrides)
for key, old_value in stale.items():
parsed = _tuple4(cleaned.get(key))
if parsed is not None and parsed == tuple(old_value):
cleaned.pop(key, None)
return cleaned
def get_fudai_detail_profile(mode: str | None = "auto", task_count: int | None = None) -> dict:
profile_key = _detail_profile_key(mode, task_count)
defaults = FUDAI_DETAIL_REGION_DEFAULTS[profile_key]
@@ -215,6 +235,7 @@ def get_fudai_detail_profile(mode: str | None = "auto", task_count: int | None =
overrides = _deep_get(cfg, "fudai_detail_regions", profile_key)
if not isinstance(overrides, dict) or not overrides:
return defaults
overrides = _drop_stale_region_overrides(profile_key, overrides)
return _apply_region_overrides(defaults, overrides)
+10 -6
View File
@@ -238,16 +238,18 @@ def validate_fudai_detail(detail: Tuple, analyser: Any = None) -> Tuple[bool, st
# 检查原始文本是否包含合理的价值信息
import re
# 查找数字模式(如:9999, 9999元, 价值9999等)
# 查找所有可能金额。营销文案常见“0元带走¥999参考价值”,
# 不能只看第一个数字,否则会把已正确解析出的参考价值误判失败。
value_patterns = [
r"(\d+(?:\.\d+)?)", # 纯数字
r"价值[::\s]*(\d+(?:\.\d+)?)", # 价值XXX
r"(\d+(?:\.\d+)?)元", # XXX元
r"[¥¥]\s*(\d+(?:\.\d+)?)",
r"(\d+(?:\.\d+)?)\s*参考价值",
r"价值[::\s¥¥]*(\d+(?:\.\d+)?)",
r"(\d+(?:\.\d+)?)元",
r"(\d+(?:\.\d+)?)",
]
found_value = False
for pattern in value_patterns:
match = re.search(pattern, value_raw)
if match:
for match in re.finditer(pattern, value_raw):
try:
extracted_value = float(match.group(1))
if (
@@ -257,6 +259,8 @@ def validate_fudai_detail(detail: Tuple, analyser: Any = None) -> Tuple[bool, st
break
except ValueError:
continue
if found_value:
break
if (
not found_value and len(value_raw) > 3
): # 只有当原始文本较长时才验证
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

+48 -3
View File
@@ -28,9 +28,9 @@ def test_v2_profile_keeps_legacy_and_adds_expected_regions(monkeypatch):
assert auto is DETAIL_UI_V2_0
assert one_task is DETAIL_UI_V2_0_ONE_TASK
assert DETAIL_UI_LEGACY["content"] == (389, 1273, 1000, 1534)
assert DETAIL_UI_V2_0["content"] == (360, 1410, 1035, 1495)
assert DETAIL_UI_V2_0["value"] == (300, 1585, 650, 1685)
assert DETAIL_UI_V2_0["countdown_full"] == (760, 1328, 1038, 1398)
assert DETAIL_UI_V2_0["content"] == (365, 1368, 1040, 1465)
assert DETAIL_UI_V2_0["value"] == (300, 1518, 650, 1615)
assert DETAIL_UI_V2_0["countdown_full"] == (760, 1265, 1040, 1345)
assert DETAIL_UI_V2_0["task_list"] == (60, 1840, 1030, 2005)
assert DETAIL_UI_V2_0["task_count"] == (860, 1770, 1035, 1875)
assert DETAIL_UI_V2_0["participants"] == (520, 1325, 760, 1415)
@@ -103,6 +103,51 @@ def test_detail_profile_ignores_invalid_config_overrides(monkeypatch):
assert profile["content"] == coords.DETAIL_UI_V2_0["content"]
def test_detail_profile_ignores_stale_v2_two_task_runtime_defaults(monkeypatch):
from douyin.fudai.core import coords
monkeypatch.setattr(
coords,
"_read_runtime_region_config",
lambda: {
"fudai_detail_regions": {
"v2_0_two_task": {
"content": [360, 1410, 1035, 1495],
"value": [300, 1585, 650, 1685],
"countdown_full": [760, 1328, 1038, 1398],
}
}
},
)
profile = coords.get_fudai_detail_profile("v2_0", task_count=2)
assert profile["content"] == coords.DETAIL_UI_V2_0["content"]
assert profile["value"] == coords.DETAIL_UI_V2_0["value"]
assert profile["countdown_full"] == coords.DETAIL_UI_V2_0["countdown_full"]
def test_v2_two_task_profile_covers_batu_4999_sample_regions():
from PIL import Image
from pathlib import Path
from douyin.fudai.core.coords import DETAIL_UI_V2_0
sample = Path("tests/fixtures/fudai_detail_v2_two_task_batu_4999_regions.png")
if not sample.exists():
pytest.skip("batu 4999 debug sample is unavailable")
img = Image.open(sample).convert("RGB")
def crop_has_bright_text(box):
crop = img.crop(box)
pixels = list(crop.getdata())
bright = sum(1 for r, g, b in pixels if r > 185 and g > 185 and b > 185)
return bright / max(1, len(pixels))
assert crop_has_bright_text(DETAIL_UI_V2_0["countdown_full"]) > 0.01
assert crop_has_bright_text(DETAIL_UI_V2_0["content"]) > 0.01
def test_ocr_switch_defaults_and_legacy_disable_compat():
from douyin.fudai.douyin_fudai_core_pkg.ocr_switches import (
FudaiDetailOcrSwitches,
+15
View File
@@ -80,6 +80,21 @@ class TestValidateFudaiDetail:
assert isinstance(is_valid, bool)
assert isinstance(reason, str)
def test_value_raw_accepts_zero_yuan_marketing_prefix(self):
from types import SimpleNamespace
from douyin.fudai.core.fudai_detail_validator import validate_fudai_detail
analyser = SimpleNamespace(
value_raw="0元带走¥999参考价值",
countdown_mm_raw="07",
countdown_ss_raw="59",
)
detail = ("福袋内容", "07:59", 0, 0, 999.0, (1000.0, 1479.0))
is_valid, reason = validate_fudai_detail(detail, analyser)
assert is_valid is True, reason
class TestFudaiDetailShimConsistency:
"""验证 fudai_detail shim 与子模块导出一致。"""