Keep debug capture history for px and overview

This commit is contained in:
Your Name committed 2026-06-03 22:46:53 +08:00
1 parent ca7d64d54b
commit 0c77bf9e0e
5 files changed
+24 -48

No files matched your search

-36
View File
@@ -13,7 +13,6 @@ from __future__ import annotations
- read_pixel_stage_state_from_screenshot 综合多种检测,返回阶段状态
"""
import os
from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import Any, Optional
@@ -50,40 +49,6 @@ def _live_room_icon_bbox(width: int, height: int) -> tuple[int, int, int, int]:
return _scale_box(get_live_room_icon_bbox(), width, height)
def _cleanup_pixel_stage_debug_images() -> None:
"""Keep the stage pixel diagnosis output to one overview image per latest run."""
try:
from douyin.handlers.screenshot_manager.paths import get_debug_captures_dir
debug_dir = get_debug_captures_dir()
if not os.path.isdir(debug_dir):
return
tokens = (
"_px_pxstage_",
"_px_lottery_",
"_px_attend_",
"_px_fansclub_",
"_px_liveicon_",
"_px_coupon_",
"_px_redpacket_",
"像素检测_抽奖结果",
"像素检测_参与按钮",
"像素检测_fansclub_join",
"像素检测_直播间图标",
"像素检测_阶段像素检测总览",
)
for name in os.listdir(debug_dir):
if not name.lower().endswith(".png"):
continue
if any(token in name for token in tokens):
try:
os.remove(os.path.join(debug_dir, name))
except Exception:
pass
except Exception:
pass
def _save_pixel_stage_overview(
pic_rgb: Image.Image,
state: dict[str, bool],
@@ -187,7 +152,6 @@ def _save_pixel_stage_overview(
for idx, line in enumerate(lines):
draw.text((panel_x, panel_y + idx * 28), line, fill=(255, 255, 255), font=font if idx == 0 else small_font)
_cleanup_pixel_stage_debug_images()
ok_count = sum(1 for value in state.values() if value)
debug_path = douyin_screenshot_manager.save_debug_image(
overview,
-2
View File
@@ -457,8 +457,6 @@ def save_fudai_detail_debug_overview(
return None
try:
cleanup_fudai_detail_debug_captures()
width, height = pic_rgb.size
rx = int(getattr(analyser, "resolution_ratio_x", 1080) or 1080)
ry = int(getattr(analyser, "resolution_ratio_y", 2400) or 2400)
@@ -186,14 +186,14 @@ def maybe_auto_cleanup(auto_cleanup: bool, mgr_log) -> None:
def cleanup_single_operation_debug_images(operation_type: str) -> None:
"""Apply per-operation latest-only policies before saving a new debug image."""
if operation_type not in {"pixel_detect", "detection"}:
"""Apply per-operation cleanup policies before saving a new debug image."""
if operation_type != "detection":
return
try:
debug_dir = get_debug_captures_dir()
if not os.path.isdir(debug_dir):
return
tokens = ("_px_", "像素检测") if operation_type == "pixel_detect" else ("_det_", "检测_福袋图标", "detection_福袋图标")
tokens = ("_det_", "检测_福袋图标", "detection_福袋图标")
for name in os.listdir(debug_dir):
if not name.lower().endswith(".png"):
continue
@@ -213,7 +213,7 @@ def build_debug_filename(
coords: Optional[Tuple[int, int, int, int]],
extra_info: Optional[dict],
) -> str:
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
parts = []
if operation_type:
parts.append(sanitize_filename_part(_SHORT_OPERATION_CODES.get(operation_type, operation_type)))
+3 -3
View File
@@ -169,7 +169,7 @@ def test_fudai_detail_debug_overview_supports_two_task_positions(tmp_path, monke
assert image.getpixel((363, 1413)) == (0, 0, 0)
def test_fudai_detail_debug_overview_cleans_old_detail_images(tmp_path, monkeypatch):
def test_fudai_detail_debug_overview_keeps_existing_detail_images(tmp_path, monkeypatch):
from douyin.core import path_config
from douyin.fudai.core import fudai_debug_utils
@@ -214,8 +214,8 @@ def test_fudai_detail_debug_overview_cleans_old_detail_images(tmp_path, monkeypa
)
assert result
assert not old_detail.exists()
assert not old_overview.exists()
assert old_detail.exists()
assert old_overview.exists()
assert unrelated.exists()
+17 -3
View File
@@ -120,7 +120,7 @@ class TestSaveImageModule:
assert "抽奖结果" not in filename
assert "检测前" not in filename
def test_cleanup_single_operation_debug_images_keeps_only_pixel_latest(self, tmp_path, monkeypatch):
def test_cleanup_single_operation_debug_images_keeps_pixel_history(self, tmp_path, monkeypatch):
from douyin.handlers.screenshot_manager.save_image_helpers import (
cleanup_single_operation_debug_images,
)
@@ -137,8 +137,8 @@ class TestSaveImageModule:
cleanup_single_operation_debug_images("pixel_detect")
assert not (tmp_path / "20260603_像素检测_福袋图标_检测成功.png").exists()
assert not (tmp_path / "20260603_px_pxstage_ov_ok_1.png").exists()
assert (tmp_path / "20260603_像素检测_福袋图标_检测成功.png").exists()
assert (tmp_path / "20260603_px_pxstage_ov_ok_1.png").exists()
assert ocr_file.exists()
def test_detection_debug_filename_uses_short_code(self):
@@ -155,6 +155,20 @@ class TestSaveImageModule:
assert "_det_fdicon_ok_" in filename
assert "福袋" not in filename
def test_build_debug_filename_includes_subsecond_timestamp(self):
from douyin.handlers.screenshot_manager.save_image_helpers import build_debug_filename
filename = build_debug_filename(
"pixel_detect",
"pixel_stage",
"overview",
None,
{"ok": 3},
)
assert filename.endswith(".png")
assert len(filename.split("_", 3)[2]) == 6
def test_cleanup_single_operation_debug_images_cleans_detection_only(self, tmp_path, monkeypatch):
from douyin.handlers.screenshot_manager.save_image_helpers import (
cleanup_single_operation_debug_images,