chore: Clean up and refactor codebase for improved maintainability
- Removed obsolete command-line test parameters from `run_cli.py` to streamline functionality. - Introduced a new `ocr_preprocess.py` module for unified OCR image preprocessing, enhancing recognition stability. - Updated various components to utilize the new preprocessing function, improving code organization and readability. - Adjusted configuration values in `config.json` for better performance and consistency. - Added comprehensive technical documentation for the Douyin project, detailing code modification standards and operational guidelines. - Cleaned up excessive blank lines across multiple files to enhance overall readability.
This commit is contained in:
1 parent
efe6e2252f
commit
223c127e11
70 files changed
+17121
-1752
No files matched your search
@@ -17,3 +17,25 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -57,3 +57,25 @@ def save_ui_to_config(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -67,3 +67,25 @@ def create_device_selector(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,3 +53,25 @@ def create_image_viewer(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,540 @@
|
||||
"""
|
||||
日志颜色配置模块
|
||||
================
|
||||
|
||||
为不同的操作类型定义颜色标签,支持明亮和暗色主题。
|
||||
"""
|
||||
|
||||
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", "动作", "行为"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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 get_operation_type(line: str) -> Optional[str]:
|
||||
"""
|
||||
根据日志行内容识别操作类型
|
||||
|
||||
日志格式通常是: [时间] [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:
|
||||
return op_type
|
||||
|
||||
# 优先级3: 使用通用关键词匹配(按操作类型优先级)
|
||||
# 调整顺序,让更具体的操作类型优先
|
||||
priority_order = [
|
||||
"lottery", # 开奖相关(更具体)
|
||||
"fansclub", # 粉丝团(更具体)
|
||||
"reservation", # 预约(更具体)
|
||||
"decision", # 决策(更具体)
|
||||
"detection", # 检测(较具体)
|
||||
"ocr", # OCR(较具体)
|
||||
"click", # 点击(较具体)
|
||||
"swipe", # 滑动(较具体)
|
||||
"flow", # 流程(较具体)
|
||||
"operation", # 操作(较具体)
|
||||
"screenshot", # 截图(较通用,放后面)
|
||||
"stage", # 阶段(较通用)
|
||||
"performance", # 性能(较通用)
|
||||
"error", # 错误(较通用)
|
||||
"success", # 成功(较通用)
|
||||
"info", # 信息(最通用,放最后)
|
||||
]
|
||||
|
||||
# 按优先级顺序检查
|
||||
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
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_color_config(theme: str = "litera") -> Dict[str, Dict[str, str]]:
|
||||
"""
|
||||
获取颜色配置(根据主题)
|
||||
|
||||
Args:
|
||||
theme: 主题名称("litera", "darkly" 等)
|
||||
|
||||
Returns:
|
||||
颜色配置字典,包含每种操作类型的颜色设置
|
||||
"""
|
||||
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", # 深蓝灰色背景
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def apply_operation_color(
|
||||
text_widget,
|
||||
start_pos: str,
|
||||
end_pos: str,
|
||||
line: str,
|
||||
theme: str = "litera"
|
||||
) -> None:
|
||||
"""
|
||||
为日志行应用操作类型颜色
|
||||
|
||||
Args:
|
||||
text_widget: tkinter Text 组件
|
||||
start_pos: 起始位置
|
||||
end_pos: 结束位置
|
||||
line: 日志行内容
|
||||
theme: 主题名称
|
||||
"""
|
||||
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:
|
||||
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
|
||||
@@ -0,0 +1,943 @@
|
||||
"""
|
||||
日志颜色配置模块
|
||||
================
|
||||
|
||||
为不同的操作类型定义颜色标签,支持明亮和暗色主题。
|
||||
"""
|
||||
|
||||
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 get_operation_type(line: str) -> Optional[str]:
|
||||
"""
|
||||
根据日志行内容识别操作类型
|
||||
|
||||
日志格式通常是: [时间] [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:
|
||||
return op_type
|
||||
|
||||
# 优先级3: 使用通用关键词匹配(按操作类型优先级)
|
||||
# 调整顺序,让更具体的操作类型优先
|
||||
priority_order = [
|
||||
"lottery", # 开奖相关(更具体)
|
||||
"fansclub", # 粉丝团(更具体)
|
||||
"reservation", # 预约(更具体)
|
||||
"decision", # 决策(更具体)
|
||||
"detection", # 检测(较具体)
|
||||
"ocr", # OCR(较具体)
|
||||
"click", # 点击(较具体)
|
||||
"swipe", # 滑动(较具体)
|
||||
"flow", # 流程(较具体)
|
||||
"operation", # 操作(较具体)
|
||||
"screenshot", # 截图(较通用,放后面)
|
||||
"stage", # 阶段(较通用)
|
||||
"performance", # 性能(较通用)
|
||||
"error", # 错误(较通用)
|
||||
"success", # 成功(较通用)
|
||||
"info", # 信息(最通用,放最后)
|
||||
]
|
||||
|
||||
# 按优先级顺序检查
|
||||
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
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_color_config(theme: str = "litera") -> Dict[str, Dict[str, str]]:
|
||||
"""
|
||||
获取颜色配置(根据主题)
|
||||
|
||||
Args:
|
||||
theme: 主题名称("litera", "darkly" 等)
|
||||
|
||||
Returns:
|
||||
颜色配置字典,包含每种操作类型的颜色设置
|
||||
"""
|
||||
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", # 深蓝灰色背景
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def apply_operation_color(
|
||||
text_widget,
|
||||
start_pos: str,
|
||||
end_pos: str,
|
||||
line: str,
|
||||
theme: str = "litera"
|
||||
) -> None:
|
||||
"""
|
||||
为日志行应用操作类型颜色
|
||||
|
||||
Args:
|
||||
text_widget: tkinter Text 组件
|
||||
start_pos: 起始位置
|
||||
end_pos: 结束位置
|
||||
line: 日志行内容
|
||||
theme: 主题名称
|
||||
"""
|
||||
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:
|
||||
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
|
||||
|
||||
|
||||
"""
|
||||
为不同的操作类型定义颜色标签,支持明亮和暗色主题。
|
||||
"""
|
||||
|
||||
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 get_operation_type(line: str) -> Optional[str]:
|
||||
"""
|
||||
根据日志行内容识别操作类型
|
||||
|
||||
日志格式通常是: [时间] [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:
|
||||
return op_type
|
||||
|
||||
# 优先级3: 使用通用关键词匹配(按操作类型优先级)
|
||||
# 调整顺序,让更具体的操作类型优先
|
||||
priority_order = [
|
||||
"lottery", # 开奖相关(更具体)
|
||||
"fansclub", # 粉丝团(更具体)
|
||||
"reservation", # 预约(更具体)
|
||||
"decision", # 决策(更具体)
|
||||
"detection", # 检测(较具体)
|
||||
"ocr", # OCR(较具体)
|
||||
"click", # 点击(较具体)
|
||||
"swipe", # 滑动(较具体)
|
||||
"flow", # 流程(较具体)
|
||||
"operation", # 操作(较具体)
|
||||
"screenshot", # 截图(较通用,放后面)
|
||||
"stage", # 阶段(较通用)
|
||||
"performance", # 性能(较通用)
|
||||
"error", # 错误(较通用)
|
||||
"success", # 成功(较通用)
|
||||
"info", # 信息(最通用,放最后)
|
||||
]
|
||||
|
||||
# 按优先级顺序检查
|
||||
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
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_color_config(theme: str = "litera") -> Dict[str, Dict[str, str]]:
|
||||
"""
|
||||
获取颜色配置(根据主题)
|
||||
|
||||
Args:
|
||||
theme: 主题名称("litera", "darkly" 等)
|
||||
|
||||
Returns:
|
||||
颜色配置字典,包含每种操作类型的颜色设置
|
||||
"""
|
||||
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", # 深蓝灰色背景
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def apply_operation_color(
|
||||
text_widget,
|
||||
start_pos: str,
|
||||
end_pos: str,
|
||||
line: str,
|
||||
theme: str = "litera"
|
||||
) -> None:
|
||||
"""
|
||||
为日志行应用操作类型颜色
|
||||
|
||||
Args:
|
||||
text_widget: tkinter Text 组件
|
||||
start_pos: 起始位置
|
||||
end_pos: 结束位置
|
||||
line: 日志行内容
|
||||
theme: 主题名称
|
||||
"""
|
||||
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:
|
||||
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
|
||||
@@ -0,0 +1,200 @@
|
||||
"""
|
||||
日志颜色配置模块
|
||||
================
|
||||
|
||||
为不同的操作类型定义颜色标签,支持明亮和暗色主题。
|
||||
"""
|
||||
|
||||
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": [
|
||||
"性能", "耗时", "time", "duration", "elapsed", "ms", "毫秒", "秒",
|
||||
"执行时间", "处理时间", "检测时间"
|
||||
],
|
||||
"error": [
|
||||
"错误", "error", "exception", "失败", "fail", "timeout", "超时",
|
||||
"异常", "崩溃", "中断", "连接失败"
|
||||
],
|
||||
"info": [
|
||||
"信息", "info", "开始", "完成", "初始化", "启动", "停止",
|
||||
"日志", "debug", "调试"
|
||||
],
|
||||
"network": [
|
||||
"网络", "network", "连接", "请求", "响应", "http", "api",
|
||||
"服务器", "接口", "上传", "下载"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def get_operation_type(line: str) -> Optional[str]:
|
||||
"""
|
||||
根据日志行内容识别操作类型
|
||||
|
||||
日志格式通常是: [时间] [GUI] - 操作类型 内容
|
||||
优先识别日志内容中的操作类型关键词(如 "流程"、"滑动"、"阶段诊断"、"预约" 等)
|
||||
|
||||
Args:
|
||||
line: 日志行内容
|
||||
|
||||
Returns:
|
||||
操作类型名称,如果无法识别则返回None
|
||||
"""
|
||||
line_lower = line.lower()
|
||||
|
||||
# 优先级1: 识别日志内容开头的操作类型(最精确)
|
||||
# 日志格式: [时间] [GUI] - 操作类型 内容
|
||||
# 例如: [GUI] - 流程 find_and_open_fudai_detail完成
|
||||
if "[gui] -" in line_lower:
|
||||
parts = line_lower.split("[gui] -")
|
||||
if len(parts) > 1:
|
||||
content = parts[1].strip()
|
||||
# 提取操作类型(第一个词)
|
||||
first_word = content.split()[0] if content.split() else ""
|
||||
if first_word in ["流程", "滑动", "阶段诊断", "预约", "截图", "点击", "识别", "检测"]:
|
||||
return first_word
|
||||
|
||||
# 优先级2: 关键词匹配(更全面的识别)
|
||||
for operation_type, keywords in OPERATION_KEYWORDS.items():
|
||||
for keyword in keywords:
|
||||
if keyword.lower() in line_lower:
|
||||
return operation_type
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_color_config(theme: str = "litera") -> Dict[str, Dict[str, str]]:
|
||||
"""
|
||||
根据主题获取颜色配置
|
||||
|
||||
Args:
|
||||
theme: 主题名称,如 'litera'(明亮), 'darkly'(暗色), 'cyborg'(深色)
|
||||
|
||||
Returns:
|
||||
颜色配置字典,包含各操作类型的颜色设置
|
||||
"""
|
||||
# 基础颜色配置
|
||||
if theme in ["litera", "minty", "pulse", "solar", "united", "yeti"]:
|
||||
# 明亮主题
|
||||
base_config = {
|
||||
"ocr": {"foreground": "#2E8B57", "background": "#F0FFF0"}, # 绿色
|
||||
"click": {"foreground": "#4169E1", "background": "#F0F8FF"}, # 蓝色
|
||||
"swipe": {"foreground": "#FF6347", "background": "#FFF5EE"}, # 红色
|
||||
"screenshot": {"foreground": "#8B4513", "background": "#FFF8DC"}, # 棕色
|
||||
"detection": {"foreground": "#9932CC", "background": "#F8F8FF"}, # 紫色
|
||||
"decision": {"foreground": "#FF8C00", "background": "#FFFACD"}, # 橙色
|
||||
"reservation": {"foreground": "#20B2AA", "background": "#F0FFFF"}, # 青色
|
||||
"fansclub": {"foreground": "#DC143C", "background": "#FFE4E1"}, # 粉红
|
||||
"lottery": {"foreground": "#FFD700", "background": "#FFFFE0"}, # 金色
|
||||
"stage": {"foreground": "#8B008B", "background": "#F0F0F0"}, # 深紫
|
||||
"performance": {"foreground": "#696969", "background": "#F5F5F5"}, # 灰色
|
||||
"error": {"foreground": "#B22222", "background": "#FFE4E1"}, # 深红
|
||||
"info": {"foreground": "#000000", "background": "#FFFFFF"}, # 黑色
|
||||
"network": {"foreground": "#4682B4", "background": "#F0F8FF"} # 钢蓝
|
||||
}
|
||||
else:
|
||||
# 暗色主题
|
||||
base_config = {
|
||||
"ocr": {"foreground": "#98FB98", "background": "#2F4F2F"}, # 亮绿
|
||||
"click": {"foreground": "#87CEEB", "background": "#191970"}, # 亮蓝
|
||||
"swipe": {"foreground": "#FFA07A", "background": "#8B0000"}, # 亮红
|
||||
"screenshot": {"foreground": "#F4A460", "background": "#8B4513"}, # 沙色
|
||||
"detection": {"foreground": "#DDA0DD", "background": "#4B0082"}, # 梅红
|
||||
"decision": {"foreground": "#FFDAB9", "background": "#FF8C00"}, # 桃色
|
||||
"reservation": {"foreground": "#AFEEEE", "background": "#008B8B"}, # 淡青
|
||||
"fansclub": {"foreground": "#FFB6C1", "background": "#8B0000"}, # 浅粉
|
||||
"lottery": {"foreground": "#FFFF00", "background": "#FFD700"}, # 亮黄
|
||||
"stage": {"foreground": "#DDA0DD", "background": "#2F2F2F"}, # 梅红
|
||||
"performance": {"foreground": "#D3D3D3", "background": "#696969"}, # 浅灰
|
||||
"error": {"foreground": "#FFA07A", "background": "#B22222"}, # 亮红
|
||||
"info": {"foreground": "#FFFFFF", "background": "#000000"}, # 白色
|
||||
"network": {"foreground": "#87CEEB", "background": "#4682B4"} # 亮蓝
|
||||
}
|
||||
|
||||
return base_config
|
||||
|
||||
|
||||
def apply_operation_color(
|
||||
text_widget,
|
||||
start_pos: str,
|
||||
end_pos: str,
|
||||
operation_type: Optional[str],
|
||||
theme: str = "litera"
|
||||
) -> None:
|
||||
"""
|
||||
为日志文本中的指定范围应用操作类型颜色标签
|
||||
|
||||
Args:
|
||||
text_widget: Tkinter文本控件
|
||||
start_pos: 开始位置(如 "1.0")
|
||||
end_pos: 结束位置(如 "1.end")
|
||||
operation_type: 操作类型(None表示不应用颜色)
|
||||
theme: 主题名称
|
||||
"""
|
||||
try:
|
||||
if operation_type is None:
|
||||
return
|
||||
|
||||
# 获取颜色配置
|
||||
color_config = get_color_config(theme)
|
||||
colors = color_config.get(operation_type)
|
||||
|
||||
if colors is None:
|
||||
return
|
||||
|
||||
# 创建唯一标签名
|
||||
tag_name = f"operation_{operation_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
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable, Optional, List, Dict
|
||||
from typing import Any, Callable, Optional, List, Dict, Tuple
|
||||
import queue
|
||||
import re
|
||||
import threading
|
||||
@@ -44,7 +44,7 @@ except ImportError:
|
||||
class EnhancedLogViewer(ttk.Frame):
|
||||
"""增强的日志查看器组件"""
|
||||
|
||||
def __init__(self, parent: Any, log_queue: "queue.Queue[str]" = None):
|
||||
def __init__(self, parent: Any, log_queue: Optional[queue.Queue] = None):
|
||||
super().__init__(parent)
|
||||
|
||||
# 初始化数据
|
||||
@@ -372,9 +372,9 @@ def format_gui_log_line(line: str) -> str:
|
||||
|
||||
def create_log_viewer(
|
||||
parent: Any,
|
||||
log_queue: "queue.Queue[str]",
|
||||
log_queue: Optional[queue.Queue],
|
||||
on_line: Callable[[str], None]
|
||||
) -> tuple[ScrolledText, Callable[[], None]]:
|
||||
) -> Any:
|
||||
"""创建日志查看器组件(兼容旧接口)。
|
||||
|
||||
参数:
|
||||
|
||||
@@ -49,3 +49,25 @@ def create_main_window(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -50,3 +50,25 @@ def create_ocr_panel(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+370
-144
@@ -27,6 +27,22 @@ from gui.gui_core import (
|
||||
)
|
||||
from path_config import get_logs_dir
|
||||
|
||||
# 导入日志颜色配置模块
|
||||
try:
|
||||
from gui.components.log_color_config import (
|
||||
get_color_config,
|
||||
apply_operation_color,
|
||||
get_operation_type,
|
||||
)
|
||||
except ImportError:
|
||||
# 如果模块不存在,使用空函数作为回退
|
||||
def get_color_config(theme: str = "litera"):
|
||||
return {}
|
||||
def apply_operation_color(*args, **kwargs):
|
||||
pass
|
||||
def get_operation_type(line: str) -> str | None:
|
||||
return None
|
||||
|
||||
# 抑制 PyTorch DataLoader 的 pin_memory 警告(当没有 GPU 时,EasyOCR 会触发此警告)
|
||||
warnings.filterwarnings("ignore", message=".*pin_memory.*", category=UserWarning)
|
||||
warnings.filterwarnings("ignore", message=".*accelerator.*", category=UserWarning)
|
||||
@@ -1087,7 +1103,7 @@ def main():
|
||||
|
||||
row4c = ttk.Frame(fudai_find_box)
|
||||
row4c.pack(fill=X, padx=10, pady=(0, 10))
|
||||
ttk.Label(row4c, text="直播间检测阈值:").pack(side=LEFT)
|
||||
ttk.Label(row4c, text="直播间检测阈值(白色像素比例):").pack(side=LEFT)
|
||||
ttk.Spinbox(
|
||||
row4c,
|
||||
from_=0.0,
|
||||
@@ -1096,7 +1112,7 @@ def main():
|
||||
textvariable=live_room_match_threshold_var,
|
||||
width=6,
|
||||
).pack(side=LEFT)
|
||||
ttk.Label(row4c, text="(0.0~1.0,默认0.7,值越高越严格)").pack(
|
||||
ttk.Label(row4c, text="(0.0~1.0,默认0.8,多边形区域白色像素比例>=此值判定为在直播间)").pack(
|
||||
side=LEFT, padx=(6, 0)
|
||||
)
|
||||
|
||||
@@ -1623,7 +1639,7 @@ def main():
|
||||
cfg2["stage_diag_max_step_time"] = float(
|
||||
stage_diag_max_step_time_var.get() or 2.0
|
||||
)
|
||||
cfg2["enable_ocr_mode1"] = bool(enable_ocr_mode1_var.get())
|
||||
cfg2["enable_ocr_mode1"] = bool(cfg.get("enable_ocr_mode1", False))
|
||||
cfg2["fudai_template_match_enabled"] = bool(
|
||||
fudai_template_match_enabled_var.get()
|
||||
)
|
||||
@@ -1941,6 +1957,7 @@ def main():
|
||||
high_value_tab = ttk.Frame(notebook)
|
||||
actions_log_tab = ttk.Frame(notebook)
|
||||
ocr_results_tab = ttk.Frame(notebook)
|
||||
win_record_tab = ttk.Frame(notebook)
|
||||
notebook.add(log_tab, text="运行日志")
|
||||
notebook.add(preview_tab, text="截图预览")
|
||||
notebook.add(stats_tab, text="统计信息")
|
||||
@@ -1948,6 +1965,7 @@ def main():
|
||||
notebook.add(high_value_tab, text="高价值房间")
|
||||
notebook.add(actions_log_tab, text="行为日志")
|
||||
notebook.add(ocr_results_tab, text="OCR结果")
|
||||
notebook.add(win_record_tab, text="中奖记录")
|
||||
|
||||
# 日志区
|
||||
log_box = ttk.Frame(log_tab)
|
||||
@@ -2100,6 +2118,19 @@ def main():
|
||||
log_text.tag_configure("log_critical", foreground="#F44336", font=("Consolas", 10, "bold")) # 加粗亮红色
|
||||
log_text.tag_configure("log_performance", foreground="#81C784") # 亮绿色,性能数据
|
||||
log_text.tag_configure("log_module", foreground="#BA68C8") # 亮紫色,模块标识
|
||||
|
||||
# 配置操作类型颜色标签(使用模块化配置)
|
||||
try:
|
||||
color_config = get_color_config(current_theme)
|
||||
for op_type, colors in color_config.items():
|
||||
tag_name = f"op_{op_type}"
|
||||
log_text.tag_configure(
|
||||
tag_name,
|
||||
foreground=colors["foreground"],
|
||||
background=colors["background"],
|
||||
)
|
||||
except Exception:
|
||||
pass # 忽略操作类型颜色配置失败
|
||||
except Exception:
|
||||
pass # 忽略标签配置失败
|
||||
|
||||
@@ -2273,7 +2304,6 @@ def main():
|
||||
0 if infinite_loop_var.get() else int(wait_minutes_var.get() or 5)
|
||||
)
|
||||
return RunParams(
|
||||
enable_ocr_mode1=bool(enable_ocr_mode1_var.get()),
|
||||
device_id=device_var.get().strip(),
|
||||
y_pianyi=int(y_var.get()),
|
||||
needswitch=bool(needswitch_var.get()),
|
||||
@@ -2287,26 +2317,15 @@ def main():
|
||||
auto_join_fansclub=bool(auto_join_var.get()),
|
||||
fansclub_fail_action=str(fansclub_action_var.get() or "stay").lower(),
|
||||
# Web端新增参数
|
||||
high_value_room_revisit_enabled=bool(
|
||||
high_value_room_revisit_enabled_var.get()
|
||||
),
|
||||
high_value_room_revisit_only_current_run=bool(
|
||||
high_value_room_revisit_only_current_run_var.get()
|
||||
),
|
||||
reservation_back_verify_enabled=bool(
|
||||
reservation_back_verify_enabled_var.get()
|
||||
),
|
||||
reservation_back_swipe_delay=float(
|
||||
reservation_back_swipe_delay_var.get() or 0
|
||||
),
|
||||
reservation_preempt_min_value=float(
|
||||
reservation_preempt_min_value_var.get() or 0
|
||||
),
|
||||
fudai_find_max_attempts=int(fudai_find_max_attempts_var.get() or 0),
|
||||
high_value_room_revisit_enabled=bool(high_value_room_revisit_enabled_var.get()),
|
||||
high_value_room_revisit_only_current_run=bool(high_value_room_revisit_only_current_run_var.get()),
|
||||
reservation_back_verify_enabled=bool(reservation_back_verify_enabled_var.get()),
|
||||
reservation_back_swipe_delay=float(reservation_back_swipe_delay_var.get() or 1.0),
|
||||
reservation_preempt_min_value=float(reservation_preempt_min_value_var.get() or 1000),
|
||||
fudai_find_max_attempts=int(fudai_find_max_attempts_var.get() or 5),
|
||||
enable_ocr_mode1=bool(enable_ocr_mode1_var.get()),
|
||||
fudai_template_match_enabled=bool(fudai_template_match_enabled_var.get()),
|
||||
fudai_template_match_threshold=float(
|
||||
fudai_template_match_threshold_var.get() or 0.7
|
||||
),
|
||||
fudai_template_match_threshold=float(fudai_template_match_threshold_var.get() or 0.7),
|
||||
)
|
||||
|
||||
def start_run():
|
||||
@@ -2354,57 +2373,7 @@ def main():
|
||||
side=LEFT, padx=(0, 8)
|
||||
)
|
||||
|
||||
ttk.Separator(actions, orient="vertical").pack(side=LEFT, fill=Y, padx=10, pady=3)
|
||||
test_seconds_var = tk.IntVar(
|
||||
value=int(cfg.get("yanghao_recommend_duration_seconds", 60) or 60)
|
||||
)
|
||||
ttk.Label(actions, text="测试养号(秒):").pack(side=LEFT)
|
||||
ttk.Spinbox(
|
||||
actions, from_=10, to=3600, increment=10, textvariable=test_seconds_var, width=8
|
||||
).pack(side=LEFT, padx=(0, 8))
|
||||
|
||||
def start_test_yanghao():
|
||||
if runner.is_running():
|
||||
on_line("[运行] 已在运行中")
|
||||
return
|
||||
save_ui_to_config()
|
||||
secs = int(test_seconds_var.get() or 90)
|
||||
dev = device_var.get().strip()
|
||||
on_line(f"[测试] 启动养号流程:device={dev or '(auto)'} seconds={secs}")
|
||||
status_var.set("运行中")
|
||||
try:
|
||||
runner.start_test_yanghao_flow(dev, secs)
|
||||
except Exception as e:
|
||||
status_var.set("启动失败")
|
||||
on_line(f"[错误] {e}")
|
||||
|
||||
ttk.Button(actions, text="测试养号流程", command=start_test_yanghao).pack(side=LEFT)
|
||||
|
||||
ttk.Separator(actions, orient="vertical").pack(side=LEFT, fill=Y, padx=10, pady=3)
|
||||
test_comment_var = tk.StringVar(value="测试评论")
|
||||
ttk.Label(actions, text="测试评论:").pack(side=LEFT)
|
||||
ttk.Entry(actions, textvariable=test_comment_var, width=12).pack(
|
||||
side=LEFT, padx=(0, 8)
|
||||
)
|
||||
|
||||
def start_test_comment():
|
||||
if runner.is_running():
|
||||
on_line("[运行] 已在运行中")
|
||||
return
|
||||
save_ui_to_config()
|
||||
text = test_comment_var.get().strip()
|
||||
dev = device_var.get().strip()
|
||||
on_line(f"[测试] 启动评论测试:device={dev or '(auto)'} text={text}")
|
||||
status_var.set("运行中")
|
||||
try:
|
||||
runner.start_test_comment(dev, text)
|
||||
except Exception as e:
|
||||
status_var.set("启动失败")
|
||||
on_line(f"[错误] {e}")
|
||||
|
||||
ttk.Button(actions, text="测试评论", command=start_test_comment).pack(side=LEFT)
|
||||
|
||||
ttk.Separator(actions, orient="vertical").pack(side=LEFT, fill=Y, padx=10, pady=3)
|
||||
# (已移除:测试养号/测试评论 按钮与相关UI)
|
||||
|
||||
def send_back_key():
|
||||
dev = device_var.get().strip()
|
||||
@@ -2422,37 +2391,56 @@ def main():
|
||||
def pump_logs():
|
||||
changed = False
|
||||
try:
|
||||
# 获取当前主题(用于颜色配置)
|
||||
try:
|
||||
current_theme = str(gui_theme_var.get() or "litera")
|
||||
except Exception:
|
||||
current_theme = "litera"
|
||||
|
||||
while True:
|
||||
line = q.get_nowait()
|
||||
try:
|
||||
# 插入日志行并应用颜色标签
|
||||
start_pos = log_text.index("end-1c")
|
||||
|
||||
# 检查是否需要应用颜色标签
|
||||
tag = None
|
||||
if "[INFO]" in line:
|
||||
tag = "log_info"
|
||||
elif "[WARNING]" in line:
|
||||
tag = "log_warning"
|
||||
elif "[ERROR]" in line:
|
||||
tag = "log_error"
|
||||
elif "[CRITICAL]" in line:
|
||||
tag = "log_critical"
|
||||
elif "elapsed_seconds=" in line or "耗时" in line:
|
||||
tag = "log_performance"
|
||||
elif re.search(r'\[[\w\.]+\]', line):
|
||||
tag = "log_module"
|
||||
|
||||
# 插入文本
|
||||
log_text.insert("end", line + "\n")
|
||||
end_pos = log_text.index("end-1c")
|
||||
|
||||
# 如果有标签,应用到这一行
|
||||
if tag:
|
||||
end_pos = log_text.index("end-1c")
|
||||
# 优先级1: 先检查操作类型颜色(更具体)
|
||||
op_type_applied = False
|
||||
try:
|
||||
op_type = get_operation_type(line)
|
||||
if op_type:
|
||||
apply_operation_color(
|
||||
log_text, start_pos, end_pos, line, current_theme
|
||||
)
|
||||
op_type_applied = True
|
||||
except Exception:
|
||||
pass # 忽略操作类型颜色应用失败
|
||||
|
||||
# 优先级2: 再检查日志级别标签(作为补充,如果操作类型未匹配)
|
||||
# 只有在没有操作类型颜色时才应用级别标签
|
||||
if not op_type_applied:
|
||||
try:
|
||||
log_text.tag_add(tag, start_pos, end_pos)
|
||||
tag = None
|
||||
if "[INFO]" in line:
|
||||
tag = "log_info"
|
||||
elif "[WARNING]" in line:
|
||||
tag = "log_warning"
|
||||
elif "[ERROR]" in line:
|
||||
tag = "log_error"
|
||||
elif "[CRITICAL]" in line:
|
||||
tag = "log_critical"
|
||||
elif "elapsed_seconds=" in line or "耗时" in line:
|
||||
tag = "log_performance"
|
||||
elif re.search(r'\[[\w\.]+\]', line):
|
||||
tag = "log_module"
|
||||
|
||||
if tag:
|
||||
log_text.tag_add(tag, start_pos, end_pos)
|
||||
except Exception:
|
||||
pass # 忽略标签应用失败
|
||||
pass # 忽略级别标签应用失败
|
||||
|
||||
# 不再自动滚动到底部,让用户自由控制滚动位置
|
||||
changed = True
|
||||
@@ -3430,35 +3418,43 @@ def main():
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 配置行为日志颜色标签(与主日志保持一致)
|
||||
try:
|
||||
# 根据主题调整行为日志颜色
|
||||
light_themes = {"litera", "flatly", "journal", "minty", "cosmo"}
|
||||
# 配置行为日志颜色标签(使用统一的颜色配置模块)
|
||||
def configure_actions_log_colors():
|
||||
"""根据当前主题配置行为日志的颜色标签"""
|
||||
try:
|
||||
current_theme = str(gui_theme_var.get() or "litera")
|
||||
# 获取当前主题
|
||||
try:
|
||||
current_theme = str(gui_theme_var.get() or "litera")
|
||||
except Exception:
|
||||
current_theme = "litera"
|
||||
|
||||
# 获取颜色配置
|
||||
color_config = get_color_config(current_theme)
|
||||
|
||||
# 根据主题设置背景和前景色
|
||||
light_themes = {"litera", "flatly", "journal", "minty", "cosmo"}
|
||||
is_light = current_theme.lower() in light_themes
|
||||
if is_light:
|
||||
actions_log_text.configure(background="#FFFFFF", foreground="#2C2C2C", insertbackground="#2C2C2C")
|
||||
else:
|
||||
actions_log_text.configure(background="#1E1E1E", foreground="#E0E0E0", insertbackground="#FFFFFF")
|
||||
|
||||
# 为所有操作类型配置标签
|
||||
for op_type, colors in color_config.items():
|
||||
tag_name = f"op_{op_type}"
|
||||
try:
|
||||
actions_log_text.tag_configure(
|
||||
tag_name,
|
||||
foreground=colors["foreground"],
|
||||
background=colors["background"],
|
||||
)
|
||||
except Exception:
|
||||
pass # 忽略标签配置失败
|
||||
except Exception:
|
||||
current_theme = "litera"
|
||||
|
||||
if current_theme in light_themes:
|
||||
# 明亮主题
|
||||
actions_log_text.configure(background="#FFFFFF", foreground="#2C2C2C", insertbackground="#2C2C2C")
|
||||
actions_log_text.tag_configure("action_timestamp", foreground="#8B8B8B")
|
||||
actions_log_text.tag_configure("action_operation", foreground="#1E88E5") # 蓝色操作
|
||||
actions_log_text.tag_configure("action_ocr", foreground="#388E3C") # 绿色OCR
|
||||
actions_log_text.tag_configure("action_decision", foreground="#F57C00") # 橙色决策
|
||||
actions_log_text.tag_configure("action_state", foreground="#7B1FA2") # 紫色状态
|
||||
actions_log_text.tag_configure("action_performance", foreground="#D32F2F") # 红色性能
|
||||
else:
|
||||
# 暗色主题
|
||||
actions_log_text.configure(background="#1E1E1E", foreground="#E0E0E0", insertbackground="#FFFFFF")
|
||||
actions_log_text.tag_configure("action_timestamp", foreground="#A0A0A0")
|
||||
actions_log_text.tag_configure("action_operation", foreground="#64B5F6") # 亮蓝色操作
|
||||
actions_log_text.tag_configure("action_ocr", foreground="#81C784") # 亮绿色OCR
|
||||
actions_log_text.tag_configure("action_decision", foreground="#FFB74D") # 金色决策
|
||||
actions_log_text.tag_configure("action_state", foreground="#BA68C8") # 亮紫色状态
|
||||
actions_log_text.tag_configure("action_performance", foreground="#EF5350") # 亮红色性能
|
||||
except Exception:
|
||||
pass # 忽略颜色配置失败
|
||||
pass # 忽略颜色配置失败
|
||||
|
||||
# 初始配置
|
||||
configure_actions_log_colors()
|
||||
|
||||
actions_filter_var = tk.StringVar(value="")
|
||||
|
||||
@@ -3515,6 +3511,12 @@ def main():
|
||||
|
||||
actions_log_text.delete("1.0", "end")
|
||||
if tail:
|
||||
# 获取当前主题(用于颜色配置)
|
||||
try:
|
||||
current_theme = str(gui_theme_var.get() or "litera")
|
||||
except Exception:
|
||||
current_theme = "litera"
|
||||
|
||||
# 逐行插入并应用颜色标签
|
||||
for i, line in enumerate(tail):
|
||||
start_pos = actions_log_text.index("end-1c")
|
||||
@@ -3524,29 +3526,18 @@ def main():
|
||||
actions_log_text.insert("end", "\n")
|
||||
actions_log_text.insert("end", line)
|
||||
|
||||
# 根据内容类型应用颜色标签
|
||||
# 使用统一的颜色配置模块应用颜色
|
||||
end_pos = actions_log_text.index("end")
|
||||
tag = None
|
||||
|
||||
if "操作:" in line or "执行" in line:
|
||||
tag = "action_operation"
|
||||
elif "OCR" in line or "识别" in line:
|
||||
tag = "action_ocr"
|
||||
elif "决策" in line or "判断" in line:
|
||||
tag = "action_decision"
|
||||
elif "状态" in line or "阶段" in line:
|
||||
tag = "action_state"
|
||||
elif "耗时" in line or "时间" in line or "性能" in line:
|
||||
tag = "action_performance"
|
||||
elif re.search(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}', line):
|
||||
tag = "action_timestamp"
|
||||
|
||||
# 应用标签
|
||||
if tag:
|
||||
try:
|
||||
actions_log_text.tag_add(tag, start_pos, end_pos)
|
||||
except Exception:
|
||||
pass # 忽略标签应用失败
|
||||
try:
|
||||
apply_operation_color(
|
||||
actions_log_text,
|
||||
start_pos,
|
||||
end_pos,
|
||||
line,
|
||||
current_theme
|
||||
)
|
||||
except Exception:
|
||||
pass # 忽略颜色应用失败
|
||||
else:
|
||||
actions_log_text.insert("1.0", "暂无匹配的行为日志")
|
||||
|
||||
@@ -3719,6 +3710,240 @@ def main():
|
||||
side=LEFT, padx=(10, 0)
|
||||
)
|
||||
|
||||
# 中奖记录显示
|
||||
win_record_top = ttk.Frame(win_record_tab)
|
||||
win_record_top.pack(fill=X, padx=10, pady=(10, 0))
|
||||
|
||||
win_record_left = ttk.Frame(win_record_tab)
|
||||
win_record_left.pack(side=LEFT, fill=BOTH, expand=True, padx=(10, 5), pady=10)
|
||||
|
||||
win_record_right = ttk.Frame(win_record_tab)
|
||||
win_record_right.pack(side=RIGHT, fill=BOTH, expand=False, padx=(5, 10), pady=10, ipadx=10)
|
||||
|
||||
# 左侧:中奖截图列表
|
||||
win_list_label = ttk.Label(win_record_left, text="中奖截图列表:")
|
||||
win_list_label.pack(anchor="w", padx=(0, 10), pady=(0, 5))
|
||||
|
||||
win_list_frame = ttk.Frame(win_record_left)
|
||||
win_list_frame.pack(fill=BOTH, expand=True)
|
||||
|
||||
win_list_scrollbar = ttk.Scrollbar(win_list_frame)
|
||||
win_list_scrollbar.pack(side=RIGHT, fill=Y)
|
||||
|
||||
win_listbox = tk.Listbox(win_list_frame, yscrollcommand=win_list_scrollbar.set, font=("Consolas", 9))
|
||||
win_listbox.pack(side=LEFT, fill=BOTH, expand=True)
|
||||
win_list_scrollbar.config(command=win_listbox.yview)
|
||||
|
||||
# 存储文件路径映射(索引 -> 文件路径)
|
||||
_win_file_paths: dict[int, str] = {}
|
||||
|
||||
# 右侧:截图预览
|
||||
win_preview_label = ttk.Label(win_record_right, text="截图预览:")
|
||||
win_preview_label.pack(anchor="w", pady=(0, 5))
|
||||
|
||||
win_preview_frame = ttk.Frame(win_record_right)
|
||||
win_preview_frame.pack(fill=BOTH, expand=True)
|
||||
|
||||
win_image_label = ttk.Label(win_preview_frame)
|
||||
win_image_label.pack(fill=BOTH, expand=True)
|
||||
_win_img_ref: dict[str, Any] = {"photo": None}
|
||||
|
||||
def scan_win_images():
|
||||
"""扫描中奖截图目录"""
|
||||
try:
|
||||
from path_config import get_pic_dir
|
||||
pic_dir = get_pic_dir()
|
||||
except Exception:
|
||||
import path_config
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
|
||||
prize_dir = os.path.join(pic_dir, "lottery_prize_captures")
|
||||
win_images = []
|
||||
|
||||
if os.path.exists(prize_dir):
|
||||
for file in os.listdir(prize_dir):
|
||||
if file.lower().endswith((".png", ".jpg", ".jpeg")):
|
||||
file_path = os.path.join(prize_dir, file)
|
||||
# 获取文件修改时间
|
||||
try:
|
||||
mtime = os.path.getmtime(file_path)
|
||||
win_images.append((file, file_path, mtime))
|
||||
except Exception:
|
||||
win_images.append((file, file_path, 0))
|
||||
|
||||
# 按时间倒序排序(最新的在前)
|
||||
win_images.sort(key=lambda x: x[2], reverse=True)
|
||||
return win_images
|
||||
|
||||
def refresh_win_record():
|
||||
"""刷新中奖记录列表"""
|
||||
try:
|
||||
win_images = scan_win_images()
|
||||
win_listbox.delete(0, tk.END)
|
||||
_win_file_paths.clear()
|
||||
|
||||
for idx, (file, file_path, mtime) in enumerate(win_images):
|
||||
# 格式化显示:文件名 + 时间
|
||||
try:
|
||||
from datetime import datetime
|
||||
dt = datetime.fromtimestamp(mtime)
|
||||
time_str = dt.strftime("%Y-%m-%d %H:%M:%S")
|
||||
display_text = f"{file} ({time_str})"
|
||||
except Exception:
|
||||
display_text = file
|
||||
|
||||
win_listbox.insert(tk.END, display_text)
|
||||
# 存储文件路径映射
|
||||
_win_file_paths[idx] = file_path
|
||||
|
||||
if win_images:
|
||||
on_line(f"[中奖记录] 扫描到 {len(win_images)} 张中奖截图")
|
||||
else:
|
||||
on_line("[中奖记录] 暂无中奖截图")
|
||||
except Exception as e:
|
||||
on_line(f"[中奖记录] 刷新失败:{e}")
|
||||
|
||||
def on_win_list_select(event):
|
||||
"""当选择中奖截图时,显示预览"""
|
||||
try:
|
||||
selection = win_listbox.curselection()
|
||||
if not selection:
|
||||
return
|
||||
|
||||
index = selection[0]
|
||||
# 从映射中获取文件路径
|
||||
if index in _win_file_paths:
|
||||
file_path = _win_file_paths[index]
|
||||
_load_win_image(file_path)
|
||||
except Exception as e:
|
||||
on_line(f"[中奖记录] 预览失败:{e}")
|
||||
|
||||
def _load_win_image(img_path: str):
|
||||
"""加载并显示中奖截图"""
|
||||
if not os.path.exists(img_path):
|
||||
win_image_label.configure(image="")
|
||||
_win_img_ref["photo"] = None
|
||||
return
|
||||
|
||||
try:
|
||||
img = Image.open(img_path)
|
||||
img.load()
|
||||
img = img.convert("RGB")
|
||||
except Exception as e:
|
||||
on_line(f"[中奖记录] 图片加载失败:{e}")
|
||||
return
|
||||
|
||||
# 获取预览区域尺寸
|
||||
try:
|
||||
win_preview_frame.update_idletasks()
|
||||
w = win_preview_frame.winfo_width()
|
||||
h = win_preview_frame.winfo_height()
|
||||
if w <= 1 or h <= 1:
|
||||
w, h = 400, 600
|
||||
except Exception:
|
||||
w, h = 400, 600
|
||||
|
||||
max_w = max(200, w - 20)
|
||||
max_h = max(300, h - 20)
|
||||
|
||||
try:
|
||||
resample = Image.Resampling.LANCZOS
|
||||
except AttributeError:
|
||||
resample = 1
|
||||
|
||||
img.thumbnail((max_w, max_h), resample)
|
||||
photo = ImageTk.PhotoImage(img)
|
||||
_win_img_ref["photo"] = photo
|
||||
win_image_label.configure(image=photo)
|
||||
|
||||
win_listbox.bind("<<ListboxSelect>>", on_win_list_select)
|
||||
|
||||
ttk.Button(win_record_top, text="刷新列表", command=refresh_win_record).pack(side=LEFT, padx=(0, 10))
|
||||
|
||||
def open_win_folder():
|
||||
"""打开中奖截图目录"""
|
||||
try:
|
||||
from path_config import get_pic_dir
|
||||
pic_dir = get_pic_dir()
|
||||
except Exception:
|
||||
import path_config
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
|
||||
prize_dir = os.path.join(pic_dir, "lottery_prize_captures")
|
||||
os.makedirs(prize_dir, exist_ok=True)
|
||||
try:
|
||||
os.startfile(prize_dir) # type: ignore[attr-defined]
|
||||
except Exception as e:
|
||||
on_line(f"[中奖记录] 打开目录失败:{e}")
|
||||
|
||||
ttk.Button(win_record_top, text="打开目录", command=open_win_folder).pack(side=LEFT)
|
||||
|
||||
# 误识别记录管理
|
||||
false_positive_frame = ttk.LabelFrame(win_record_right, text="误识别记录管理")
|
||||
false_positive_frame.pack(fill=X, pady=(10, 0))
|
||||
|
||||
false_positive_text = ScrolledText(false_positive_frame, height=6)
|
||||
false_positive_text.pack(fill=X, padx=10, pady=10)
|
||||
|
||||
def load_false_positives():
|
||||
"""加载误识别记录"""
|
||||
try:
|
||||
from path_config import get_pic_dir
|
||||
pic_dir = get_pic_dir()
|
||||
except Exception:
|
||||
import path_config
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
|
||||
false_positive_file = os.path.join(pic_dir, "lottery_prize_captures", "false_positives.json")
|
||||
if not os.path.exists(false_positive_file):
|
||||
false_positive_text.delete("1.0", "end")
|
||||
false_positive_text.insert("1.0", "暂无误识别记录")
|
||||
return
|
||||
|
||||
try:
|
||||
import json
|
||||
with open(false_positive_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
false_positives = data.get("false_positives", [])
|
||||
false_positive_text.delete("1.0", "end")
|
||||
if false_positives:
|
||||
false_positive_text.insert("1.0", "\n".join(false_positives))
|
||||
else:
|
||||
false_positive_text.insert("1.0", "暂无误识别记录")
|
||||
except Exception as e:
|
||||
false_positive_text.delete("1.0", "end")
|
||||
false_positive_text.insert("1.0", f"加载失败:{e}")
|
||||
|
||||
def save_false_positives():
|
||||
"""保存误识别记录"""
|
||||
try:
|
||||
from path_config import get_pic_dir
|
||||
pic_dir = get_pic_dir()
|
||||
except Exception:
|
||||
import path_config
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
|
||||
false_positive_file = os.path.join(pic_dir, "lottery_prize_captures", "false_positives.json")
|
||||
os.makedirs(os.path.dirname(false_positive_file), exist_ok=True)
|
||||
|
||||
content = false_positive_text.get("1.0", "end-1c")
|
||||
lines = [line.strip() for line in content.splitlines() if line.strip()]
|
||||
|
||||
try:
|
||||
import json
|
||||
with open(false_positive_file, "w", encoding="utf-8") as f:
|
||||
json.dump({"false_positives": lines}, f, ensure_ascii=False, indent=2)
|
||||
on_line(f"[中奖记录] 已保存 {len(lines)} 条误识别记录")
|
||||
except Exception as e:
|
||||
on_line(f"[中奖记录] 保存失败:{e}")
|
||||
|
||||
false_positive_btn_frame = ttk.Frame(false_positive_frame)
|
||||
false_positive_btn_frame.pack(fill=X, padx=10, pady=(0, 10))
|
||||
ttk.Button(false_positive_btn_frame, text="刷新", command=load_false_positives).pack(side=LEFT, padx=(0, 5))
|
||||
ttk.Button(false_positive_btn_frame, text="保存", command=save_false_positives).pack(side=LEFT)
|
||||
|
||||
load_false_positives()
|
||||
|
||||
pump_logs()
|
||||
|
||||
def delayed_refresh_preview() -> None:
|
||||
@@ -3730,6 +3955,7 @@ def main():
|
||||
root.after(500, refresh_reservations) # type: ignore[arg-type]
|
||||
root.after(500, refresh_high_value_rooms) # type: ignore[arg-type]
|
||||
root.after(500, refresh_actions_log) # type: ignore[arg-type]
|
||||
root.after(500, refresh_win_record) # type: ignore[arg-type]
|
||||
|
||||
# 定期刷新行为日志(每2秒)
|
||||
def auto_refresh_actions_log() -> None:
|
||||
@@ -3771,4 +3997,4 @@ if __name__ == "__main__":
|
||||
print_version_banner("gui_app")
|
||||
except Exception:
|
||||
pass
|
||||
main()
|
||||
main()
|
||||
+7
-166
@@ -894,172 +894,9 @@ class Runner:
|
||||
self._reader_thread = threading.Thread(target=_reader, daemon=True)
|
||||
self._reader_thread.start()
|
||||
|
||||
def start_test_yanghao_flow(self, device_id: str, seconds: int) -> None:
|
||||
if self.is_running():
|
||||
raise RuntimeError("已经在运行")
|
||||
# (已移除) 测试养号启动器
|
||||
|
||||
seconds = int(seconds or 0)
|
||||
if seconds <= 0:
|
||||
seconds = 90
|
||||
|
||||
run_cli_path = path_config.get_run_cli_path()
|
||||
if not os.path.exists(run_cli_path):
|
||||
raise FileNotFoundError(
|
||||
f"未找到 run_cli.py 文件。\n"
|
||||
f"预期路径: {run_cli_path}\n"
|
||||
f"请确保 run_cli.py 位于项目根目录。"
|
||||
)
|
||||
cmd = [
|
||||
sys.executable,
|
||||
run_cli_path,
|
||||
"--test-yanghao-flow",
|
||||
"--test-yanghao-flow-seconds",
|
||||
str(seconds),
|
||||
]
|
||||
if device_id:
|
||||
cmd += ["--device-id", device_id]
|
||||
|
||||
env = os.environ.copy()
|
||||
env.setdefault("PYTHONIOENCODING", "utf-8")
|
||||
|
||||
adb_exe = find_adb_executable()
|
||||
if adb_exe:
|
||||
adb_dir = os.path.dirname(adb_exe)
|
||||
env["PATH"] = adb_dir + os.pathsep + env.get("PATH", "")
|
||||
env["ADB_EXECUTABLE"] = adb_exe
|
||||
else:
|
||||
self._on_line("[警告] 未找到 adb.exe:请安装 platform-tools 或将 adb 加入 PATH")
|
||||
|
||||
p = subprocess.Popen(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
env=env,
|
||||
cwd=path_config.PROJECT_ROOT,
|
||||
)
|
||||
|
||||
with self._lock:
|
||||
self._proc = p
|
||||
self._pid = p.pid
|
||||
self._start_ts = time.time()
|
||||
self._exit_code = None
|
||||
self._last_log_ts = time.time()
|
||||
self._counters = {}
|
||||
self._fudai_last = {
|
||||
"content": "",
|
||||
"countdown": "",
|
||||
"participants": None,
|
||||
"copies": None,
|
||||
"prize_value_yuan": None,
|
||||
"updated_ts": None,
|
||||
}
|
||||
self._events = []
|
||||
self._wins = []
|
||||
|
||||
def _reader():
|
||||
assert self._proc is not None
|
||||
out = self._proc.stdout
|
||||
if out is None:
|
||||
return
|
||||
for line in out:
|
||||
cleaned_line = line.rstrip("\n")
|
||||
self._on_line(cleaned_line)
|
||||
try:
|
||||
self._update_stats_from_line(cleaned_line)
|
||||
except Exception:
|
||||
pass
|
||||
rc = self._proc.wait()
|
||||
with self._lock:
|
||||
self._exit_code = rc
|
||||
self._on_line(f"[进程结束] exit_code={rc}")
|
||||
|
||||
self._reader_thread = threading.Thread(target=_reader, daemon=True)
|
||||
self._reader_thread.start()
|
||||
|
||||
def start_test_comment(self, device_id: str, text: str) -> None:
|
||||
if self.is_running():
|
||||
raise RuntimeError("已经在运行")
|
||||
|
||||
text = str(text or "").strip()
|
||||
run_cli_path = path_config.get_run_cli_path()
|
||||
if not os.path.exists(run_cli_path):
|
||||
raise FileNotFoundError(
|
||||
f"未找到 run_cli.py 文件。\n"
|
||||
f"预期路径: {run_cli_path}\n"
|
||||
f"请确保 run_cli.py 位于项目根目录。"
|
||||
)
|
||||
cmd = [
|
||||
sys.executable,
|
||||
run_cli_path,
|
||||
"--test-comment",
|
||||
]
|
||||
if text:
|
||||
cmd += ["--test-comment-text", text]
|
||||
if device_id:
|
||||
cmd += ["--device-id", device_id]
|
||||
|
||||
env = os.environ.copy()
|
||||
env.setdefault("PYTHONIOENCODING", "utf-8")
|
||||
|
||||
adb_exe = find_adb_executable()
|
||||
if adb_exe:
|
||||
adb_dir = os.path.dirname(adb_exe)
|
||||
env["PATH"] = adb_dir + os.pathsep + env.get("PATH", "")
|
||||
env["ADB_EXECUTABLE"] = adb_exe
|
||||
else:
|
||||
self._on_line("[警告] 未找到 adb.exe:请安装 platform-tools 或将 adb 加入 PATH")
|
||||
|
||||
p = subprocess.Popen(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
env=env,
|
||||
cwd=path_config.PROJECT_ROOT,
|
||||
)
|
||||
|
||||
with self._lock:
|
||||
self._proc = p
|
||||
self._pid = p.pid
|
||||
self._start_ts = time.time()
|
||||
self._exit_code = None
|
||||
self._last_log_ts = time.time()
|
||||
self._counters = {}
|
||||
self._fudai_last = {
|
||||
"content": "",
|
||||
"countdown": "",
|
||||
"participants": None,
|
||||
"copies": None,
|
||||
"prize_value_yuan": None,
|
||||
"updated_ts": None,
|
||||
}
|
||||
self._events = []
|
||||
self._wins = []
|
||||
|
||||
def _reader():
|
||||
assert self._proc is not None
|
||||
out = self._proc.stdout
|
||||
if out is None:
|
||||
return
|
||||
for line in out:
|
||||
cleaned_line = line.rstrip("\n")
|
||||
self._on_line(cleaned_line)
|
||||
try:
|
||||
self._update_stats_from_line(cleaned_line)
|
||||
except Exception:
|
||||
pass
|
||||
rc = self._proc.wait()
|
||||
with self._lock:
|
||||
self._exit_code = rc
|
||||
self._on_line(f"[进程结束] exit_code={rc}")
|
||||
|
||||
self._reader_thread = threading.Thread(target=_reader, daemon=True)
|
||||
self._reader_thread.start()
|
||||
# (已移除) 测试评论启动器
|
||||
|
||||
def send_back_key(self, device_id: str) -> bool:
|
||||
"""手动发送返回键到指定设备。
|
||||
@@ -1153,7 +990,11 @@ class Runner:
|
||||
# 类 Unix:尝试向进程组发送 SIGKILL
|
||||
import signal
|
||||
|
||||
os.kill(pid, signal.SIGKILL)
|
||||
try:
|
||||
os.kill(pid, signal.SIGKILL)
|
||||
except AttributeError:
|
||||
# 如果SIGKILL不存在,使用SIGTERM
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@@ -17,3 +17,25 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,3 +25,25 @@ __all__ = ["ProcRunner"]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+16
-37
@@ -825,12 +825,13 @@ class ProcRunner:
|
||||
|
||||
def get_reservations(self) -> dict:
|
||||
"""获取当前预约队列信息(来自子进程写入的 douyin/core/state/reservations.json)。"""
|
||||
try:
|
||||
import path_config
|
||||
path = path_config.get_reservations_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
path = path_config.get_reservations_path()
|
||||
if hasattr(path_config, "get_reservations_path"):
|
||||
try:
|
||||
path = path_config.get_reservations_path()
|
||||
except Exception:
|
||||
path = os.path.join(path_config.PROJECT_ROOT if hasattr(path_config, "PROJECT_ROOT") else os.getcwd(), "douyin", "state", "reservations.json")
|
||||
else:
|
||||
path = os.path.join(os.getcwd(), "douyin", "state", "reservations.json")
|
||||
try:
|
||||
if os.path.exists(path):
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
@@ -1577,13 +1578,14 @@ class Handler(BaseHTTPRequestHandler):
|
||||
n = int((qs.get("lines") or [200])[0])
|
||||
except Exception:
|
||||
n = 200
|
||||
# 使用统一的路径配置
|
||||
try:
|
||||
import path_config
|
||||
path = path_config.get_actions_log_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
path = path_config.get_actions_log_path()
|
||||
# 使用统一的路径配置(优先使用 path_config 中的配置,失败时回退到项目内置路径)
|
||||
if hasattr(path_config, "get_actions_log_path"):
|
||||
try:
|
||||
path = path_config.get_actions_log_path()
|
||||
except Exception:
|
||||
path = os.path.join(path_config.PROJECT_ROOT if hasattr(path_config, "PROJECT_ROOT") else os.getcwd(), "logs", "actions.log")
|
||||
else:
|
||||
path = os.path.join(os.getcwd(), "logs", "actions.log")
|
||||
out_lines: list[str] = []
|
||||
try:
|
||||
if os.path.exists(path):
|
||||
@@ -1779,29 +1781,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
return self._send_json({"ok": False, "error": str(e)}, status=500)
|
||||
return self._send_json({"ok": True})
|
||||
|
||||
if u.path == "/api/test-yanghao":
|
||||
if RUNNER.is_running():
|
||||
return self._send_json({"ok": False, "error": "running"}, status=409)
|
||||
body = self._read_json()
|
||||
device_id = str(body.get("device_id") or "").strip()
|
||||
seconds = int(body.get("seconds") or 60)
|
||||
try:
|
||||
RUNNER.start_test_yanghao(device_id, seconds)
|
||||
except Exception as e:
|
||||
return self._send_json({"ok": False, "error": str(e)}, status=500)
|
||||
return self._send_json({"ok": True})
|
||||
|
||||
if u.path == "/api/test-comment":
|
||||
if RUNNER.is_running():
|
||||
return self._send_json({"ok": False, "error": "running"}, status=409)
|
||||
body = self._read_json()
|
||||
device_id = str(body.get("device_id") or "").strip()
|
||||
text = str(body.get("text") or "").strip()
|
||||
try:
|
||||
RUNNER.start_test_comment(device_id, text)
|
||||
except Exception as e:
|
||||
return self._send_json({"ok": False, "error": str(e)}, status=500)
|
||||
return self._send_json({"ok": True})
|
||||
# (已移除) /api/test-yanghao 与 /api/test-comment 接口已删除
|
||||
|
||||
if u.path == "/api/stop":
|
||||
RUNNER.stop()
|
||||
@@ -1854,7 +1834,6 @@ def main() -> int:
|
||||
raise
|
||||
print(f"Web GUI: http://{host}:{port}")
|
||||
print("- 可在页面里设置养号时长/间隔并保存到 config.json")
|
||||
print("- 可一键运行‘测试养号流程’,日志会在页面里滚动显示")
|
||||
try:
|
||||
httpd.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
|
||||
Reference in new issue
Block a user