From c802f62796afb187d7f92bd52c4601354b17732f Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 21 May 2026 13:32:35 +0800 Subject: [PATCH] =?UTF-8?q?docs/=E5=AE=8C=E6=95=B4=E6=8A=80=E6=9C=AF?= =?UTF-8?q?=E6=96=87=E6=A1=A3:=20=E6=89=B9=E9=87=8F=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E5=8F=99=E8=BF=B0=E6=80=A7=E6=97=A7=E8=B7=AF=E5=BE=84=E4=B8=BA?= =?UTF-8?q?=E6=96=B0=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 把全文(除头部"路径迁移说明"对照表外)所有反引号包裹的旧路径标识符 更新为重构后位置: - \`Underlying_Operations.py\` → \`douyin/core/underlying_operations.py\` (23 处) - \`path_config.py\` → \`douyin/core/path_config.py\` (7 处) - \`run_cli.py\` → \`bin/run_cli.py\` (15 处) - \`unified_logger.py\` → \`douyin/logging/unified_logger.py\` (1 处) - \`Underlying_Operations.()\` → \`underlying_operations.()\` (6 处) 头部 "⚠️ 路径迁移说明" 对照表内的旧路径作为示例保留。 Co-Authored-By: Claude Opus 4.7 --- docs/完整技术文档.md | 90 ++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/docs/完整技术文档.md b/docs/完整技术文档.md index 7b41316..167900e 100644 --- a/docs/完整技术文档.md +++ b/docs/完整技术文档.md @@ -236,7 +236,7 @@ else: - `douyin/fudai/core/fudai_detail_orchestrator.py`(旧位置:`fudai_detail_modules/fudai_detail_reader.py`):默认任务计数为 0,增强警告日志输出。 - 日志时间戳统一: - `douyin/logging/douyin_logging.py`:新增 MillisecondFormatter 类。 - - `unified_logger.py`:为 UnifiedFormatter 添加 formatTime 方法。 + - `douyin/logging/unified_logger.py`:为 UnifiedFormatter 添加 formatTime 方法。 - `douyin/logging/action_logger.py`:更新为使用 MillisecondFormatter。 - 截图复用优化: - 确保在福袋详情页关闭前复用截图,避免不必要的重复截图。 @@ -307,13 +307,13 @@ python run_cli.py --device-id --wait-minutes 0 1. 代码内默认值(常量/类属性) 2. `config/config.json`(通过 `path_config.get_config_path()` 获取) 3. 环境变量(例如 `SKIP_OCR_INIT`, `DISABLE_SCREENSHOT_MIRROR`) -4. 命令行参数(`run_cli.py` 解析,优先级最高,运行时覆盖实例属性) +4. 命令行参数(`bin/run_cli.py` 解析,优先级最高,运行时覆盖实例属性) 示例:通过命令行临时指定设备优先于 `config/config.json` 中的默认设备。 实现建议与样例: -- 在 `douyin/utils/douyin_config.py` 中实现 `load_config_from_file(path)` 返回 dict,主流程使用该 dict 初始化分析器并在 `run_cli.py` 中用命令行覆盖字段。 +- 在 `douyin/utils/douyin_config.py` 中实现 `load_config_from_file(path)` 返回 dict,主流程使用该 dict 初始化分析器并在 `bin/run_cli.py` 中用命令行覆盖字段。 - 推荐在 `config/config.json` 中采用明确分组,例如: ```json @@ -324,7 +324,7 @@ python run_cli.py --device-id --wait-minutes 0 } ``` -- 命令行覆盖示例(`run_cli.py` 中解析后合并): +- 命令行覆盖示例(`bin/run_cli.py` 中解析后合并): ```python # pseudo @@ -337,7 +337,7 @@ if args.device_id: - 使用代码内默认值并在日志中写 warning; - 在关键字段(如 `device`、`ocr_engine`)缺失时中断并提示用户。 -关联文件:`config/config.json`,`douyin/utils/douyin_config.py`,`path_config.py`,`run_cli.py`。 +关联文件:`config/config.json`,`douyin/utils/douyin_config.py`,`douyin/core/path_config.py`,`bin/run_cli.py`。 ## 截图 / OCR / 日志 / 状态(实现细节与故障采样) @@ -345,12 +345,12 @@ if args.device_id: - 优先方式:`adb exec-out screencap -p`(单次 adb 调用,速度最快)。 - 回退方式:`adb shell screencap -p /sdcard/screen.png` + `adb pull`(兼容性但更慢)。 -- 写入策略:先写入临时文件(例如 `screenshot.png.tmp`),再通过原子替换或安全复制覆盖 `pic/screenshot.png`,以避免并发读取到半写入文件。见 `Underlying_Operations.get_screenshot()` 的实现。 +- 写入策略:先写入临时文件(例如 `screenshot.png.tmp`),再通过原子替换或安全复制覆盖 `pic/screenshot.png`,以避免并发读取到半写入文件。见 `underlying_operations.get_screenshot()` 的实现。 - Windows 文件锁与镜像:`_safe_replace_file()` 包含多重回退(`os.replace` → `shutil.copy2` → 分块复制),并可通过环境变量 `DISABLE_SCREENSHOT_MIRROR=1` 禁用将截图镜像到外部目录(`EXTERNAL_DOUYIN_FUDAI_DIR`)。 2) OCR(策略与初始化) -- 优先引擎:EasyOCR(速度与准确性通常最佳);回退:PaddleOCR。实现位于 `Underlying_Operations.analyse_pic_word()`。 +- 优先引擎:EasyOCR(速度与准确性通常最佳);回退:PaddleOCR。实现位于 `underlying_operations.analyse_pic_word()`。 - 延迟初始化:支持 `SKIP_OCR_INIT=1`(跳过启动时初始化),首次调用时会在 `_ensure_ocr()` 进行按需初始化。 - 回退与容错:若 OCR 未能初始化或识别失败,函数返回空字符串,上层代码需对空结果做容错与重试。建议生产环境安装 `easyocr` 并允许启动时初始化以减少首次延迟。 @@ -438,7 +438,7 @@ powershell -Command "Get-Content tools/coords_report.csv -TotalCount 200 | Out-F python -m py_compile $(git ls-files "**/*.py") ``` -- 关键文件存在性检查:确保 `run_cli.py`、`Underlying_Operations.py`、`config/config.json`、`path_config.py` 存在并可被导入。 +- 关键文件存在性检查:确保 `bin/run_cli.py`、`douyin/core/underlying_operations.py`、`config/config.json`、`douyin/core/path_config.py` 存在并可被导入。 示例 CI 脚本片段: @@ -459,9 +459,9 @@ PY - 项目意图(一句话):自动化在抖音直播中查找并参与“福袋”活动的流程化机器人,包含截图、像素/模板检测、OCR、决策与预约管理。 - 关键入口(按优先级): - - `run_cli.py`:CLI 入口,生成 `fudai_analyse` 实例并开始主循环;适合触发最小可运行示例。 + - `bin/run_cli.py`:CLI 入口,生成 `fudai_analyse` 实例并开始主循环;适合触发最小可运行示例。 - `douyin/core/douyin_fudai.py::fudai_choujiang()`:主循环调度;查看运行状态与错误堆栈。 - - `Underlying_Operations.py`:底层设备接口(截图、裁剪、OCR)— 对外数据采集点。 + - `douyin/core/underlying_operations.py`:底层设备接口(截图、裁剪、OCR)— 对外数据采集点。 - 可调用的“程序式”API(Python)示例: @@ -475,7 +475,7 @@ text = op.analyse_pic_word(img) ``` - 关键文件与含义速查表(便于 LLM 快速定位实现细节): - - `path_config.py`:统一路径(logs/pic/state)——用于定位运行数据。 + - `douyin/core/path_config.py`:统一路径(logs/pic/state)——用于定位运行数据。 - `douyin/logging/douyin_logging_wrapper.py`:业务日志封装——搜索 `traceId` 与 `stage`。 - 可观测数据(建议供 AI 检索): @@ -505,18 +505,18 @@ text = op.analyse_pic_word(img) 6) 参考实现与文件链接 -- 截图与裁剪:`Underlying_Operations.get_screenshot()`、`Underlying_Operations.cut_pic()`。 -- OCR:`Underlying_Operations.analyse_pic_word()`、`Underlying_Operations.analyse_pic_digits()`。 +- 截图与裁剪:`underlying_operations.get_screenshot()`、`underlying_operations.cut_pic()`。 +- OCR:`underlying_operations.analyse_pic_word()`、`underlying_operations.analyse_pic_digits()`。 - 日志:`douyin/logging/douyin_logging.py`、`douyin/logging/douyin_logging_wrapper.py`。 -- 路径与状态:`path_config.py`、`state/reservations.json`。 +- 路径与状态:`douyin/core/path_config.py`、`state/reservations.json`。 以上补充将帮助运维快速定位截图/OCR/日志相关问题并提供明确采样路径供后续模型/规则优化使用。 ## 核心模块地图(快捷索引) -- `run_cli.py`:入口,解析命令行并创建 `fudai_analyse`。 +- `bin/run_cli.py`:入口,解析命令行并创建 `fudai_analyse`。 - `douyin/core/douyin_fudai.py`:主分析器/主循环(`fudai_choujiang`、`run_once_basic`)。 -- `Underlying_Operations.py`:底层设备/截图/OCR/文件操作。 +- `douyin/core/underlying_operations.py`:底层设备/截图/OCR/文件操作。 - `douyin/detection/douyin_pixel.py`:像素检测与并行检测实现。 - `douyin/fudai/douyin_fudai_core.py`:福袋核心逻辑。 @@ -546,7 +546,7 @@ text = op.analyse_pic_word(img) - `douyin/stage/douyin_stage.py`:阶段诊断入口(`diagnose_stage_from_current_screen`)。 - `douyin/reservation/douyin_reservation_logic.py`:预约加载与回退处理。 -- `path_config.py`:统一路径获取,避免硬编码。 +- `douyin/core/path_config.py`:统一路径获取,避免硬编码。 在文档中引用这些文件并包含小示例会帮助维护者快速定位实现点。 @@ -592,7 +592,7 @@ text = op.analyse_pic_word(img) ## 运行流程概览(精简) -1. `run_cli.py` -> 创建 `fudai_analyse` -> `load_config()` -> `fudai_choujiang()` +1. `bin/run_cli.py` -> 创建 `fudai_analyse` -> `load_config()` -> `fudai_choujiang()` 2. `fudai_choujiang()` 循环调用 `run_once_basic()` 3. `run_once_basic()` 流程要点: - 处理等待开奖 / 预约回退 @@ -639,7 +639,7 @@ python run_cli.py --device-id --wait-minutes 1 ## 验证清单(可纳入 CI) 1. `python -m py_compile` 全仓库通过。 -2. 关键路径存在检查:`run_cli.py`、`Underlying_Operations.py`、`config/config.json`、`path_config.py`。 +2. 关键路径存在检查:`bin/run_cli.py`、`douyin/core/underlying_operations.py`、`config/config.json`、`douyin/core/path_config.py`。 3. `path_config.get_reservations_path()` 返回文件夹存在性检查。 示例 CI 命令片段: @@ -960,7 +960,7 @@ _handle_in_fudai_detail() #### `run_cli.py::main(argv: list[str]) -> int` -- **文件位置**: `run_cli.py` +- **文件位置**: `bin/run_cli.py` - **作用**: 命令行入口函数,解析参数并启动主程序 - **参数**: - `argv`: 命令行参数列表 @@ -2269,19 +2269,19 @@ is_match, reason, debug = match_reservation(item, detail) ## 5. 底层操作函数 -底层操作函数封装在 `Underlying_Operations.py` 的 `underlying_operations` 类中,提供设备控制、截图、OCR、图像处理等基础功能。 +底层操作函数封装在 `douyin/core/underlying_operations.py` 的 `underlying_operations` 类中,提供设备控制、截图、OCR、图像处理等基础功能。 ### 5.1 设备操作函数 #### `underlying_operations.select_device() -> str | bool` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 选择需要连接的Android设备 - **参数**: 无 - **返回值**: - `str`: 设备ID(单设备或多设备选择后) - `False`: 无设备连接 -- **调用位置**: `run_cli.py` 的 `main()` 函数中调用 +- **调用位置**: `bin/run_cli.py` 的 `main()` 函数中调用 - **实现细节**: - 执行 `adb devices` 命令获取设备列表 - 使用正则表达式提取设备ID(支持IP地址和序列号) @@ -2300,7 +2300,7 @@ if not device_id: #### `underlying_operations.get_device_resolution(device_id: str) -> Tuple[int, int]` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 获取Android设备的分辨率 - **参数**: - `device_id: str`: 设备ID @@ -2320,7 +2320,7 @@ analyser.resolution_ratio_y = height #### `underlying_operations.click(device_id: str, x: int, y: int) -> None` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 在设备屏幕上点击指定坐标 - **参数**: - `device_id: str`: 设备ID @@ -2339,7 +2339,7 @@ operation.click(device_id, 540, 1200) # 点击屏幕中心 #### `underlying_operations.click_back(device_id: str) -> None` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 点击Android返回键(KEYCODE_BACK) - **参数**: - `device_id: str`: 设备ID @@ -2350,7 +2350,7 @@ operation.click(device_id, 540, 1200) # 点击屏幕中心 #### `underlying_operations.click_confirm(device_id: str) -> None` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 点击确认键(KEYCODE_ENTER) - **参数**: - `device_id: str`: 设备ID @@ -2363,7 +2363,7 @@ operation.click(device_id, 540, 1200) # 点击屏幕中心 #### `underlying_operations.get_screenshot(device_id: str, path: str = "pic") -> bool` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 获取设备屏幕截图并保存到本地 - **参数**: - `device_id: str`: 设备ID @@ -2399,7 +2399,7 @@ else: #### `underlying_operations.save_reward_pic(device_id: str) -> None` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 保存中奖截图(带时间戳) - **参数**: - `device_id: str`: 设备ID @@ -2414,7 +2414,7 @@ else: #### `underlying_operations.cut_pic(left_up: Tuple[int, int] = (0, 63), right_down: Tuple[int, int] = (1080, 1620), target: str = "", name: str = "") -> bool` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 裁剪图片,获取指定区域的子图片(用于OCR识别) - **参数**: - `left_up: Tuple[int, int]`: 左上角坐标(默认(0, 63)) @@ -2451,7 +2451,7 @@ else: #### `underlying_operations.analyse_pic_word(picname: str, change_color: int = 0, pic_path: Optional[str] = None) -> str` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 对指定图片运行OCR识别,返回拼接后的文本结果 - **参数**: - `picname: str`: 图片名称(不含扩展名,如"福袋内容") @@ -2494,7 +2494,7 @@ else: #### `underlying_operations.analyse_pic_digits(picname: str, change_color: int = 1, pic_path: Optional[str] = None) -> str` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 对指定图片运行OCR识别,专门用于识别数字(倒计时、价值、参与人数等) - **参数**: - `picname: str`: 图片名称(不含扩展名,如"倒计时") @@ -2515,7 +2515,7 @@ countdown_text = operation.analyse_pic_digits("倒计时") #### `underlying_operations.extract_ocr_content(content: List, return_confidence: bool = False) -> str | Tuple[str, float]` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 从OCR结果中提取文本内容(去除坐标、置信度等信息) - **参数**: - `content: List`: OCR原始结果(EasyOCR或PaddleOCR格式) @@ -2534,7 +2534,7 @@ countdown_text = operation.analyse_pic_digits("倒计时") #### `underlying_operations.swipe(device_id: str, x1: int, y1: int, x2: int, y2: int, duration_ms: int = 600) -> None` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 在设备屏幕上执行滑动操作(从起点滑动到终点) - **参数**: - `device_id: str`: 设备ID @@ -2562,7 +2562,7 @@ operation.swipe(device_id, 540, 1800, 540, 800, duration_ms=600) #### `underlying_operations.delay(seconds: float = 1.0) -> None` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 延迟指定秒数 - **参数**: - `seconds: float`: 延迟秒数(默认1.0秒) @@ -2571,7 +2571,7 @@ operation.swipe(device_id, 540, 1800, 540, 800, duration_ms=600) #### `underlying_operations.random_delay(min_seconds: float = 1.0, max_seconds: float = 100.0) -> None` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 随机延迟指定范围内的秒数(模拟人工操作) - **参数**: - `min_seconds: float`: 最小延迟秒数(默认1.0秒) @@ -2581,7 +2581,7 @@ operation.swipe(device_id, 540, 1800, 540, 800, duration_ms=600) #### `underlying_operations.check_countdown(last_time: str = "") -> Optional[int]` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 检查倒计时文本,转换为剩余秒数 - **参数**: - `last_time: str`: 倒计时文本(格式:`mm:ss` 或 `m:ss` 或 `ss`) @@ -2601,7 +2601,7 @@ remaining_seconds = operation.check_countdown(countdown_text) #### `underlying_operations.get_current_hour() -> int` -- **文件位置**: `Underlying_Operations.py` +- **文件位置**: `douyin/core/underlying_operations.py` - **作用**: 获取当前时间的小时数(0-23) - **参数**: 无 - **返回值**: `int` - 当前小时数(0-23) @@ -2935,7 +2935,7 @@ class fudai_analyse( - `needswitch: bool` - 是否允许切换直播间 - `wait_minutes: int` - 每次循环等待时间(分钟) - **实现**: 设置设备ID和配置,然后循环调用 `run_once_basic()` - - **调用位置**: `run_cli.py` 的 `main()` 函数中调用 + - **调用位置**: `bin/run_cli.py` 的 `main()` 函数中调用 #### 6.2.7 BaseFudaiMixin(基础混入类) @@ -3049,7 +3049,7 @@ UNKNOWN = "UNKNOWN" # 未知阶段 配置文件位于 `config/config.json`,路径通过 `path_config.get_config_path()` 获取。 -### 7.1.1 `path_config.py` 用法 +### 7.1.1 `douyin/core/path_config.py` 用法 - 使用 `path_config.get_config_path()` 获取配置文件的绝对路径; - 常用路径获取函数: @@ -3066,9 +3066,9 @@ UNKNOWN = "UNKNOWN" # 未知阶段 1. 代码中内置的默认值(类属性或常量); 2. `config/config.json`(通过 `path_config.get_config_path()` 指定的文件); 3. 环境变量(仅少数开关被代码显式读取,如 `SKIP_OCR_INIT`, `EXTERNAL_DOUYIN_FUDAI_DIR`, `DISABLE_MODEL_SOURCE_CHECK`, `DISABLE_SCREENSHOT_MIRROR` 等); -4. 命令行参数(`run_cli.py` 中解析的参数,会在创建 `fudai_analyse` 实例后覆盖运行时属性——命令行优先级最高)。 +4. 命令行参数(`bin/run_cli.py` 中解析的参数,会在创建 `fudai_analyse` 实例后覆盖运行时属性——命令行优先级最高)。 -说明:实际运行时 `fudai_analyse.__init__()` 会加载 `config.json`(若存在),随后 `run_cli.py` 会将命令行参数按需覆盖分析器属性;因此临时调试请优先使用命令行参数,长期配置请写入 `config/config.json`。 +说明:实际运行时 `fudai_analyse.__init__()` 会加载 `config.json`(若存在),随后 `bin/run_cli.py` 会将命令行参数按需覆盖分析器属性;因此临时调试请优先使用命令行参数,长期配置请写入 `config/config.json`。 ### 7.2 配置项详解 @@ -4692,7 +4692,7 @@ self.new_config_item = self.config.get("new_config_item", False) #### 15.1.1 入口文件 -- **`run_cli.py`**: 命令行入口,初始化设备和分析器 +- **`bin/run_cli.py`**: 命令行入口,初始化设备和分析器 - **`gui/gui_app.py`**: Tkinter GUI入口 - **`gui/web_gui.py`**: Web GUI入口 @@ -4725,7 +4725,7 @@ self.new_config_item = self.config.get("new_config_item", False) #### 15.1.7 底层操作 -- **`Underlying_Operations.py`**: 底层操作类(ADB、OCR、图像处理) +- **`douyin/core/underlying_operations.py`**: 底层操作类(ADB、OCR、图像处理) #### 15.1.8 配置文件 @@ -7216,7 +7216,7 @@ result = analyser.operation.analyse_pic_word(preprocessed_name, 0) #### 24.2.2 OCR识别优化 -**文件位置**: `Underlying_Operations.py` +**文件位置**: `douyin/core/underlying_operations.py` **优化措施**: