Skip full countdown OCR in fudai critical path

This commit is contained in:
Your Name committed 2026-06-19 14:30:47 +08:00
1 parent 6b987fd04f
commit 32fcbc4c24
4 files changed
+83 -7

No files matched your search

@@ -83,6 +83,7 @@ def apply_fudai_defaults(self: Any) -> None:
self.fudai_detail_ocr_participants_enabled = False
self.fudai_detail_ocr_live_title_enabled = False
self.fudai_detail_task_ocr_in_critical_path_enabled = False
self.fudai_detail_countdown_full_ocr_in_critical_path_enabled = False
self.pixel_detect_fudai_icon_enabled = True
self.pixel_detect_coupon_popup_enabled = True
self.pixel_detect_shopping_redpacket_enabled = True
+35 -7
View File
@@ -161,6 +161,20 @@ def _should_schedule_task_list_ocr(analyser: Any, ocr_switches: Any) -> bool:
)
def _should_schedule_countdown_full_ocr(analyser: Any, ocr_switches: Any) -> bool:
"""Use split minute/second OCR by default; full-line OCR is an opt-in fallback."""
try:
if not bool(getattr(ocr_switches, "countdown", False)):
return False
except Exception:
return False
return _get_bool_setting(
analyser,
"fudai_detail_countdown_full_ocr_in_critical_path_enabled",
False,
)
def _slowest_ocr_task(durations: Dict[str, Any]) -> str:
if not durations:
return ""
@@ -601,6 +615,11 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
ui_version = str(profile.get("version") or "v2_0")
ocr_switches = FudaiDetailOcrSwitches()
countdown_full_ocr_in_critical_path = _should_schedule_countdown_full_ocr(
analyser,
ocr_switches,
)
try:
setattr(analyser, "fudai_detail_ui_version_active", ui_version)
setattr(analyser, "fudai_detail_ocr_enabled_fields", sorted(ocr_switches.enabled_fields()))
@@ -682,10 +701,17 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
)
except Exception:
pass
# 额外整行倒计时图:用于优先解析 mm:ss,降低分钟框被文案污染的风险。
# 额外整行倒计时图:默认不进关键路径;需要专项兜底时显式开启。
try:
if ocr_switches.countdown:
if countdown_full_ocr_in_critical_path:
analyser.cut_pic(*countdown_box, "", "福袋倒计时_整行", analyser.y_pianyi)
elif ocr_switches.countdown:
analyser._log_kv(
"性能",
"跳过倒计时整行OCR关键路径",
reason="countdown_full_ocr_not_in_critical_path",
enable_key="fudai_detail_countdown_full_ocr_in_critical_path_enabled",
)
except Exception:
pass
# 额外切割倒计时候选区域(用于并行多候选OCR,根治分钟框偏移)
@@ -883,7 +909,8 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
if ocr_switches.countdown:
task_funcs["countdown_mm"] = ocr_countdown_mm
task_funcs["countdown_ss"] = ocr_countdown_ss
task_funcs["countdown_full"] = ocr_countdown_full
if countdown_full_ocr_in_critical_path:
task_funcs["countdown_full"] = ocr_countdown_full
if ocr_switches.value:
task_funcs["value"] = ocr_value
if ocr_switches.button:
@@ -979,7 +1006,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
room_title_hint=str(live_room_title_text_raw or live_room_title_raw or ""),
)
mm_full, ss_full = _parse_mmss_from_full_text(countdown_full_raw)
if mm_full and ss_full:
if countdown_full_ocr_in_critical_path and mm_full and ss_full:
countdown_mm_raw, countdown_ss_raw = mm_full, ss_full
if _detail_verbose_logs(analyser):
try:
@@ -1124,7 +1151,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
room_title_hint=str(live_room_title_text_raw or live_room_title_raw or ""),
)
mm_full_h, ss_full_h = _parse_mmss_from_full_text(countdown_full_raw)
if mm_full_h and ss_full_h:
if countdown_full_ocr_in_critical_path and mm_full_h and ss_full_h:
countdown_mm_raw, countdown_ss_raw = mm_full_h, ss_full_h
if picked_heavy:
picked_heavy_idx = int(picked_heavy.get("idx", -1))
@@ -1306,7 +1333,8 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
if ocr_switches.countdown:
task_funcs["countdown_mm"] = ocr_countdown_mm_fallback
task_funcs["countdown_ss"] = ocr_countdown_ss_fallback
task_funcs["countdown_full"] = ocr_countdown_full_fallback
if countdown_full_ocr_in_critical_path:
task_funcs["countdown_full"] = ocr_countdown_full_fallback
if ocr_switches.value:
task_funcs["value"] = ocr_value_fallback
if ocr_switches.button:
@@ -1388,7 +1416,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
),
)
mm_fb, ss_fb = _parse_mmss_from_full_text(countdown_full_raw_fb)
if mm_fb and ss_fb:
if countdown_full_ocr_in_critical_path and mm_fb and ss_fb:
countdown_mm_raw, countdown_ss_raw = mm_fb, ss_fb
if picked_fb:
picked_fb_idx = int(picked_fb.get("idx", -1))
+1
View File
@@ -413,6 +413,7 @@ class ConfigManager:
"fudai_detail_ocr_participants_enabled": False,
"fudai_detail_ocr_live_title_enabled": False,
"fudai_detail_task_ocr_in_critical_path_enabled": False,
"fudai_detail_countdown_full_ocr_in_critical_path_enabled": False,
}.items():
if key in config:
setattr(analyser, key, bool(config.get(key, default)))
+46
View File
@@ -304,6 +304,52 @@ def test_task_list_ocr_critical_path_requires_explicit_opt_in(monkeypatch):
assert _should_schedule_task_list_ocr(analyser, disabled_switches) is False
def test_countdown_full_ocr_is_not_in_detail_critical_path_by_default(monkeypatch):
from douyin.fudai.douyin_fudai_contain_impl import (
_should_schedule_countdown_full_ocr,
)
from douyin.fudai.douyin_fudai_core_pkg.ocr_switches import (
resolve_fudai_detail_ocr_switches,
)
monkeypatch.setattr(
"douyin.core.path_config.get_config_path",
lambda: "__missing__.json",
)
switches = resolve_fudai_detail_ocr_switches(
{"fudai_detail_ocr_countdown_enabled": True}
)
assert _should_schedule_countdown_full_ocr(SimpleNamespace(), switches) is False
def test_countdown_full_ocr_critical_path_requires_explicit_opt_in(monkeypatch):
from douyin.fudai.douyin_fudai_contain_impl import (
_should_schedule_countdown_full_ocr,
)
from douyin.fudai.douyin_fudai_core_pkg.ocr_switches import (
resolve_fudai_detail_ocr_switches,
)
monkeypatch.setattr(
"douyin.core.path_config.get_config_path",
lambda: "__missing__.json",
)
switches = resolve_fudai_detail_ocr_switches(
{"fudai_detail_ocr_countdown_enabled": True}
)
disabled_switches = resolve_fudai_detail_ocr_switches(
{"fudai_detail_ocr_countdown_enabled": False}
)
analyser = SimpleNamespace(
fudai_detail_countdown_full_ocr_in_critical_path_enabled=True,
)
assert _should_schedule_countdown_full_ocr(analyser, switches) is True
assert _should_schedule_countdown_full_ocr(analyser, disabled_switches) is False
def test_config_manager_loads_fudai_detail_ui_and_ocr_switches(tmp_path):
from douyin.utils.douyin_config import ConfigManager