feat: expose fudai region coordinates in gui
This commit is contained in:
1 parent
bcc4d1151f
commit
4797fa046e
17 files changed
+1044
-119
No files matched your search
@@ -35,13 +35,13 @@ def test_fudai_detail_debug_overview_saves_one_annotated_image(tmp_path, monkeyp
|
||||
{
|
||||
"key": "content",
|
||||
"name": "内容",
|
||||
"coords": (300, 1400, 1030, 1515),
|
||||
"coords": (360, 1460, 1035, 1545),
|
||||
"enabled": True,
|
||||
},
|
||||
{
|
||||
"key": "participants",
|
||||
"name": "人数",
|
||||
"coords": (520, 1325, 760, 1415),
|
||||
"coords": (516, 1396, 743, 1443),
|
||||
"enabled": False,
|
||||
},
|
||||
],
|
||||
@@ -91,13 +91,13 @@ def test_fudai_detail_debug_labels_are_inside_region_edges(tmp_path, monkeypatch
|
||||
{
|
||||
"key": "countdown",
|
||||
"name": "倒计时",
|
||||
"coords": (760, 1355, 1035, 1455),
|
||||
"coords": (730, 1338, 1038, 1418),
|
||||
"enabled": True,
|
||||
},
|
||||
{
|
||||
"key": "content",
|
||||
"name": "内容",
|
||||
"coords": (360, 1472, 1035, 1545),
|
||||
"coords": (360, 1460, 1035, 1545),
|
||||
"enabled": True,
|
||||
},
|
||||
],
|
||||
@@ -112,9 +112,61 @@ def test_fudai_detail_debug_labels_are_inside_region_edges(tmp_path, monkeypatch
|
||||
image, _kwargs = saved[0]
|
||||
# Labels are now drawn adjacent to their own boxes, not floating above
|
||||
# another OCR field.
|
||||
assert image.getpixel((763, 1358)) == (0, 0, 0)
|
||||
assert image.getpixel((363, 1475)) == (0, 0, 0)
|
||||
assert image.getpixel((363, 1444)) != (0, 0, 0)
|
||||
assert image.getpixel((767, 1348)) == (0, 0, 0)
|
||||
assert image.getpixel((363, 1463)) == (0, 0, 0)
|
||||
assert image.getpixel((363, 1438)) != (0, 0, 0)
|
||||
|
||||
|
||||
def test_fudai_detail_debug_overview_supports_two_task_positions(tmp_path, monkeypatch):
|
||||
from douyin.core import path_config
|
||||
from douyin.fudai.core import fudai_debug_utils
|
||||
|
||||
screenshot = tmp_path / "screenshot.png"
|
||||
Image.new("RGB", (1080, 2400), "white").save(screenshot)
|
||||
saved = []
|
||||
|
||||
def fake_save_debug_image(image, **kwargs):
|
||||
saved.append((image.copy(), kwargs))
|
||||
return str(tmp_path / "overview.png")
|
||||
|
||||
monkeypatch.setattr(path_config, "get_screenshot_path", lambda: str(screenshot))
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.douyin_screenshot_manager.save_debug_image",
|
||||
fake_save_debug_image,
|
||||
)
|
||||
|
||||
analyser = SimpleNamespace(
|
||||
resolution_ratio_x=1080,
|
||||
resolution_ratio_y=2400,
|
||||
_log_kv=lambda *args, **kwargs: None,
|
||||
)
|
||||
|
||||
result = fudai_debug_utils.save_fudai_detail_debug_overview(
|
||||
analyser,
|
||||
[
|
||||
{
|
||||
"key": "countdown",
|
||||
"name": "倒计时",
|
||||
"coords": (760, 1328, 1038, 1398),
|
||||
"enabled": True,
|
||||
},
|
||||
{
|
||||
"key": "content",
|
||||
"name": "内容",
|
||||
"coords": (360, 1410, 1035, 1495),
|
||||
"enabled": True,
|
||||
},
|
||||
],
|
||||
ui_version="v2_0",
|
||||
ocr_enabled={"countdown", "content"},
|
||||
task_count=2,
|
||||
task_count_source="v2_pixels",
|
||||
)
|
||||
|
||||
assert result
|
||||
image, _kwargs = saved[0]
|
||||
assert image.getpixel((763, 1331)) == (0, 0, 0)
|
||||
assert image.getpixel((363, 1413)) == (0, 0, 0)
|
||||
|
||||
|
||||
def test_fudai_detail_debug_overview_cleans_old_detail_images(tmp_path, monkeypatch):
|
||||
@@ -165,3 +217,53 @@ def test_fudai_detail_debug_overview_cleans_old_detail_images(tmp_path, monkeypa
|
||||
assert not old_detail.exists()
|
||||
assert not old_overview.exists()
|
||||
assert unrelated.exists()
|
||||
|
||||
|
||||
def test_fudai_detail_debug_overview_uses_configured_profile_coords(tmp_path, monkeypatch):
|
||||
from douyin.core import path_config
|
||||
from douyin.fudai.core import coords as coords_mod
|
||||
from douyin.fudai.core import fudai_debug_utils
|
||||
|
||||
screenshot = tmp_path / "screenshot.png"
|
||||
Image.new("RGB", (1080, 2400), "white").save(screenshot)
|
||||
saved = []
|
||||
|
||||
def fake_save_debug_image(image, **kwargs):
|
||||
saved.append((image.copy(), kwargs))
|
||||
return str(tmp_path / "overview.png")
|
||||
|
||||
monkeypatch.setattr(path_config, "get_screenshot_path", lambda: str(screenshot))
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.douyin_screenshot_manager.save_debug_image",
|
||||
fake_save_debug_image,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
coords_mod,
|
||||
"_read_runtime_region_config",
|
||||
lambda: {
|
||||
"fudai_detail_regions": {
|
||||
"v2_0_two_task": {
|
||||
"content": [111, 222, 333, 444],
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
analyser = SimpleNamespace(
|
||||
resolution_ratio_x=1080,
|
||||
resolution_ratio_y=2400,
|
||||
_log_kv=lambda *args, **kwargs: None,
|
||||
)
|
||||
profile = coords_mod.get_fudai_detail_profile("v2_0", task_count=2)
|
||||
|
||||
result = fudai_debug_utils.save_fudai_detail_debug_overview(
|
||||
analyser,
|
||||
[{"key": "content", "name": "内容", "coords": profile["content"], "enabled": True}],
|
||||
ui_version="v2_0",
|
||||
ocr_enabled={"content"},
|
||||
task_count=2,
|
||||
)
|
||||
|
||||
assert result
|
||||
image, _kwargs = saved[0]
|
||||
assert image.getpixel((114, 225)) == (0, 0, 0)
|
||||
@@ -24,24 +24,81 @@ def test_v2_profile_keeps_legacy_and_adds_expected_regions():
|
||||
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, 1472, 1035, 1545)
|
||||
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, 1355, 1035, 1455)
|
||||
assert DETAIL_UI_V2_0["countdown_full"] == (760, 1328, 1038, 1398)
|
||||
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)
|
||||
assert DETAIL_UI_V2_0["button"] == (70, 2020, 1010, 2165)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["content"] == (360, 1472, 1035, 1545)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["value"] == (340, 1680, 690, 1765)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["countdown_full"] == (760, 1355, 1035, 1455)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["task_list"] == (55, 1935, 900, 2055)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["task_count"] == (890, 1855, 1040, 1950)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["participants"] == (535, 1375, 760, 1475)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["button"] == (70, 2055, 1010, 2225)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["content"] == (360, 1460, 1035, 1545)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["value"] == (350, 1640, 760, 1735)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["countdown_full"] == (730, 1338, 1038, 1418)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["info_line"] == (430, 1315, 1055, 1435)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["task_list"] == (60, 1845, 885, 2005)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["task_count"] == (890, 1855, 1040, 1960)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["participants"] == (516, 1396, 743, 1443)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["button"] == (70, 2050, 1010, 2195)
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["task_list"][1] > DETAIL_UI_V2_0["task_list"][1]
|
||||
assert DETAIL_UI_V2_0_ONE_TASK["button"][1] > DETAIL_UI_V2_0["button"][1]
|
||||
|
||||
|
||||
def test_detail_profile_prefers_config_overrides(monkeypatch):
|
||||
from douyin.fudai.core import coords
|
||||
|
||||
override = {
|
||||
"fudai_detail_regions": {
|
||||
"v2_0_two_task": {
|
||||
"content": [1, 2, 3, 4],
|
||||
},
|
||||
"v2_0_one_task": {
|
||||
"info_line": [11, 22, 33, 44],
|
||||
},
|
||||
"legacy": {
|
||||
"button": [101, 202, 303, 404],
|
||||
},
|
||||
},
|
||||
"pixel_regions": {
|
||||
"lottery_result": {
|
||||
"pixel": [7, 8, 9, 10],
|
||||
"click": [66, 77, 0, 0],
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
monkeypatch.setattr(coords, "_read_runtime_region_config", lambda: override)
|
||||
|
||||
legacy = coords.get_fudai_detail_profile("legacy")
|
||||
v2_two = coords.get_fudai_detail_profile("v2_0", task_count=2)
|
||||
v2_one = coords.get_fudai_detail_profile("v2_0", task_count=1)
|
||||
lottery = coords.get_lottery_result_confirm_profile("v2_0")
|
||||
|
||||
assert legacy["button"] == (101, 202, 303, 404)
|
||||
assert v2_two["content"] == (1, 2, 3, 4)
|
||||
assert v2_one["info_line"] == (11, 22, 33, 44)
|
||||
assert lottery["pixel"] == (7, 8, 9, 10)
|
||||
assert lottery["click"] == (66, 77)
|
||||
|
||||
|
||||
def test_detail_profile_ignores_invalid_config_overrides(monkeypatch):
|
||||
from douyin.fudai.core import coords
|
||||
|
||||
monkeypatch.setattr(
|
||||
coords,
|
||||
"_read_runtime_region_config",
|
||||
lambda: {
|
||||
"fudai_detail_regions": {
|
||||
"v2_0_two_task": {
|
||||
"content": [1, 2, 3],
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
profile = coords.get_fudai_detail_profile("v2_0", task_count=2)
|
||||
assert profile["content"] == coords.DETAIL_UI_V2_0["content"]
|
||||
|
||||
|
||||
def test_ocr_switch_defaults_and_legacy_disable_compat():
|
||||
from douyin.fudai.douyin_fudai_core_pkg.ocr_switches import (
|
||||
FudaiDetailOcrSwitches,
|
||||
|
||||
@@ -137,6 +137,27 @@ class TestFudaiDetailOcrGuiConfig:
|
||||
):
|
||||
assert key in vars_
|
||||
|
||||
def test_build_config_vars_exposes_region_coordinate_fields(self, monkeypatch):
|
||||
import tkinter as tk
|
||||
|
||||
from gui.components.config_vars import build_config_vars
|
||||
|
||||
monkeypatch.setattr(tk, "StringVar", lambda value="": MagicMock(get=lambda: value, set=lambda _v: None))
|
||||
monkeypatch.setattr(tk, "BooleanVar", lambda value=False: MagicMock(get=lambda: value, set=lambda _v: None))
|
||||
monkeypatch.setattr(tk, "IntVar", lambda value=0: MagicMock(get=lambda: value, set=lambda _v: None))
|
||||
monkeypatch.setattr(tk, "DoubleVar", lambda value=0.0: MagicMock(get=lambda: value, set=lambda _v: None))
|
||||
|
||||
vars_ = build_config_vars({})
|
||||
|
||||
for key in (
|
||||
"fudai_detail_regions_legacy_content_x1_var",
|
||||
"fudai_detail_regions_v2_0_two_task_content_x1_var",
|
||||
"fudai_detail_regions_v2_0_one_task_info_line_x1_var",
|
||||
"pixel_regions_lottery_result_pixel_x1_var",
|
||||
"pixel_regions_live_room_icon_bbox_x1_var",
|
||||
):
|
||||
assert key in vars_
|
||||
|
||||
|
||||
class TestWriteConfig:
|
||||
def test_write_and_read_roundtrip(self):
|
||||
@@ -186,6 +207,31 @@ class TestWriteConfig:
|
||||
assert saved["alpha"] == 1
|
||||
assert saved["beta"] == 2
|
||||
|
||||
def test_write_config_retries_replace_on_permission_error(self, tmp_path, monkeypatch):
|
||||
from gui.gui_core_pkg import config as cfg_mod
|
||||
|
||||
cfg_path = tmp_path / "config.json"
|
||||
cfg_path.write_text(json.dumps({"base": 1}, ensure_ascii=False), encoding="utf-8")
|
||||
monkeypatch.setattr(cfg_mod, "CONFIG_PATH", str(cfg_path))
|
||||
|
||||
real_replace = os.replace
|
||||
calls = {"count": 0}
|
||||
|
||||
def flaky_replace(src, dst):
|
||||
calls["count"] += 1
|
||||
if calls["count"] == 1:
|
||||
raise PermissionError("locked")
|
||||
return real_replace(src, dst)
|
||||
|
||||
monkeypatch.setattr(cfg_mod.os, "replace", flaky_replace)
|
||||
|
||||
cfg_mod.write_config({"alpha": 1})
|
||||
|
||||
saved = json.loads(cfg_path.read_text(encoding="utf-8"))
|
||||
assert saved["base"] == 1
|
||||
assert saved["alpha"] == 1
|
||||
assert calls["count"] >= 2
|
||||
|
||||
|
||||
# ============================================================
|
||||
# adb.py — find_adb_executable / list_adb_devices / resolve_adb_device
|
||||
|
||||
@@ -140,6 +140,31 @@ def test_config_accepts_fudai_detail_v2_ocr_switches_and_ui_mode(monkeypatch):
|
||||
assert written["fudai_detail_ocr_participants_enabled"] is False
|
||||
|
||||
|
||||
def test_config_accepts_region_coordinate_arrays(monkeypatch):
|
||||
written = {}
|
||||
|
||||
monkeypatch.setattr(routes, "read_config", lambda: {})
|
||||
monkeypatch.setattr(routes, "write_config", lambda cfg: written.update(cfg))
|
||||
|
||||
status, obj = _post(
|
||||
"/api/config",
|
||||
{
|
||||
"config": {
|
||||
"fudai_detail_regions.v2_0_one_task.info_line": [430, 1315, 1055, 1435],
|
||||
"pixel_regions.lottery_result.pixel": ["290", "1300", "790", "1415"],
|
||||
"pixel_regions.live_room_icon_bbox": [999, 172, 1028, 202],
|
||||
}
|
||||
},
|
||||
monkeypatch,
|
||||
)
|
||||
|
||||
assert status == 200
|
||||
assert obj.get("ok") is True
|
||||
assert written["fudai_detail_regions"]["v2_0_one_task"]["info_line"] == [430, 1315, 1055, 1435]
|
||||
assert written["pixel_regions"]["lottery_result"]["pixel"] == [290, 1300, 790, 1415]
|
||||
assert written["pixel_regions"]["live_room_icon_bbox"] == [999, 172, 1028, 202]
|
||||
|
||||
|
||||
def test_config_rejects_invalid_fudai_detail_ui_mode(monkeypatch):
|
||||
written = {"fudai_detail_ui_mode": "legacy"}
|
||||
|
||||
|
||||
Reference in new issue
Block a user