diff --git a/douyin/core/fudai_modules/init_helpers.py b/douyin/core/fudai_modules/init_helpers.py index ae70108..9cbb0e4 100644 --- a/douyin/core/fudai_modules/init_helpers.py +++ b/douyin/core/fudai_modules/init_helpers.py @@ -78,7 +78,7 @@ def apply_fudai_defaults(self: Any) -> None: self.fudai_detail_ocr_task_count_enabled = True self.fudai_detail_ocr_button_enabled = True self.fudai_detail_ocr_participants_enabled = False - self.fudai_detail_ocr_live_title_enabled = True + self.fudai_detail_ocr_live_title_enabled = False self.pixel_detect_fudai_icon_enabled = True self.pixel_detect_coupon_popup_enabled = True self.pixel_detect_shopping_redpacket_enabled = False diff --git a/douyin/detection/detection_pkg/finder.py b/douyin/detection/detection_pkg/finder.py index 303a331..34ad0b3 100644 --- a/douyin/detection/detection_pkg/finder.py +++ b/douyin/detection/detection_pkg/finder.py @@ -16,6 +16,14 @@ from douyin.core import path_config from ._common import _ensure_detection_cache from .finder_numpy_scan import scan_with_numpy from .finder_pixel_scan import scan_pixel_by_pixel +from .finder_scan_config import ( + FUDAI_ICON_DEFAULT_OPTIMAL_X, + FUDAI_ICON_SCAN_X_END, + FUDAI_ICON_SCAN_X_START, + FUDAI_ICON_SCAN_Y_BASES, + scale_x, + scale_y, +) from .finder_template_match import match_template @@ -222,12 +230,11 @@ def check_have_fudai_with_ready_screenshot( detected = False detected_x = None # 初始化扫描范围变量(用于日志记录) - scan_x_start = 41 * rx // 1080 - scan_x_end = min(410 * rx // 1080, width) + scan_x_start = scale_x(FUDAI_ICON_SCAN_X_START, rx) + scan_x_end = min(scale_x(FUDAI_ICON_SCAN_X_END, rx), width) scan_y_candidates = [ - 403 * ry // 2400 + y_pianyi_val, - 503 * ry // 2400 + y_pianyi_val, - 354 * ry // 2400 + y_pianyi_val, + scale_y(base_y, ry, y_pianyi_val) + for base_y in FUDAI_ICON_SCAN_Y_BASES ] scan_y_values = [y for y in scan_y_candidates if 0 <= y < height] scan_y = scan_y_values[0] if scan_y_values else 403 * ry // 2400 + y_pianyi_val @@ -241,10 +248,10 @@ def check_have_fudai_with_ready_screenshot( optimal_x_scaled = last_fudai_x_scaled else: # 使用默认最优位置:最热门区域中心(98-240的中心,约169) - optimal_x_scaled = 169 * rx // 1080 + optimal_x_scaled = scale_x(FUDAI_ICON_DEFAULT_OPTIMAL_X, rx) except Exception: # 使用默认最优位置 - optimal_x_scaled = 169 * rx // 1080 + optimal_x_scaled = scale_x(FUDAI_ICON_DEFAULT_OPTIMAL_X, rx) # 确保最优位置在搜索范围内 optimal_x_scaled = max(scan_x_start, min(optimal_x_scaled, scan_x_end - 1)) diff --git a/douyin/detection/detection_pkg/finder_numpy_scan.py b/douyin/detection/detection_pkg/finder_numpy_scan.py index f98bf90..af85e58 100644 --- a/douyin/detection/detection_pkg/finder_numpy_scan.py +++ b/douyin/detection/detection_pkg/finder_numpy_scan.py @@ -12,6 +12,14 @@ from __future__ import annotations import time from typing import Any, Optional, Tuple +from .finder_scan_config import ( + FUDAI_ICON_SCAN_X_END, + FUDAI_ICON_SCAN_X_START, + FUDAI_ICON_SCAN_Y_BASES, + scale_x, + scale_y, +) + def scan_with_numpy( analyser: Any, @@ -45,12 +53,11 @@ def scan_with_numpy( # 计算检测区域,考虑分辨率缩放和偏移。 # 新版福袋 icon 可能更靠左,也可能出现在 403/503 两条高度带。 y_candidates = [ - 403 * ry // 2400 + y_pianyi_val, - 503 * ry // 2400 + y_pianyi_val, - 354 * ry // 2400 + y_pianyi_val, + scale_y(base_y, ry, y_pianyi_val) + for base_y in FUDAI_ICON_SCAN_Y_BASES ] - x1 = max(0, 41 * rx // 1080) - x2 = min(width, 410 * rx // 1080) + x1 = max(0, scale_x(FUDAI_ICON_SCAN_X_START, rx)) + x2 = min(width, scale_x(FUDAI_ICON_SCAN_X_END, rx)) y_values = [y for y in y_candidates if 0 <= y < height] if not y_values: return False, None diff --git a/douyin/detection/detection_pkg/finder_pixel_scan.py b/douyin/detection/detection_pkg/finder_pixel_scan.py index b02fceb..798dd9b 100644 --- a/douyin/detection/detection_pkg/finder_pixel_scan.py +++ b/douyin/detection/detection_pkg/finder_pixel_scan.py @@ -13,6 +13,15 @@ from __future__ import annotations import time from typing import Any, Optional, Tuple +from .finder_scan_config import ( + FUDAI_ICON_DEFAULT_OPTIMAL_X, + FUDAI_ICON_SCAN_X_END, + FUDAI_ICON_SCAN_X_START, + FUDAI_ICON_SCAN_Y_BASES, + scale_x, + scale_y, +) + # 福袋图标主色范围(与 finder_numpy_scan 共享) _R_MIN, _R_MAX = 190, 206 @@ -48,7 +57,7 @@ def _pick_optimal_x(analyser, scan_x_start: int, scan_x_end: int, rx: int) -> in except Exception: pass # 默认最优位置:最热门区域中心(98-240 的中心,约 169) - return 169 * rx // 1080 + return scale_x(FUDAI_ICON_DEFAULT_OPTIMAL_X, rx) def _search_along_y( @@ -111,12 +120,11 @@ def scan_pixel_by_pixel( pix = pic_new.load() pic_width, pic_height = pic_new.size # 计算实际扫描范围,防止越界 - scan_x_start = 41 * rx // 1080 - scan_x_end = min(410 * rx // 1080, pic_width) + scan_x_start = scale_x(FUDAI_ICON_SCAN_X_START, rx) + scan_x_end = min(scale_x(FUDAI_ICON_SCAN_X_END, rx), pic_width) scan_y_candidates = [ - 403 * ry // 2400 + y_pianyi_val, - 503 * ry // 2400 + y_pianyi_val, - 354 * ry // 2400 + y_pianyi_val, + scale_y(base_y, ry, y_pianyi_val) + for base_y in FUDAI_ICON_SCAN_Y_BASES ] optimal_x_scaled = _pick_optimal_x(analyser, scan_x_start, scan_x_end, rx) diff --git a/douyin/detection/detection_pkg/finder_scan_config.py b/douyin/detection/detection_pkg/finder_scan_config.py new file mode 100644 index 0000000..7a2cbb5 --- /dev/null +++ b/douyin/detection/detection_pkg/finder_scan_config.py @@ -0,0 +1,17 @@ +"""Shared scan ranges for finding the small fudai icon.""" +from __future__ import annotations + + +# v2 live-room icon can sit slightly further left than the old hot zone. +FUDAI_ICON_SCAN_X_START = 20 +FUDAI_ICON_SCAN_X_END = 430 +FUDAI_ICON_SCAN_Y_BASES = (403, 503, 354) +FUDAI_ICON_DEFAULT_OPTIMAL_X = 169 + + +def scale_x(value: int, rx: int) -> int: + return int(value * rx // 1080) + + +def scale_y(value: int, ry: int, y_offset: int = 0) -> int: + return int(value * ry // 2400 + y_offset) diff --git a/douyin/fudai/douyin_fudai_core_pkg/ocr_switches.py b/douyin/fudai/douyin_fudai_core_pkg/ocr_switches.py index 8abf942..e0601ad 100644 --- a/douyin/fudai/douyin_fudai_core_pkg/ocr_switches.py +++ b/douyin/fudai/douyin_fudai_core_pkg/ocr_switches.py @@ -12,7 +12,7 @@ OCR_SWITCH_DEFAULTS = { "task_count": True, "button": True, "participants": False, - "live_title": True, + "live_title": False, } OCR_SWITCH_CONFIG_KEYS = { @@ -36,7 +36,7 @@ class FudaiDetailOcrSwitches: task_count: bool = True button: bool = True participants: bool = False - live_title: bool = True + live_title: bool = False def enabled_fields(self) -> set[str]: return { diff --git a/douyin/fudai/douyin_fudai_finder_pkg/detector.py b/douyin/fudai/douyin_fudai_finder_pkg/detector.py index 9317327..542c800 100644 --- a/douyin/fudai/douyin_fudai_finder_pkg/detector.py +++ b/douyin/fudai/douyin_fudai_finder_pkg/detector.py @@ -62,14 +62,14 @@ class FudaiDetector: """初始化搜索区域 实际福袋出现区域按 2.0 直播间样式向左、向下扩展。 - 普通 finder 的调试样本已验证 icon 可能落在 x=41..410、y=403/503 两条带。 + 普通 finder 的调试样本已验证 icon 可能落在 x=20..430、y=403/503/354 三条带。 """ # 旧区域 X=153..561/Y=348..451 保留在扩展区域内;新版图标更靠左且高度可能下移。 self.search_regions = [ { "name": "实际福袋区域", "priority": 1, - "x1": 41 * self.rx // 1080, + "x1": 20 * self.rx // 1080, "x2": 561 * self.rx // 1080, "y_top": 348 * self.ry // 2400 + self.y_pianyi, "y_bottom": 540 * self.ry // 2400 + self.y_pianyi, diff --git a/douyin/utils/douyin_config.py b/douyin/utils/douyin_config.py index 0a27e71..4c4dc5e 100644 --- a/douyin/utils/douyin_config.py +++ b/douyin/utils/douyin_config.py @@ -383,7 +383,7 @@ class ConfigManager: "fudai_detail_ocr_task_count_enabled": True, "fudai_detail_ocr_button_enabled": True, "fudai_detail_ocr_participants_enabled": False, - "fudai_detail_ocr_live_title_enabled": True, + "fudai_detail_ocr_live_title_enabled": False, }.items(): if key in config: setattr(analyser, key, bool(config.get(key, default))) diff --git a/gui/components/config_io.py b/gui/components/config_io.py index 30176f7..1f940bf 100644 --- a/gui/components/config_io.py +++ b/gui/components/config_io.py @@ -159,7 +159,7 @@ def load_config_to_ui( "fudai_detail_ocr_task_count_enabled": True, "fudai_detail_ocr_button_enabled": True, "fudai_detail_ocr_participants_enabled": False, - "fudai_detail_ocr_live_title_enabled": True, + "fudai_detail_ocr_live_title_enabled": False, }.items(): vars_[f"{key}_var"].set(bool(cfg.get(key, default))) try: @@ -210,7 +210,7 @@ def load_config_to_ui( float(cfg.get("stage_diag_max_step_time", 2.0) or 2.0) ) vars_["stage_diag_verbose_var"].set( - bool(cfg.get("logging", {}).get("stage_diag_verbose", True)) + bool(cfg.get("logging", {}).get("stage_diag_verbose", False)) ) vars_["enable_ocr_mode1_var"].set(bool(cfg.get("enable_ocr_mode1", False))) for key, default in { diff --git a/gui/components/config_io_helpers.py b/gui/components/config_io_helpers.py index 1056155..c51422f 100644 --- a/gui/components/config_io_helpers.py +++ b/gui/components/config_io_helpers.py @@ -75,10 +75,10 @@ def apply_logging_from_cfg(vars_: Dict[str, tk.Variable], cfg: dict) -> None: vars_["logging_compress_logs_var"].set(bool(logging_config.get("compress_logs", True))) vars_["logging_max_total_size_gb_var"].set(float(logging_config.get("max_total_size_gb", 10.0) or 10.0)) vars_["logging_compress_after_days_var"].set(int(logging_config.get("compress_after_days", 7) or 7)) - vars_["logging_debug_level_var"].set(str(logging_config.get("debug_detail_level", "normal") or "normal")) - vars_["logging_error_level_var"].set(str(logging_config.get("error_detail_level", "full") or "full")) - vars_["logging_action_format_var"].set(str(logging_config.get("action_log_format", "concise") or "concise")) - vars_["logging_format_mode_var"].set(str(logging_config.get("log_format_mode", "simple") or "simple")) + vars_["logging_debug_level_var"].set("normal") + vars_["logging_error_level_var"].set("full") + vars_["logging_action_format_var"].set("concise") + vars_["logging_format_mode_var"].set("simple") perf_cfg = logging_config.get("performance_tracking", {}) if isinstance(perf_cfg, dict): vars_["logging_performance_enabled_var"].set(bool(perf_cfg.get("enabled", True))) @@ -110,10 +110,10 @@ def write_logging_to_cfg(cfg2: dict, vars_: Dict[str, tk.Variable]) -> None: cfg2["logging"]["compress_logs"] = bool(vars_["logging_compress_logs_var"].get()) cfg2["logging"]["max_total_size_gb"] = float(vars_["logging_max_total_size_gb_var"].get() or 10.0) cfg2["logging"]["compress_after_days"] = int(vars_["logging_compress_after_days_var"].get() or 7) - cfg2["logging"]["debug_detail_level"] = str(vars_["logging_debug_level_var"].get() or "normal") - cfg2["logging"]["error_detail_level"] = str(vars_["logging_error_level_var"].get() or "full") - cfg2["logging"]["action_log_format"] = str(vars_["logging_action_format_var"].get() or "concise") - cfg2["logging"]["log_format_mode"] = str(vars_["logging_format_mode_var"].get() or "simple") + cfg2["logging"]["debug_detail_level"] = "normal" + cfg2["logging"]["error_detail_level"] = "full" + cfg2["logging"]["action_log_format"] = "concise" + cfg2["logging"]["log_format_mode"] = "simple" cfg2["logging"]["stage_diag_verbose"] = bool(vars_["stage_diag_verbose_var"].get()) cfg2["logging"]["monitor_warning_mb"] = float(vars_["logging_monitor_warning_mb_var"].get() or 500.0) cfg2["logging"]["monitor_critical_mb"] = float(vars_["logging_monitor_critical_mb_var"].get() or 2000.0) @@ -124,4 +124,3 @@ def write_logging_to_cfg(cfg2: dict, vars_: Dict[str, tk.Variable]) -> None: cfg2["logging"]["performance_tracking"]["track_function_calls"] = bool(vars_["logging_track_functions_var"].get()) cfg2["log_unified_enabled"] = bool(vars_["log_unified_enabled_var"].get()) cfg2["log_unified_path"] = str(vars_["log_unified_path_var"].get() or "logs/unified.log") - diff --git a/gui/components/config_vars.py b/gui/components/config_vars.py index 4de697c..5e840c9 100644 --- a/gui/components/config_vars.py +++ b/gui/components/config_vars.py @@ -155,7 +155,7 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]: value=bool(cfg.get("fudai_detail_ocr_participants_enabled", False)) ) fudai_detail_ocr_live_title_enabled_var = tk.BooleanVar( - value=bool(cfg.get("fudai_detail_ocr_live_title_enabled", True)) + value=bool(cfg.get("fudai_detail_ocr_live_title_enabled", False)) ) fudai_exit_after_misses_var = tk.IntVar( value=int(cfg.get("fudai_exit_after_misses", 30) or 30) @@ -286,7 +286,7 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]: value=float(cfg.get("stage_diag_max_step_time", 2.0) or 2.0) ) stage_diag_verbose_var = tk.BooleanVar( - value=bool(cfg.get("logging", {}).get("stage_diag_verbose", True)) + value=bool(cfg.get("logging", {}).get("stage_diag_verbose", False)) ) enable_ocr_mode1_var = tk.BooleanVar(value=bool(cfg.get("enable_ocr_mode1", False))) pixel_detect_fudai_icon_enabled_var = tk.BooleanVar(value=bool(cfg.get("pixel_detect_fudai_icon_enabled", True))) diff --git a/gui/components/debug_tab.py b/gui/components/debug_tab.py index 907f4a7..23113c6 100644 --- a/gui/components/debug_tab.py +++ b/gui/components/debug_tab.py @@ -267,7 +267,7 @@ def setup_debug_tab(parent: ttk.Notebook, *, vars_: Dict[str, tk.Variable]) -> t for label, var_name in ( ("按钮文案OCR", "fudai_detail_ocr_button_enabled_var"), ("人数OCR(默认关)", "fudai_detail_ocr_participants_enabled_var"), - ("直播间标题OCR(默认开)", "fudai_detail_ocr_live_title_enabled_var"), + ("直播间标题OCR(默认关)", "fudai_detail_ocr_live_title_enabled_var"), ): ttk.Checkbutton(row4ocr2, text=label, variable=vars_[var_name]).pack( side=LEFT, padx=(0, 10) diff --git a/gui/components/log_color_config.py b/gui/components/log_color_config.py index 925f9fb..0754713 100644 --- a/gui/components/log_color_config.py +++ b/gui/components/log_color_config.py @@ -1,540 +1,151 @@ -""" -日志颜色配置模块 -================ - -为不同的操作类型定义颜色标签,支持明亮和暗色主题。 -""" +"""Log color classification for GUI text widgets.""" +from __future__ import annotations from typing import Dict, Optional -# 操作类型关键词映射(用于识别日志中的操作类型) -OPERATION_KEYWORDS: Dict[str, list] = { - "ocr": [ - "OCR", "ocr", "识别", "读取", "analyse_pic_word", "识别成功", "识别失败", - "直播间标题", "福袋内容", "福袋倒计时", "福袋价值", "参与人数", "开奖结果" - ], - "click": [ - "点击", "click", "点击成功", "点击失败", "参与按钮", "福袋图标", - "返回", "确认", "关闭", "发送", "加入" - ], - "swipe": [ - "滑动", "swipe", "向上滑动", "向下滑动", "向左滑动", "向右滑动", - "回退", "切换直播间", "切换房间" - ], - "screenshot": [ - "截图", "screenshot", "get_screenshot", "保存截图", "截图成功", "截图失败" - ], - "detection": [ - "检测", "detect", "阶段检测", "阶段诊断", "像素检测", "模板匹配", - "检测成功", "检测失败", "匹配成功", "匹配失败", "识别到", "未识别到" - ], - "decision": [ - "决策", "判断", "决定", "选择", "跳过", "参与", "不参与", "筛选", - "价值过低", "人数过少", "人数过多", "倒计时", "内容不符合" - ], - "reservation": [ - "预约", "reservation", "记录预约", "回退到预约", "预约窗口", "预约队列", - "高价值预约", "预约回退", "预约校验" - ], - "fansclub": [ - "粉丝团", "fansclub", "加入粉丝团", "粉丝团失败", "粉丝团成功" - ], - "lottery": [ - "开奖", "lottery", "中奖", "未中奖", "抽奖结果", "等待开奖", "开奖时间" - ], - "stage": [ - "阶段", "stage", "IN_LIVE_ROOM", "FUDai_DETAIL", "RECOMMEND_PAGE", - "LIVE_OR_UNKNOWN", "阶段变化", "阶段流转" - ], - "performance": [ - "耗时", "elapsed_seconds", "性能", "时间", "秒", "毫秒", "效率" - ], - "error": [ - "错误", "ERROR", "失败", "异常", "Exception", "失败", "超时", "timeout" - ], - "success": [ - "成功", "SUCCESS", "完成", "完成", "已", "完成" - ], - "info": [ - "信息", "INFO", "提示", "注意", "开始", "启动", "停止" - ], - "flow": [ - "流程", "flow", "处理", "执行", "运行", "完成" - ], - "operation": [ - "操作", "operation", "动作", "行为" - ] +OPERATION_KEYWORDS: Dict[str, tuple[str, ...]] = { + "lottery": ("开奖", "抽奖结果", "等待开奖", "中奖", "未中奖", "我知道了"), + "reservation": ("预约", "高价值", "预约队列", "预约窗口", "回退校验"), + "detail": ("福袋详情", "福袋内容", "福袋任务", "倒计时OCR", "按钮文案", "参与人数"), + "decision": ("决策", "判断", "选择", "跳过", "筛选", "不参与", "参与过滤"), + "fansclub": ("粉丝团", "加入粉丝团", "fansclub"), + "detection": ("阶段诊断", "阶段检测", "并行检测", "像素检测", "模板匹配", "找福袋图标", "福袋查找", "检测"), + "ocr": ("OCR", "ocr", "analyse_pic_word", "识别"), + "click": ("点击", "click", "参与按钮", "福袋图标", "确认", "关闭", "发送", "加入"), + "swipe": ("滑动", "swipe", "上滑", "下滑", "切换直播间", "切换房间", "回退"), + "screenshot": ("截图", "screenshot", "get_screenshot", "保存截图"), + "performance": ("耗时", "elapsed", "性能", "毫秒", "seconds=", "ms)"), + "stage": ("IN_LIVE_ROOM", "FUDai_DETAIL", "RECOMMEND_PAGE", "LIVE_OR_UNKNOWN", "阶段变化"), + "flow": ("流程", "flow", "处理", "执行", "运行"), + "operation": ("操作", "operation", "动作", "行为"), + "info": ("信息", "INFO", "提示", "开始", "启动", "停止"), } +STATUS_KEYWORDS: tuple[tuple[str, tuple[str, ...]], ...] = ( + ("critical", ("[CRITICAL]", "CRITICAL", "严重")), + ("error", ("[ERROR]", "ERROR", "错误", "异常", "Exception", "失败", "超时", "timeout")), + ("warning", ("[WARNING]", "WARNING", "警告", "WARN")), + ("debug", ("[DEBUG]", "DEBUG", "调试图像", "流程标志", "[FLOW_FLAG]", "OCR调试(")), +) + +SUCCESS_KEYWORDS = ("成功", "完成(成功)", "PASS", "已参与", "检测成功", "识别成功") +SUCCESS_BLOCKERS = ("失败", "错误", "异常", "未找到", "未识别", "未检测") +def _extract_tag_and_content(line: str) -> tuple[str, str]: + import re + + tags = re.findall(r"\[([^\]]+)\]", line or "") + tag = tags[-1].strip() if tags else "" + content_match = re.search(r"\]\s*-\s*(.+)$", line or "") + content = content_match.group(1).strip() if content_match else str(line or "") + return tag, content - - -from typing import Dict, Optional - - -# 操作类型关键词映射(用于识别日志中的操作类型) -OPERATION_KEYWORDS: Dict[str, list] = { - "ocr": [ - "OCR", "ocr", "识别", "读取", "analyse_pic_word", "识别成功", "识别失败", - "直播间标题", "福袋内容", "福袋倒计时", "福袋价值", "参与人数", "开奖结果" - ], - "click": [ - "点击", "click", "点击成功", "点击失败", "参与按钮", "福袋图标", - "返回", "确认", "关闭", "发送", "加入" - ], - "swipe": [ - "滑动", "swipe", "向上滑动", "向下滑动", "向左滑动", "向右滑动", - "回退", "切换直播间", "切换房间" - ], - "screenshot": [ - "截图", "screenshot", "get_screenshot", "保存截图", "截图成功", "截图失败" - ], - "detection": [ - "检测", "detect", "阶段检测", "阶段诊断", "像素检测", "模板匹配", - "检测成功", "检测失败", "匹配成功", "匹配失败", "识别到", "未识别到" - ], - "decision": [ - "决策", "判断", "决定", "选择", "跳过", "参与", "不参与", "筛选", - "价值过低", "人数过少", "人数过多", "倒计时", "内容不符合" - ], - "reservation": [ - "预约", "reservation", "记录预约", "回退到预约", "预约窗口", "预约队列", - "高价值预约", "预约回退", "预约校验" - ], - "fansclub": [ - "粉丝团", "fansclub", "加入粉丝团", "粉丝团失败", "粉丝团成功" - ], - "lottery": [ - "开奖", "lottery", "中奖", "未中奖", "抽奖结果", "等待开奖", "开奖时间" - ], - "stage": [ - "阶段", "stage", "IN_LIVE_ROOM", "FUDai_DETAIL", "RECOMMEND_PAGE", - "LIVE_OR_UNKNOWN", "阶段变化", "阶段流转" - ], - "performance": [ - "耗时", "elapsed_seconds", "性能", "时间", "秒", "毫秒", "效率" - ], - "error": [ - "错误", "ERROR", "失败", "异常", "Exception", "失败", "超时", "timeout" - ], - "success": [ - "成功", "SUCCESS", "完成", "完成", "已", "完成" - ], - "info": [ - "信息", "INFO", "提示", "注意", "开始", "启动", "停止" - ], - "flow": [ - "流程", "flow", "处理", "执行", "运行", "完成" - ], - "operation": [ - "操作", "operation", "动作", "行为" - ] -} +def _contains_any(text: str, keywords: tuple[str, ...]) -> bool: + text_lower = text.lower() + return any(keyword.lower() in text_lower for keyword in keywords) def get_operation_type(line: str) -> Optional[str]: - """ - 根据日志行内容识别操作类型 + """Return the display color category for one log line.""" + text = str(line or "") + tag, content = _extract_tag_and_content(text) + combined = f"{tag} {content} {text}" - 日志格式通常是: [时间] [GUI] - 操作类型 内容 - 优先识别日志内容中的操作类型关键词(如 "流程"、"滑动"、"阶段诊断"、"预约" 等) - - Args: - line: 日志行内容 - - Returns: - 操作类型名称,如果无法识别则返回None - """ - line_lower = line.lower() - - # 优先级1: 识别日志内容开头的操作类型(最精确) - # 日志格式: [时间] [GUI] - 操作类型 内容 - # 例如: [GUI] - 流程 find_and_open_fudai_detail完成 - # [GUI] - 滑动上滑切换直播间 - # [GUI] - 阶段诊断开始阶段诊断 - # [GUI] - 预约[预约]记录直播间标题 - - import re - # 提取日志内容部分(去掉时间戳和标签) - # 匹配格式: [时间] [标签] - 内容 - content_match = re.search(r'\]\s*-\s*(.+)$', line) - if content_match: - content = content_match.group(1).strip() - content_lower = content.lower() - - # 操作类型关键词映射(按优先级排序,更具体的在前) - operation_type_map = [ - # 检测相关(最具体) - ("阶段诊断", "detection"), - ("阶段检测", "detection"), - ("并行检测", "detection"), - ("像素检测", "detection"), - ("模板匹配", "detection"), - ("检测", "detection"), - # 滑动相关 - ("滑动", "swipe"), - ("上滑", "swipe"), - ("下滑", "swipe"), - ("切换直播间", "swipe"), - # 预约相关 - ("预约", "reservation"), - # OCR相关 - ("OCR", "ocr"), - ("ocr识别", "ocr"), - ("识别", "ocr"), - # 点击相关 - ("点击", "click"), - # 截图相关 - ("截图", "screenshot"), - # 流程相关 - ("流程", "flow"), - # 决策相关 - ("决策", "decision"), - ("行为识别", "decision"), - # 开奖相关 - ("开奖", "lottery"), - ("抽奖结果", "lottery"), - # 粉丝团相关 - ("粉丝团", "fansclub"), - # 操作相关(通用,放后面) - ("操作", "operation"), - # 自救相关 - ("自救", "info"), - # 错误相关 - ("错误", "error"), - ("异常", "error"), - # 成功相关 - ("成功", "success"), - # 信息相关(最通用,放最后) - ("信息", "info"), - ] - - # 检查内容开头是否匹配操作类型 - for keyword, op_type in operation_type_map: - # 检查是否在内容开头(更精确) - if content_lower.startswith(keyword.lower()): - return op_type - # 或者检查是否紧跟在 " - " 后面 - if f" - {keyword.lower()}" in line_lower or f"- {keyword.lower()}" in line_lower: - return op_type - - # 优先级2: 使用日志标签识别(如果内容中没有匹配到) - tag_match = re.search(r'\[([^\]]+)\]', line) - if tag_match: - tag = tag_match.group(1).lower() - - # 标签到操作类型的映射(精确匹配) - tag_to_op_type = { - "阶段诊断": "detection", - "阶段检测": "detection", - "截图": "screenshot", - "ocr": "ocr", - "ocr识别": "ocr", - "点击": "click", - "滑动": "swipe", - "预约": "reservation", - "找福袋图标": "detection", - "福袋查找": "detection", - "自救": "info", - "流程": "flow", - "行为识别": "decision", - "决策": "decision", - "错误": "error", - "异常": "error", - "成功": "success", - "信息": "info", - "提示": "info", - } - - # 精确匹配标签 - if tag in tag_to_op_type: - return tag_to_op_type[tag] - - # 部分匹配标签(用于更灵活的匹配) - for tag_key, op_type in tag_to_op_type.items(): - if tag_key in tag or tag in tag_key: - return op_type - - # 优先级2: 使用关键词匹配(更具体的短语优先) - # 定义更具体的关键词短语(按优先级排序) - specific_patterns = [ - # 检测相关(更具体的短语优先) - ("阶段诊断", "detection"), - ("阶段检测", "detection"), - ("像素检测", "detection"), - ("模板匹配", "detection"), - ("并行检测", "detection"), - # OCR相关 - ("OCR识别", "ocr"), - ("OCR模式", "ocr"), - ("识别成功", "ocr"), - ("识别失败", "ocr"), - # 点击相关 - ("点击成功", "click"), - ("点击失败", "click"), - ("参与按钮", "click"), - # 滑动相关 - ("向上滑动", "swipe"), - ("向下滑动", "swipe"), - ("切换直播间", "swipe"), - # 预约相关 - ("记录预约", "reservation"), - ("预约窗口", "reservation"), - ("预约队列", "reservation"), - # 开奖相关 - ("抽奖结果", "lottery"), - ("等待开奖", "lottery"), - ("开奖时间", "lottery"), - # 粉丝团相关 - ("加入粉丝团", "fansclub"), - ("粉丝团失败", "fansclub"), - ("粉丝团成功", "fansclub"), - ] - - # 先检查更具体的短语 - for pattern, op_type in specific_patterns: - if pattern.lower() in line_lower: + for op_type, keywords in STATUS_KEYWORDS: + if _contains_any(combined, keywords): return op_type - # 优先级3: 使用通用关键词匹配(按操作类型优先级) - # 调整顺序,让更具体的操作类型优先 - priority_order = [ - "lottery", # 开奖相关(更具体) - "fansclub", # 粉丝团(更具体) - "reservation", # 预约(更具体) - "decision", # 决策(更具体) - "detection", # 检测(较具体) - "ocr", # OCR(较具体) - "click", # 点击(较具体) - "swipe", # 滑动(较具体) - "flow", # 流程(较具体) - "operation", # 操作(较具体) - "screenshot", # 截图(较通用,放后面) - "stage", # 阶段(较通用) - "performance", # 性能(较通用) - "error", # 错误(较通用) - "success", # 成功(较通用) - "info", # 信息(最通用,放最后) - ] + if _contains_any(combined, SUCCESS_KEYWORDS) and not _contains_any( + combined, SUCCESS_BLOCKERS + ): + return "success" - # 按优先级顺序检查 - for op_type in priority_order: - if op_type in OPERATION_KEYWORDS: - for keyword in OPERATION_KEYWORDS[op_type]: - # 避免过于宽泛的关键词误匹配 - if keyword.lower() in ["截图", "检测", "识别", "成功", "完成", "失败", "错误"]: - # 这些关键词太宽泛,只在特定上下文中使用 - # 检查是否在更具体的上下文中 - if keyword.lower() == "截图" and ("截图成功" in line_lower or "截图失败" in line_lower or "[截图]" in line): - return op_type - elif keyword.lower() == "检测" and ("阶段检测" in line_lower or "像素检测" in line_lower or "并行检测" in line_lower): - return op_type - elif keyword.lower() == "识别" and ("OCR识别" in line_lower or "识别成功" in line_lower or "识别失败" in line_lower): - return op_type - # 其他宽泛关键词跳过,避免误匹配 - continue - - if keyword.lower() in line_lower: - return op_type + for op_type, keywords in OPERATION_KEYWORDS.items(): + if _contains_any(combined, keywords): + return op_type return None def get_color_config(theme: str = "litera") -> Dict[str, Dict[str, str]]: - """ - 获取颜色配置(根据主题) - - Args: - theme: 主题名称("litera", "darkly" 等) - - Returns: - 颜色配置字典,包含每种操作类型的颜色设置 - """ + """Return high-contrast colors for the current GUI theme.""" light_themes = {"litera", "flatly", "journal", "minty", "cosmo"} is_light = theme.lower() in light_themes if is_light: - # 明亮主题颜色配置(深色文字,与白色背景对比,高区分度) return { - "ocr": { - "foreground": "#0052CC", # 鲜明蓝色 - OCR识别 - "background": "#D6E8FF", # 浅蓝色背景 - }, - "click": { - "foreground": "#D32F2F", # 鲜明红色 - 点击操作 - "background": "#FFE0E0", # 浅红色背景 - }, - "swipe": { - "foreground": "#2E7D32", # 鲜明绿色 - 滑动操作 - "background": "#E0F2E8", # 浅绿色背景 - }, - "screenshot": { - "foreground": "#7B1FA2", # 鲜明紫色 - 截图操作 - "background": "#F3E5F5", # 浅紫色背景 - }, - "detection": { - "foreground": "#F57C00", # 鲜明橙色 - 检测操作 - "background": "#FFF3E0", # 浅橙色背景 - }, - "decision": { - "foreground": "#C2185B", # 鲜明品红色 - 决策操作 - "background": "#FCE4EC", # 浅品红色背景 - }, - "reservation": { - "foreground": "#00897B", # 鲜明青色 - 预约操作(区别于OCR蓝色) - "background": "#E0F2F1", # 浅青色背景 - }, - "fansclub": { - "foreground": "#8E24AA", # 鲜明紫红色 - 粉丝团操作(区别于截图紫色) - "background": "#F3E5F5", # 浅紫红色背景 - }, - "lottery": { - "foreground": "#E64A19", # 鲜明橙红色 - 开奖相关(区别于点击红色) - "background": "#FFEBEE", # 浅橙红色背景 - }, - "stage": { - "foreground": "#616161", # 深灰色 - 阶段信息 - "background": "#F5F5F5", # 浅灰色背景 - }, - "performance": { - "foreground": "#00796B", # 鲜明青绿色 - 性能信息 - "background": "#E0F2F1", # 浅青绿色背景 - }, - "error": { - "foreground": "#C62828", # 鲜明深红色 - 错误 - "background": "#FFCDD2", # 浅红色背景 - }, - "success": { - "foreground": "#2E7D32", # 鲜明深绿色 - 成功 - "background": "#C8E6C9", # 浅绿色背景 - }, - "info": { - "foreground": "#0277BD", # 鲜明天蓝色 - 信息(区别于OCR深蓝色) - "background": "#BBDEFB", # 浅天蓝色背景 - }, - "flow": { - "foreground": "#5D4037", # 深棕色 - 流程操作 - "background": "#EFEBE9", # 浅棕色背景 - }, - "operation": { - "foreground": "#455A64", # 深蓝灰色 - 操作动作 - "background": "#ECEFF1", # 浅蓝灰色背景 - }, - } - else: - # 暗色主题颜色配置(亮色文字,与深色背景对比,高区分度) - return { - "ocr": { - "foreground": "#42A5F5", # 鲜明亮蓝色 - OCR识别 - "background": "#0D47A1", # 深蓝色背景 - }, - "click": { - "foreground": "#EF5350", # 鲜明亮红色 - 点击操作 - "background": "#B71C1C", # 深红色背景 - }, - "swipe": { - "foreground": "#66BB6A", # 鲜明亮绿色 - 滑动操作 - "background": "#1B5E20", # 深绿色背景 - }, - "screenshot": { - "foreground": "#AB47BC", # 鲜明亮紫色 - 截图操作 - "background": "#4A148C", # 深紫色背景 - }, - "detection": { - "foreground": "#FFA726", # 鲜明亮橙色 - 检测操作 - "background": "#E65100", # 深橙色背景 - }, - "decision": { - "foreground": "#EC407A", # 鲜明亮品红色 - 决策操作 - "background": "#880E4F", # 深品红色背景 - }, - "reservation": { - "foreground": "#26A69A", # 鲜明亮青色 - 预约操作(区别于OCR蓝色) - "background": "#004D40", # 深青色背景 - }, - "fansclub": { - "foreground": "#BA68C8", # 鲜明亮紫红色 - 粉丝团操作(区别于截图紫色) - "background": "#4A148C", # 深紫红色背景 - }, - "lottery": { - "foreground": "#FF7043", # 鲜明亮橙红色 - 开奖相关(区别于点击红色) - "background": "#BF360C", # 深橙红色背景 - }, - "stage": { - "foreground": "#90A4AE", # 亮灰色 - 阶段信息 - "background": "#263238", # 深灰色背景 - }, - "performance": { - "foreground": "#26A69A", # 鲜明亮青绿色 - 性能信息 - "background": "#004D40", # 深青绿色背景 - }, - "error": { - "foreground": "#F44336", # 鲜明亮红色 - 错误 - "background": "#B71C1C", # 深红色背景 - }, - "success": { - "foreground": "#66BB6A", # 鲜明亮绿色 - 成功 - "background": "#1B5E20", # 深绿色背景 - }, - "info": { - "foreground": "#29B6F6", # 鲜明亮天蓝色 - 信息(区别于OCR深蓝色) - "background": "#01579B", # 深天蓝色背景 - }, - "flow": { - "foreground": "#A1887F", # 亮棕色 - 流程操作 - "background": "#3E2723", # 深棕色背景 - }, - "operation": { - "foreground": "#78909C", # 亮蓝灰色 - 操作动作 - "background": "#263238", # 深蓝灰色背景 - }, + "critical": {"foreground": "#FFFFFF", "background": "#7F0000"}, + "error": {"foreground": "#B42318", "background": "#FFE4E2"}, + "warning": {"foreground": "#B54708", "background": "#FEF0C7"}, + "debug": {"foreground": "#667085", "background": "#F2F4F7"}, + "success": {"foreground": "#067647", "background": "#D1FADF"}, + "detail": {"foreground": "#175CD3", "background": "#D1E9FF"}, + "ocr": {"foreground": "#004EEB", "background": "#E0EAFF"}, + "click": {"foreground": "#C01048", "background": "#FFE4E8"}, + "swipe": {"foreground": "#027A48", "background": "#DCFAE6"}, + "screenshot": {"foreground": "#6941C6", "background": "#F4EBFF"}, + "detection": {"foreground": "#C4320A", "background": "#FFEDDB"}, + "decision": {"foreground": "#9E165F", "background": "#FCE7F6"}, + "reservation": {"foreground": "#0E7090", "background": "#CFF9FE"}, + "fansclub": {"foreground": "#7A2E0E", "background": "#FDEAD7"}, + "lottery": {"foreground": "#B93815", "background": "#FFEAD5"}, + "stage": {"foreground": "#344054", "background": "#EAECF0"}, + "performance": {"foreground": "#047857", "background": "#CCFBF1"}, + "info": {"foreground": "#026AA2", "background": "#E0F2FE"}, + "flow": {"foreground": "#4E5BA6", "background": "#E0EAFF"}, + "operation": {"foreground": "#475467", "background": "#F2F4F7"}, } + return { + "critical": {"foreground": "#FFFFFF", "background": "#991B1B"}, + "error": {"foreground": "#FCA5A5", "background": "#7F1D1D"}, + "warning": {"foreground": "#FCD34D", "background": "#78350F"}, + "debug": {"foreground": "#CBD5E1", "background": "#334155"}, + "success": {"foreground": "#86EFAC", "background": "#14532D"}, + "detail": {"foreground": "#93C5FD", "background": "#1E3A8A"}, + "ocr": {"foreground": "#BFDBFE", "background": "#1D4ED8"}, + "click": {"foreground": "#FDA4AF", "background": "#881337"}, + "swipe": {"foreground": "#BBF7D0", "background": "#166534"}, + "screenshot": {"foreground": "#DDD6FE", "background": "#4C1D95"}, + "detection": {"foreground": "#FDBA74", "background": "#7C2D12"}, + "decision": {"foreground": "#F0ABFC", "background": "#701A75"}, + "reservation": {"foreground": "#67E8F9", "background": "#164E63"}, + "fansclub": {"foreground": "#FED7AA", "background": "#7C2D12"}, + "lottery": {"foreground": "#FDBA74", "background": "#9A3412"}, + "stage": {"foreground": "#CBD5E1", "background": "#1F2937"}, + "performance": {"foreground": "#5EEAD4", "background": "#134E4A"}, + "info": {"foreground": "#7DD3FC", "background": "#0C4A6E"}, + "flow": {"foreground": "#C7D2FE", "background": "#3730A3"}, + "operation": {"foreground": "#CBD5E1", "background": "#334155"}, + } + def apply_operation_color( text_widget, start_pos: str, end_pos: str, line: str, - theme: str = "litera" + theme: str = "litera", ) -> None: - """ - 为日志行应用操作类型颜色 - - Args: - text_widget: tkinter Text 组件 - start_pos: 起始位置 - end_pos: 结束位置 - line: 日志行内容 - theme: 主题名称 - """ + """Apply the color tag for one log line.""" try: - # 识别操作类型 op_type = get_operation_type(line) if not op_type: return - # 获取颜色配置 - color_config = get_color_config(theme) - if op_type not in color_config: + colors = get_color_config(theme).get(op_type) + if not colors: return - colors = color_config[op_type] tag_name = f"op_{op_type}" - - # 配置标签(总是重新配置,确保主题改变时颜色也会更新) text_widget.tag_configure( tag_name, foreground=colors["foreground"], background=colors["background"], ) - - # 应用标签 text_widget.tag_add(tag_name, start_pos, end_pos) except Exception: - # 忽略颜色应用失败,不影响日志显示 pass diff --git a/gui/components/logging_config_io.py b/gui/components/logging_config_io.py index 5871c03..a19ff18 100644 --- a/gui/components/logging_config_io.py +++ b/gui/components/logging_config_io.py @@ -32,14 +32,14 @@ def save_logging_config( if "logging" not in cfg: cfg["logging"] = {} - cfg["logging"]["log_format_mode"] = vars_["logging_format_mode_var"].get() + cfg["logging"]["log_format_mode"] = "simple" cfg["logging"]["beautify_output"] = bool(vars_["logging_beautify_var"].get()) cfg["logging"]["color_output"] = bool(vars_["logging_color_var"].get()) cfg["logging"]["show_timestamps"] = bool(vars_["logging_show_timestamps_var"].get()) cfg["logging"]["use_dated_logs"] = bool(vars_["logging_use_dated_logs_var"].get()) - cfg["logging"]["debug_detail_level"] = vars_["logging_debug_level_var"].get() - cfg["logging"]["error_detail_level"] = vars_["logging_error_level_var"].get() - cfg["logging"]["action_log_format"] = vars_["logging_action_format_var"].get() + cfg["logging"]["debug_detail_level"] = "normal" + cfg["logging"]["error_detail_level"] = "full" + cfg["logging"]["action_log_format"] = "concise" cfg["logging"]["enable_monitor"] = bool(vars_["logging_enable_monitor_var"].get()) cfg["logging"]["keep_days"] = int(vars_["logging_keep_days_var"].get()) cfg["logging"]["compress_logs"] = bool(vars_["logging_compress_logs_var"].get()) diff --git a/gui/components/logging_tab.py b/gui/components/logging_tab.py index bd8d09a..b3b5508 100644 --- a/gui/components/logging_tab.py +++ b/gui/components/logging_tab.py @@ -32,20 +32,13 @@ def setup_logging_tab( log_format_box = ttk.LabelFrame(logging_container, text="日志格式") log_format_box.pack(fill=X, pady=(0, 10)) - # 日志格式模式 + # Simple 是唯一日常显示模式;详细调试信息留在内部 debug 日志。 log_format_r1 = ttk.Frame(log_format_box) log_format_r1.pack(fill=X, padx=10, pady=(10, 6)) - ttk.Label(log_format_r1, text="日志格式模式:").pack(side=LEFT) - ttk.Combobox( + ttk.Label( log_format_r1, - values=["simple", "detailed"], - textvariable=vars_["logging_format_mode_var"], - state="readonly", - width=12, - ).pack(side=LEFT, padx=(0, 20)) - ttk.Label(log_format_r1, text="(simple=简洁模式,detailed=详细模式用于debug)").pack( - side=LEFT, padx=(6, 0) - ) + text="日志显示模式:simple(统一简洁模式,调试细节自动收进 debug/detail)", + ).pack(side=LEFT) # 日志美化选项 log_format_r2 = ttk.Frame(log_format_box) @@ -66,44 +59,16 @@ def setup_logging_tab( variable=vars_["logging_show_timestamps_var"], ).pack(side=LEFT, padx=(20, 0)) - # 日志详细程度设置 - log_detail_box = ttk.LabelFrame(logging_container, text="日志详细程度") + log_detail_box = ttk.LabelFrame(logging_container, text="日志输出") log_detail_box.pack(fill=X, pady=(0, 10)) - log_detail_r1 = ttk.Frame(log_detail_box) - log_detail_r1.pack(fill=X, padx=10, pady=(10, 6)) - ttk.Label(log_detail_r1, text="调试日志详细程度:").pack(side=LEFT) - ttk.Combobox( - log_detail_r1, - values=["normal", "detailed", "minimal"], - textvariable=vars_["logging_debug_level_var"], - state="readonly", - width=12, - ).pack(side=LEFT, padx=(0, 20)) - ttk.Label(log_detail_r1, text="错误日志详细程度:").pack(side=LEFT) - ttk.Combobox( - log_detail_r1, - values=["full", "basic", "minimal"], - textvariable=vars_["logging_error_level_var"], - state="readonly", - width=12, - ).pack(side=LEFT) - log_detail_r2 = ttk.Frame(log_detail_box) - log_detail_r2.pack(fill=X, padx=10, pady=(0, 10)) - ttk.Label(log_detail_r2, text="行为日志格式:").pack(side=LEFT) - ttk.Combobox( - log_detail_r2, - values=["concise", "detailed", "minimal"], - textvariable=vars_["logging_action_format_var"], - state="readonly", - width=12, - ).pack(side=LEFT, padx=(0, 20)) + log_detail_r2.pack(fill=X, padx=10, pady=(10, 10)) ttk.Checkbutton( log_detail_r2, text="启用日志监控(超限告警/触发清理)", variable=vars_["logging_enable_monitor_var"], - ).pack(side=LEFT, padx=(20, 0)) + ).pack(side=LEFT) log_detail_r3 = ttk.Frame(log_detail_box) log_detail_r3.pack(fill=X, padx=10, pady=(0, 10)) diff --git a/gui/web_gui_pkg/routes.py b/gui/web_gui_pkg/routes.py index 81af4e2..d3f05b9 100644 --- a/gui/web_gui_pkg/routes.py +++ b/gui/web_gui_pkg/routes.py @@ -447,6 +447,12 @@ def handle_post(handler, u, runner, csrf_token: str) -> None: "reenter_live_entry_mode", "fudai_detail_ui_mode", } + fixed_simple_logging = { + "logging.debug_detail_level": "normal", + "logging.error_detail_level": "full", + "logging.action_log_format": "concise", + "logging.log_format_mode": "simple", + } def set_nested_value(obj, key, value): if "." in key: @@ -463,6 +469,8 @@ def handle_post(handler, u, runner, csrf_token: str) -> None: for k, v in (update or {}).items(): if k in deny_keys: continue + if k in fixed_simple_logging: + continue if k in int_keys: try: set_nested_value(cfg, k, int(v)) @@ -496,6 +504,8 @@ def handle_post(handler, u, runner, csrf_token: str) -> None: set_nested_value(cfg, k, val) else: set_nested_value(cfg, k, v) + for fixed_key, fixed_value in fixed_simple_logging.items(): + set_nested_value(cfg, fixed_key, fixed_value) write_config(cfg) return handler._send_json({"ok": True}) diff --git a/tests/test_finder_numpy_scan.py b/tests/test_finder_numpy_scan.py index 1ce8cde..c3e6204 100644 --- a/tests/test_finder_numpy_scan.py +++ b/tests/test_finder_numpy_scan.py @@ -86,6 +86,20 @@ class TestScanWithNumpy: # x 应落在 200..250 范围内(1080 基准坐标) assert 200 <= x <= 250 + def test_left_expanded_icon_range_detects_x_25(self): + """新版福袋 icon 偏左时,x=25 也应纳入扫描范围。""" + from douyin.detection.detection_pkg.finder_numpy_scan import scan_with_numpy + + a = _mk_analyser() + pic = _make_image_with_target_band( + TARGET_RGB, x_start=25, x_end=32, y_target=353 + ) + detected, x = scan_with_numpy( + a, pic, rx=1080, ry=2400, y_pianyi_val=0, optimal_x_scaled=169 + ) + assert detected is True + assert 20 <= x <= 40 + def test_writes_back_last_fudai_x_on_hit(self): from douyin.detection.detection_pkg.finder_numpy_scan import scan_with_numpy diff --git a/tests/test_fudai_detail_ui_v2.py b/tests/test_fudai_detail_ui_v2.py index 1edd854..4b410ca 100644 --- a/tests/test_fudai_detail_ui_v2.py +++ b/tests/test_fudai_detail_ui_v2.py @@ -57,7 +57,7 @@ def test_ocr_switch_defaults_and_legacy_disable_compat(): task_count=True, button=True, participants=False, - live_title=True, + live_title=False, ) legacy = resolve_fudai_detail_ocr_switches( @@ -81,18 +81,21 @@ def test_ocr_switch_defaults_and_legacy_disable_compat(): assert explicit.participants is True -def test_static_config_defaults_include_v2_ocr_keys(): - cfg = json.loads(open("config/config.json", encoding="utf-8").read()) +def test_code_defaults_include_v2_ocr_keys(): + from douyin.fudai.douyin_fudai_core_pkg.ocr_switches import ( + resolve_fudai_detail_ocr_switches, + ) - assert cfg["fudai_detail_ui_mode"] == "auto" - assert cfg["fudai_detail_ocr_content_enabled"] is True - assert cfg["fudai_detail_ocr_value_enabled"] is True - assert cfg["fudai_detail_ocr_countdown_enabled"] is True - assert cfg["fudai_detail_ocr_task_enabled"] is True - assert cfg["fudai_detail_ocr_task_count_enabled"] is True - assert cfg["fudai_detail_ocr_button_enabled"] is True - assert cfg["fudai_detail_ocr_participants_enabled"] is False - assert cfg["fudai_detail_ocr_live_title_enabled"] is True + defaults = resolve_fudai_detail_ocr_switches({}) + + assert defaults.content is True + assert defaults.value is True + assert defaults.countdown is True + assert defaults.task is True + assert defaults.task_count is True + assert defaults.button is True + assert defaults.participants is False + assert defaults.live_title is False def test_config_manager_loads_fudai_detail_ui_and_ocr_switches(tmp_path): diff --git a/tests/test_gui_components.py b/tests/test_gui_components.py index be24422..a2546c1 100644 --- a/tests/test_gui_components.py +++ b/tests/test_gui_components.py @@ -17,7 +17,7 @@ class TestGetOperationType: from gui.components.log_color_config import get_operation_type result = get_operation_type("[GUI] - OCR识别成功") - assert result == "ocr" or result is not None + assert result == "success" def test_click_keywords(self): from gui.components.log_color_config import get_operation_type @@ -41,7 +41,31 @@ class TestGetOperationType: from gui.components.log_color_config import get_operation_type result = get_operation_type("[ERROR] 操作失败") - assert result == "error" or result is not None + assert result == "error" + + def test_error_status_has_priority_over_business_type(self): + from gui.components.log_color_config import get_operation_type + + result = get_operation_type("[INFO] [福袋详情] OCR识别失败") + assert result == "error" + + def test_warning_status_has_priority(self): + from gui.components.log_color_config import get_operation_type + + result = get_operation_type("[WARNING] [验证] 倒计时OCR结果完全为空") + assert result == "warning" + + def test_fudai_detail_has_own_color_category(self): + from gui.components.log_color_config import get_operation_type + + result = get_operation_type("[INFO] [福袋详情] read_fudai_detail_once完成") + assert result == "detail" + + def test_debug_noise_is_gray_category(self): + from gui.components.log_color_config import get_operation_type + + result = get_operation_type("[INFO] [调试图像] 福袋详情综合标注图已保存") + assert result == "debug" def test_unknown_line_returns_none_or_default(self): from gui.components.log_color_config import get_operation_type @@ -79,6 +103,9 @@ class TestGetColorConfig: config = get_color_config() # 应该包含一些操作类型的颜色配置 assert any(key in config for key in ["ocr", "click", "error", "info"]) + assert "detail" in config + assert "warning" in config + assert "debug" in config class TestApplyOperationColor: diff --git a/tools/dev/web_gui_config_manifest.json b/tools/dev/web_gui_config_manifest.json index 6b6f4ee..f69da3f 100644 --- a/tools/dev/web_gui_config_manifest.json +++ b/tools/dev/web_gui_config_manifest.json @@ -59,16 +59,12 @@ "high_value_room_revisit_only_current_run", "infinite_loop_enabled", "live_room_match_threshold", - "logging.action_log_format", "logging.beautify_output", "logging.color_output", "logging.compress_after_days", "logging.compress_logs", - "logging.debug_detail_level", "logging.enable_monitor", - "logging.error_detail_level", "logging.keep_days", - "logging.log_format_mode", "logging.max_total_size_gb", "logging.monitor_critical_mb", "logging.monitor_warning_mb", @@ -155,6 +151,10 @@ "gui.realtime_status.tail_items", "log_unified_enabled", "log_unified_path", + "logging.action_log_format", + "logging.debug_detail_level", + "logging.error_detail_level", + "logging.log_format_mode", "logging.use_dated_logs" ], "gui_saved_keys": [ @@ -522,16 +522,12 @@ "live_room_match_threshold", "log_unified_enabled", "log_unified_path", - "logging.action_log_format", "logging.beautify_output", "logging.color_output", "logging.compress_after_days", "logging.compress_logs", - "logging.debug_detail_level", "logging.enable_monitor", - "logging.error_detail_level", "logging.keep_days", - "logging.log_format_mode", "logging.max_total_size_gb", "logging.monitor_critical_mb", "logging.monitor_warning_mb", diff --git a/tools/diagnostics/check_web_gui_config_sync.py b/tools/diagnostics/check_web_gui_config_sync.py index 1dfe456..fb08784 100644 --- a/tools/diagnostics/check_web_gui_config_sync.py +++ b/tools/diagnostics/check_web_gui_config_sync.py @@ -49,6 +49,11 @@ GUI_RUNTIME_ONLY_KEYS = { # These are right-side runtime refresh preferences in gui_app.py. "gui.realtime_status.refresh_interval_ms", "gui.realtime_status.tail_items", + # Internal compatibility fields: UI always uses simple mode now. + "logging.debug_detail_level", + "logging.error_detail_level", + "logging.action_log_format", + "logging.log_format_mode", } FUDAI_DETAIL_OCR_KEYS = { diff --git a/webui/js/config_panel_templates.js b/webui/js/config_panel_templates.js index 6921eb5..5d68e05 100644 --- a/webui/js/config_panel_templates.js +++ b/webui/js/config_panel_templates.js @@ -100,7 +100,7 @@
- +
@@ -262,29 +262,21 @@
- +
固定为 normal;simple 会自动隐藏调试噪声
- +
固定为 full;错误和异常仍完整保留
- +
固定为 concise,日常日志统一走 simple 简洁模式
- +
固定为 simple,调试细节自动收进 debug/detail
diff --git a/webui/js/constants.js b/webui/js/constants.js index c0427b4..4709028 100644 --- a/webui/js/constants.js +++ b/webui/js/constants.js @@ -141,7 +141,7 @@ const DEFAULTS = { fudai_detail_ocr_task_count_enabled: true, fudai_detail_ocr_button_enabled: true, fudai_detail_ocr_participants_enabled: false, - fudai_detail_ocr_live_title_enabled: true, + fudai_detail_ocr_live_title_enabled: false, pixel_detect_fudai_icon_enabled: true, pixel_detect_coupon_popup_enabled: true, pixel_detect_shopping_redpacket_enabled: false, @@ -209,7 +209,7 @@ const DEFAULTS = { "logging.log_format_mode": "simple", "logging.monitor_warning_mb": 500, "logging.monitor_critical_mb": 2000, - "logging.stage_diag_verbose": true, + "logging.stage_diag_verbose": false, "logging.performance_tracking.enabled": true, "logging.performance_tracking.track_function_calls": true, "gui.theme": "litera",