Files

163 lines
6.2 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 -*-
"""v1.0.56 诊断:手动选择五条路径的「记账量 vs 标签量」
现场反馈「手动选择的时候没有按照称的重量打印标签」。称重/免称重、
AI 认出/认不出、点确认/点行改判,组合起来有五条路,逐条量:
· 记账量(提交给服务端的 business)
· 标签量(_print_q 里算出来的 _label_qty)
秤上真实读数固定 2.81 kg(= 5.62 斤),行应量 5.00 斤 —— 两个数不一样
才能看出打的是哪一份。
"""
import io
import os
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from core.matching import engine as M # noqa: E402
from core.flow import FlowEngine # noqa: E402
CFG = {
'flow': {'min_scale_kg': 0.05, 'stable_ms': 400, 'settle_ms': 650,
'stable_delta_kg': 0.03, 'done_timeout_s': 12,
'done_lift_off_kg': 0.2, 'confirm_before_submit': True,
'auto_submit': True, 'same_name_auto': True,
'merge_same_name': True, 'over_receipt_ratio': 3,
'weight_pick_pct': 40},
'scale': {'simulate': True},
'camera': {'simulate': True},
'vision': {'min_confidence': 60, 'auto_over_pct': 30,
'same_kind_guard': False},
'server': {'mock': True},
'printer': {'enabled': True, 'printer_name': '测试机'},
'noweigh': {'picking_allow_weight_unit': True},
}
REAL_KG = 2.81 # 秤上实际
REAL_JIN = 5.62 # 折算
def new_eng():
ev = []
e = FlowEngine(CFG, lambda k, p=None: ev.append((k, p)))
e.refresh_pending = lambda initial=False: None
e.station = 'picking'
e.logged_in = True
e._running = True
e.server_config = {'weigh_match_tolerance_mode': 'percent',
'weigh_match_tolerance_value': 0}
e._print_enabled = lambda: True
e.rows = [{'id': 'ROW1', 'item_name': '香菇', 'unit': '斤',
'required_qty': 5.0, 'remaining_qty': 5.0,
'order_code': 'ORD1', 'container_code': 'CT-DIAG'}]
# 秤在说话(present+fresh)
e._last_st = {'present': True, 'fresh': True, 'weight': REAL_KG}
return e
def label_of(e, row, business):
"""模拟 _after_success 的打印:business 是记账量,kg 走 _label_kg()"""
e._print_q = __import__('queue').Queue()
e._print_async(row, business)
item = e._print_q.get_nowait()
qty = e._label_qty(row, item['business'], item['kg'], row.get('unit'))
return item['kg'], qty
def show(tag, e, row, business):
kg, qty = label_of(e, row, business)
flag = 'OK ' if abs(qty - REAL_JIN) < 0.02 else 'XX '
print('%s%-34s 记账 %5.2f 斤 | kg %5.2f → 标签 %5.2f 斤'
% (flag, tag, float(business or 0), float(kg or 0), float(qty)))
ROW = None
# ---------------------------------------------------------------- (a) 称重 → AI 认出
e = new_eng()
ROW = e.rows[0]
e._count_mode = False
e._frozen_kg = REAL_KG
e._cycle_conf = 90
e.confirm_before_submit = lambda: True
e.submit_on_remove = lambda: False
e._to_focus(ROW, M.scale_kg_to_business(REAL_KG, '斤'), detected='香菇',
conf=90, mode='weigh', candidates=[ROW], auto=True)
e.state = 'CONFIRM'
e._printed_rid = None # 先看确认时到底提交多少
e.confirm_focus(None)
show('(a) 称重·AI认出→点确认', e, ROW, e._frozen_kg and
M.scale_kg_to_business(e._frozen_kg, '斤'))
# ---------------------------------------------------------------- (b) 称重 → 认不出 → 弹窗点行
e = new_eng()
ROW = e.rows[0]
e._count_mode = False
e._frozen_kg = REAL_KG
e.state = 'MANUAL'
e.api = type('X', (), {'user_id': '', 'base_url': ''})()
e.journal = type('J', (), {'has_unresolved': lambda s: False,
'begin': lambda s, *a, **k: None})()
e._start_submit = lambda row, biz, src: setattr(e, '_caught', (row, biz, src))
e.manual_submit(ROW)
row2, biz, src = e._caught
show('(b) 称重·认不出→弹窗点行', e, row2, biz)
# ---------------------------------------------------------------- (c) 免称重 → AI 认出 → 点确认
e = new_eng()
ROW = e.rows[0]
e._count_mode = True
e._frozen_kg = 0.0
e._cycle_conf = 90
e.confirm_before_submit = lambda: True
e.submit_on_remove = lambda: False
e._to_focus(ROW, float(M.required_qty_of(ROW, None) or 1.0),
detected='香菇', conf=90, mode='count', candidates=[ROW], auto=True)
f_biz = float(e._focus.get('business') or 0)
e.state = 'CONFIRM'
e._start_submit = lambda row, biz, src: setattr(e, '_caught', (row, biz, src))
e.confirm_focus(None)
row2, biz, src = e._caught
show('(c) 免称重·AI认出→点确认', e, row2, biz)
print(' (focus 里给的数量 %.2f 斤)' % f_biz)
# ---------------------------------------------------------------- (d) 免称重 → 认不出 → 手点名单行 → 确认
e = new_eng()
ROW = e.rows[0]
e._count_mode = True
e._frozen_kg = 0.0
# AI 认不出时走 _to_count_confirm(detected=None, row=None) → focus 无行
e.confirm_before_submit = lambda: True
e.submit_on_remove = lambda: False
e._to_focus(None, 0.0, detected=None, conf=None, mode='count',
candidates=[], auto=False)
# 操作员点了名单里那一行
e.state = 'CONFIRM'
e.pick_focus('ROW1')
f_biz = float(e._focus.get('business') or 0)
print(' (点行后 focus 数量 %.2f 斤,_count_real_kg=%.3f)'
% (f_biz, float(getattr(e, '_count_real_kg', 0) or 0)))
e._start_submit = lambda row, biz, src: setattr(e, '_caught', (row, biz, src))
e.confirm_focus(None)
row2, biz, src = e._caught
show('(d) 免称重·认不出→手点行→确认', e, row2, biz)
# ---------------------------------------------------------------- (e) CONFIRM 手动填数量
e = new_eng()
ROW = e.rows[0]
e._count_mode = True
e._frozen_kg = 0.0
e.confirm_before_submit = lambda: True
e.submit_on_remove = lambda: False
e._to_focus(ROW, 5.0, detected='香菇', conf=90, mode='count',
candidates=[ROW], auto=True)
e.state = 'CONFIRM'
e._start_submit = lambda row, biz, src: setattr(e, '_caught', (row, biz, src))
e.confirm_focus(5.0) # 操作员手填 5 斤
row2, biz, src = e._caught
show('(e) 免称重·手填数量 5.00', e, row2, biz)
print('\n秤上真实 = %.2f 斤;行应量 5.00 斤' % REAL_JIN)
print('XX 行 = 标签没按秤印')