Files
windows-fenjian/tools/_bench_focus_scroll.py

93 lines
2.9 KiB
Python
Raw Permalink 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.
# -*- coding: utf-8 -*-
"""基准:现场实际状态下的拖动耗时(识别前 / 识别后确认条弹出)
复现现场配置:1440x900 窗口、待办 4 列、66 行、不分组,
并且「识别后」= 确认条可见 + 当前行高亮 + 候选卡存在。
用法:python tools/_bench_focus_scroll.py [行数]
"""
import os
import sys
import time
import json
sys.path.insert(0, os.getcwd())
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.getcwd())
import tkinter as tk
import ui.app as A
N = int(sys.argv[1]) if len(sys.argv) > 1 else 66
cfg = json.load(open('config.json', encoding='utf-8'))
cfg.setdefault('server', {})['mock'] = True
cfg.setdefault('scale', {})['simulate'] = True
cfg.setdefault('camera', {})['simulate'] = True
cfg.setdefault('ui', {})['mode'] = 'window'
cfg['flow'] = cfg.get('flow', {})
cfg['flow']['confirm_before_submit'] = True
cfg.setdefault('ui', {})['todo_group'] = 'none'
cfg['ui']['todo_cols'] = 4
cfg['ui']['todo_thumb'] = False
A.load_config = lambda: cfg
root = tk.Tk()
root.geometry('1440x900')
app = A.App(root)
app._build()
app.ready = True
root.update()
rows = [{'id': 'r%d' % i, 'item_name': '商品名称示例%d' % i, 'spec': '500g',
'unit': '斤', 'required_qty': 3.0 + i % 5,
'customer_name': '客户%d' % (i % 5), 'sku_code': 'S%d' % i}
for i in range(N)]
app._fill_todo(rows)
for _ in range(60):
root.update()
time.sleep(0.01)
def drag(tag, runs=3, frames=60):
best = 9e9
for _ in range(runs):
app.todo_canvas.yview_moveto(0.0)
root.update()
t = time.perf_counter()
for i in range(frames):
app.todo_canvas.yview_moveto((i / float(frames)) * 0.5)
root.update_idletasks()
best = min(best, (time.perf_counter() - t) * 1000.0 / frames)
scroll = app.todo_canvas.bbox('all')
print('%s|%d 行|控件总数 %4d|scrollregion %s|拖动 %5.2f ms/帧'
% (tag, len(app.todo_cards),
sum(1 + len(c.winfo_children())
for c in app.todo_cards.values()),
scroll, best))
return best
drag('① 识别前(待机)')
# 模拟识别完成:确认条第 30 行
p = {'row_id': 'r30', 'row': rows[30], 'detected': '商品名称示例30',
'conf': 92, 'mode': 'weigh', 'weight': 1.6, 'business': 3.2,
'unit': '斤', 'warn': '', 'candidates': [rows[30], rows[31]]}
for _ in range(6):
app._on_focus(p)
for _ in range(30):
root.update()
time.sleep(0.01)
drag('② 识别后(确认条+高亮)')
# 再叠加:确认条开着时刷新待办(模拟后台到货刷新)
t = time.perf_counter()
app._fill_todo([dict(r) for r in rows])
print('③ 确认条开着时刷新待办:%.0f ms' % ((time.perf_counter() - t) * 1000))
for _ in range(30):
root.update()
time.sleep(0.01)
drag('④ 刷新后再拖')
root.destroy()