autotrain/scripts/auto_calibrate_from_recording.py
xinxin6623 65d2719afb H5 视觉兜底优化 + scrcpy 非阻塞启动 + 自动校准/重连脚本
- wait_for_page_transition: XML 持续返回 other 超过 quick_timeout 后自动启用视觉兜底
- _xml_or_vision_click: 优先视觉 API 找按钮(H5 WebView XML 不可见)
- 自动处理媒体访问权限弹窗
- scrcpy 改为非阻塞 Popen 启动,绑定当前设备 serial 避免多设备冲突
- 新增 auto_calibrate_from_recording.py / reconnect-phone.sh
- postJson 前端异常捕获
2026-07-24 09:46:32 +08:00

74 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""从录制快照自动灌入校准样图并分析。"""
import shutil, sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[0]))
import calibrate, device_runtime
RECORDING = Path("work/replay/20260712-214511_manual")
CALIB = calibrate.CALIBRATION_DIR
# 录制 page_hint → 校准 step_id 映射,取每个页面第一次出现的最完整截图
MAPPING = {
"album_qr": "album_qr",
"list": "list_page",
"invoice_info": "invoice_info",
"invoice_confirm": "invoice_confirm",
"success": "success_page",
}
# 按录制时间线顺序每个页面类型取第一个UI 最稳定)
seen = set()
copied = []
missing = []
for snap in sorted(RECORDING.glob("*_*"), key=lambda p: p.name):
if not snap.is_dir():
continue
meta_file = snap / "meta.json"
if not meta_file.exists():
continue
import json
meta = json.loads(meta_file.read_text())
hint = meta.get("page_hint", "other")
step_id = MAPPING.get(hint)
if not step_id or step_id in seen:
continue
seen.add(step_id)
screen = snap / "screen.png"
if not screen.exists():
print(f"WARN: {snap.name} 没有 screen.png跳过")
continue
dest = CALIB / f"{step_id}.png"
CALIB.mkdir(parents=True, exist_ok=True)
shutil.copy2(screen, dest)
copied.append(step_id)
print(f" {step_id}{snap.name}")
for step in calibrate.CALIBRATION_STEPS:
if step["id"] not in seen:
missing.append(step["id"])
print(f"\n复制了 {len(copied)} 张样图: {copied}")
if missing:
print(f"缺失: {missing}(可在真机运行时补录)")
# 分析所有已有样图
print("\n分析中...")
results = calibrate.analyze_all()
for sid, r in results.items():
if r.get("skipped"):
print(f" {sid}: 无截图,跳过")
elif r.get("error"):
print(f" {sid}: 错误 - {r['error']}")
else:
page_ok = "" if r.get("page_ok") else "⚠️"
buttons = r.get("buttons", {})
btn_status = ", ".join(f"{k}:{'' if v.get('found') else ''}" for k, v in buttons.items())
print(f" {sid}: {page_ok} page={r.get('page_detected', '?')} | buttons: {btn_status}")
# 保存设备配置
print("\n保存设备配置...")
profile = calibrate.save_device_profile(results)
print(f"状态: {profile.get('status', '?')}")
print("完成!")