#!/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("完成!")