Fix fudai diagnostics and redpacket guard
This commit is contained in:
1 parent
cb74a23e81
commit
28709d2d97
11 files changed
+245
-4
No files matched your search
@@ -124,7 +124,7 @@ DETAIL_UI_LEGACY = {
|
||||
DETAIL_UI_V2_0 = {
|
||||
"version": "v2_0",
|
||||
"content": (365, 1368, 1040, 1465),
|
||||
"value": (300, 1518, 650, 1615),
|
||||
"value": (300, 1518, 820, 1695),
|
||||
"countdown_full": (760, 1265, 1040, 1345),
|
||||
"task_list": (60, 1840, 1030, 2005),
|
||||
"task_count": (860, 1770, 1035, 1875),
|
||||
@@ -158,7 +158,7 @@ STALE_DETAIL_REGION_DEFAULTS = {
|
||||
"content": (360, 1410, 1035, 1495),
|
||||
"value": (300, 1585, 650, 1685),
|
||||
"countdown_full": (760, 1328, 1038, 1398),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
PIXEL_REGION_DEFAULTS = {
|
||||
|
||||
@@ -718,6 +718,112 @@ class FudaiDetector:
|
||||
except Exception as exc:
|
||||
return False, {"commercial_overlay_error": str(exc)}
|
||||
|
||||
def _is_commercial_redpacket_widget(self, arr: Any) -> Tuple[bool, Dict[str, Any]]:
|
||||
"""Detect left-side shopping/live redpacket widgets near the fudai slot."""
|
||||
try:
|
||||
import numpy as np # type: ignore[import-untyped]
|
||||
|
||||
height, width = arr.shape[:2]
|
||||
if height <= 0 or width <= 0:
|
||||
return False, {"reason": "empty_window"}
|
||||
|
||||
r = arr[:, :, 0]
|
||||
g = arr[:, :, 1]
|
||||
b = arr[:, :, 2]
|
||||
|
||||
pink_body = (
|
||||
(r >= 205)
|
||||
& (g >= 25)
|
||||
& (g <= 120)
|
||||
& (b >= 95)
|
||||
& (b <= 190)
|
||||
)
|
||||
pale_badge = (r >= 230) & (g >= 150) & (b >= 130)
|
||||
orange_badge = (r >= 220) & (g >= 120) & (g <= 205) & (b <= 120)
|
||||
avatar_like = (
|
||||
(r >= 85)
|
||||
& (r <= 245)
|
||||
& (g >= 45)
|
||||
& (g <= 210)
|
||||
& (b >= 25)
|
||||
& (b <= 190)
|
||||
)
|
||||
|
||||
pink_area, pink_box = self._largest_component_box(pink_body)
|
||||
avatar_band = avatar_like[: max(1, int(height * 0.45)), :]
|
||||
avatar_area, avatar_box = self._largest_component_box(avatar_band)
|
||||
badge_area, badge_box = self._largest_component_box(pale_badge | orange_badge)
|
||||
pink_ratio = float(np.mean(pink_body)) if pink_body.size else 0.0
|
||||
|
||||
pink_large = False
|
||||
if pink_box is not None:
|
||||
_px, _py, pw, ph = pink_box
|
||||
pink_large = pink_area >= 1000 and pw >= 35 and ph >= 40
|
||||
|
||||
avatar_large = False
|
||||
if avatar_box is not None:
|
||||
_ax, ay, aw, ah = avatar_box
|
||||
avatar_large = avatar_area >= 500 and aw >= 22 and ah >= 22 and ay <= height * 0.45
|
||||
|
||||
badge_present = badge_area >= 80
|
||||
redpacket_like = pink_large and avatar_large and badge_present and pink_ratio >= 0.04
|
||||
return bool(redpacket_like), {
|
||||
"pink_ratio": round(pink_ratio, 4),
|
||||
"pink_area": pink_area,
|
||||
"pink_box": pink_box,
|
||||
"avatar_area": avatar_area,
|
||||
"avatar_box": avatar_box,
|
||||
"badge_area": badge_area,
|
||||
"badge_box": badge_box,
|
||||
}
|
||||
except Exception as exc:
|
||||
return False, {"redpacket_widget_error": str(exc)}
|
||||
|
||||
def _has_redpacket_neighbor_widget(
|
||||
self, pic: Image.Image, detected_x: int
|
||||
) -> Tuple[bool, Dict[str, Any]]:
|
||||
"""Detect a redpacket/popularity widget immediately to the right."""
|
||||
try:
|
||||
import numpy as np # type: ignore[import-untyped]
|
||||
|
||||
width, height = pic.size
|
||||
detected_x_scaled = int(detected_x * self.rx / 1080)
|
||||
x1 = max(0, detected_x_scaled + 35)
|
||||
x2 = min(width, detected_x_scaled + 210)
|
||||
y1 = max(0, int(300 * self.ry / 2400) + self.y_pianyi)
|
||||
y2 = min(height, int(520 * self.ry / 2400) + self.y_pianyi)
|
||||
if x1 >= x2 or y1 >= y2:
|
||||
return False, {"reason": "empty_neighbor"}
|
||||
|
||||
arr = np.asarray(pic.crop((x1, y1, x2, y2)).convert("RGB"))
|
||||
r = arr[:, :, 0]
|
||||
g = arr[:, :, 1]
|
||||
b = arr[:, :, 2]
|
||||
pink = (r >= 200) & (g <= 115) & (b >= 85) & (b <= 210)
|
||||
red = (r >= 190) & (g <= 110) & (b <= 130)
|
||||
white = (r >= 220) & (g >= 220) & (b >= 220)
|
||||
dark = (r <= 80) & (g <= 80) & (b <= 95)
|
||||
|
||||
pink_ratio = float(np.mean(pink)) if pink.size else 0.0
|
||||
red_ratio = float(np.mean(red)) if red.size else 0.0
|
||||
white_ratio = float(np.mean(white)) if white.size else 0.0
|
||||
dark_ratio = float(np.mean(dark)) if dark.size else 0.0
|
||||
widget_like = (
|
||||
white_ratio >= 0.35
|
||||
and pink_ratio >= 0.06
|
||||
and red_ratio >= 0.06
|
||||
and dark_ratio <= 0.12
|
||||
)
|
||||
return bool(widget_like), {
|
||||
"pink_ratio": round(pink_ratio, 4),
|
||||
"red_ratio": round(red_ratio, 4),
|
||||
"white_ratio": round(white_ratio, 4),
|
||||
"dark_ratio": round(dark_ratio, 4),
|
||||
"neighbor": (x1, y1, x2, y2),
|
||||
}
|
||||
except Exception as exc:
|
||||
return False, {"redpacket_neighbor_error": str(exc)}
|
||||
|
||||
def confirm_pixel_candidate_shape(self, pic: Image.Image, detected_x: int) -> bool:
|
||||
"""Validate that the pixel hit has the compact shape of a fudai badge."""
|
||||
try:
|
||||
@@ -748,8 +854,14 @@ class FudaiDetector:
|
||||
valid_cols = int(np.sum(cols >= 2))
|
||||
max_col = int(np.max(cols)) if cols.size else 0
|
||||
commercial_overlay, commercial_info = self._is_commercial_coupon_overlay(arr)
|
||||
redpacket_widget, redpacket_info = self._is_commercial_redpacket_widget(arr)
|
||||
redpacket_neighbor, redpacket_neighbor_info = self._has_redpacket_neighbor_widget(
|
||||
pic, detected_x
|
||||
)
|
||||
passed = (
|
||||
not commercial_overlay
|
||||
and not redpacket_widget
|
||||
and not redpacket_neighbor
|
||||
and 20 <= total <= 120
|
||||
and 6 <= valid_cols <= 45
|
||||
and 2 <= max_col <= 10
|
||||
@@ -765,6 +877,10 @@ class FudaiDetector:
|
||||
max_col=max_col,
|
||||
commercial_overlay=commercial_overlay,
|
||||
commercial_info=commercial_info,
|
||||
redpacket_widget=redpacket_widget,
|
||||
redpacket_info=redpacket_info,
|
||||
redpacket_neighbor=redpacket_neighbor,
|
||||
redpacket_neighbor_info=redpacket_neighbor_info,
|
||||
window=(x1, y1, x2, y2),
|
||||
)
|
||||
except Exception:
|
||||
|
||||
@@ -120,6 +120,7 @@ def cleanup_debug_captures(keep_days: int = 7, max_files: int = 2000) -> int:
|
||||
|
||||
# 按日期排序(最旧的在前)
|
||||
dirs_info.sort(key=lambda x: x["date"])
|
||||
today_name = datetime.now().strftime("%Y-%m-%d")
|
||||
|
||||
# 先按天数清理:删除超过保留天数的目录
|
||||
for dir_info in dirs_info[:]:
|
||||
@@ -147,6 +148,14 @@ def cleanup_debug_captures(keep_days: int = 7, max_files: int = 2000) -> int:
|
||||
for dir_info in dirs_info[:]:
|
||||
if deleted_files_count >= need_delete_count:
|
||||
break
|
||||
if dir_info["name"] == today_name:
|
||||
try:
|
||||
_mgr_log(
|
||||
f"[调试图像清理] 保留当天调试图像目录: {dir_info['name']},避免丢失当前测试证据"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
continue
|
||||
|
||||
try:
|
||||
shutil.rmtree(dir_info["path"])
|
||||
|
||||
@@ -130,6 +130,7 @@ def maybe_auto_cleanup(auto_cleanup: bool, mgr_log) -> None:
|
||||
try:
|
||||
debug_base_dir = get_debug_captures_base_dir()
|
||||
cleanup_marker = os.path.join(debug_base_dir, ".cleanup_marker")
|
||||
over_limit_marker = os.path.join(debug_base_dir, ".over_limit_marker")
|
||||
today_str = datetime.now().strftime("%Y-%m-%d")
|
||||
|
||||
need_cleanup = True
|
||||
@@ -167,6 +168,13 @@ def maybe_auto_cleanup(auto_cleanup: bool, mgr_log) -> None:
|
||||
return
|
||||
|
||||
try:
|
||||
if os.path.exists(over_limit_marker):
|
||||
try:
|
||||
with open(over_limit_marker, "r", encoding="utf-8") as f:
|
||||
if f.read().strip() == today_str:
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
config_path = path_config.get_config_path()
|
||||
max_files = 2000
|
||||
if os.path.exists(config_path):
|
||||
@@ -181,7 +189,17 @@ def maybe_auto_cleanup(auto_cleanup: bool, mgr_log) -> None:
|
||||
mgr_log(f"[调试图像清理] 检测到文件数量 {current_count} 超过限制 {max_files},立即清理")
|
||||
except Exception:
|
||||
pass
|
||||
cleanup_debug_captures(keep_days=999, max_files=max_files)
|
||||
deleted = cleanup_debug_captures(keep_days=999, max_files=max_files)
|
||||
if deleted == 0:
|
||||
try:
|
||||
mgr_log("[调试图像清理] 当前仅保留当天测试证据,本日跳过后续超限扫描")
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
with open(over_limit_marker, "w", encoding="utf-8") as f:
|
||||
f.write(today_str)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
|
||||
Reference in new issue
Block a user