_tmp_ab_check.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. """A/B 对比: 稳定版(VisionParser1) vs 交叉版(VisionParserCross) 同图实测
  3. 检查: 输出差异 / 耗时 / page_wrong一致性 / 调用次数(按日志行数)"""
  4. import sys
  5. import time
  6. from pathlib import Path
  7. ROOT = Path(__file__).parent
  8. sys.path.insert(0, str(ROOT))
  9. from ai_helper_vision1 import VisionParser1
  10. from ai_helper_vision_cross import VisionParserCross
  11. from PIL import Image
  12. IMAGES = [
  13. (r"screenshots\OV7T8PV8GEHYSCNB\step3\step3_b0.png", "甲巯咪唑片"),
  14. (r"screenshots\OV7T8PV8GEHYSCNB\step3\step3_b1.png", "甲巯咪唑片"),
  15. (r"screenshots\OV7T8PV8GEHYSCNB\step3\step3_b2.png", "甲巯咪唑片"),
  16. (r"screenshots\T4VK4LM7AAUOV8AY\step3\step3_b0.png", "甲巯咪唑片"),
  17. ]
  18. CROSS = VisionParserCross()
  19. STABLE = VisionParser1()
  20. def run(parser, img, kw, w, h):
  21. t0 = time.time()
  22. shops, status = parser.parse_shops(img, screen_size=(w, h), keyword=kw, crop_x=287)
  23. dt = time.time() - t0
  24. return shops, status, dt
  25. def sig(shops):
  26. return sorted((s[0], str(price_num := __import__("re").search(r"[\d.]+", s[2]).group(0)), s[1][:18])
  27. for s in shops)
  28. for rel, kw in IMAGES:
  29. img = str(ROOT / rel)
  30. w, h = Image.open(img).size
  31. print("=" * 78)
  32. print(f"{rel.split(chr(92))[-2]}_b{Path(img).stem[-1]} ({w}x{h})")
  33. s_shops, s_status, s_dt = run(STABLE, img, kw, w, h)
  34. print(f" [稳定] {s_status} {len(s_shops)}卡 {s_dt:.0f}s")
  35. for s in s_shops:
  36. print(f" {s[0][:14]} | {s[2]} | {s[1][:26]}")
  37. c_shops, c_status, c_dt = run(CROSS, img, kw, w, h)
  38. print(f" [交叉] {c_status} {len(c_shops)}卡 {c_dt:.0f}s")
  39. for s in c_shops:
  40. print(f" {s[0][:14]} | {s[2]} | {s[1][:26]}")
  41. same = (s_status == c_status) and (sig(s_shops) == sig(c_shops))
  42. print(f" → {'两版结果一致' if same else '★ 两版结果不同(上面对比)'} 耗时比 {c_dt/s_dt:.1f}x")