202 lines
6.8 KiB
Python
202 lines
6.8 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""v1.0.50 回归:名单缺项要直接说「名单里没有这件货」
|
||
|
||
现场(2026-11-05 19:21):一捆芹菜 13.760 kg(27.52 斤)放上秤,待办名单
|
||
53 行里根本没有「芹菜」(只有「香菜 应 1 斤」)。模型只能在名单里挑最像的,
|
||
答「香菜(把握 90%,次选 小葱)」;同一堆货前后拍了 4 次,3 次答「认不出」。
|
||
旧的提示是「超出应验量 30%,AI 不自动入账,请人工确认」——现场看到的是
|
||
「AI 说这是香菜」,很容易顺手点香菜、记成 1 斤。
|
||
|
||
本文件验证:
|
||
① 实收 ≥ 应量 × over_receipt_ratio(3) → 提示「待办名单里没有这件货」,
|
||
写明倍数与「确实要按它收多少再点」,且不提交
|
||
② 普通超收(1.5 倍、超 30% 以上)→ 仍是原文案,不误报成「名单里没有」
|
||
③ 正好 3 倍(边界)→ 走缺项文案
|
||
④ over_receipt_ratio=0 → 关闭,回到原文案
|
||
⑤ 模型答「认不出」(命中为空)→ 日志点明「不在待办名单里」
|
||
|
||
不需要秤/摄像头/网络。
|
||
"""
|
||
import sys
|
||
import io
|
||
import os
|
||
|
||
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.flow import FlowEngine
|
||
|
||
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},
|
||
'noweigh': {'picking_allow_weight_unit': True},
|
||
}
|
||
|
||
EVENTS = []
|
||
|
||
|
||
def emit(ev, p=None):
|
||
EVENTS.append((ev, p))
|
||
|
||
|
||
eng = FlowEngine(CFG, emit)
|
||
eng.refresh_pending = lambda initial=False: None
|
||
eng.logged_in = True
|
||
eng._running = True
|
||
# 现场口径:服务端下发 weigh_match_tolerance_value = 0(关闭校验),
|
||
# 所以超差一律走到 auto_over_pct 30% 那道闸门 —— 与 19:21 日志一致。
|
||
eng.server_config = {'weigh_match_tolerance_mode': 'percent',
|
||
'weigh_match_tolerance_value': 0}
|
||
|
||
|
||
class FakeJournal:
|
||
def begin(self, *a, **k):
|
||
return {'op': 'op'}
|
||
|
||
def update(self, *a, **k):
|
||
pass
|
||
|
||
def conclude(self, *a, **k):
|
||
pass
|
||
|
||
def has_unresolved(self):
|
||
return False
|
||
|
||
|
||
class FakeRecog:
|
||
def __init__(self, name='香菜', conf=90, alt='小葱', alt_conf=35):
|
||
self.name, self.conf, self.alt = name, conf, alt
|
||
self.alt_conf = alt_conf
|
||
|
||
def identify_ex(self, path, names, timeout=8):
|
||
return {'name': self.name, 'conf': self.conf, 'alt': self.alt,
|
||
'alt_conf': self.alt_conf, 'prompt_tag': 'v1'}
|
||
|
||
|
||
def xiangcai():
|
||
"""现场那行:香菜 应 1 斤"""
|
||
return [{'id': 'x1', 'item_name': '香菜', 'unit': '斤',
|
||
'required_qty': 1.0, 'order_code': 'ORD_1', 'sku_code': 'S900'}]
|
||
|
||
|
||
def reset(rows, kg, ratio=3, recog=None, conf=90):
|
||
CFG['flow']['over_receipt_ratio'] = ratio
|
||
EVENTS.clear()
|
||
eng.rows = [dict(r) for r in rows]
|
||
eng.state = 'IDLE'
|
||
eng._focus = None
|
||
eng._count_mode = False
|
||
eng._count_qty = 0.0
|
||
eng._frozen_kg = kg
|
||
eng._frozen_row = None
|
||
eng._aborted = False
|
||
eng._running = True
|
||
eng._last_ok = None
|
||
eng._plan = []
|
||
eng._pre_pick_rid = None
|
||
eng.journal = FakeJournal()
|
||
eng._cycle_conf = conf
|
||
eng._cycle_detected = ''
|
||
eng._cycle_recog_path = 'fake.jpg'
|
||
eng.recog = recog or FakeRecog(conf=conf)
|
||
eng.submitted = []
|
||
eng._start_submit = lambda row, biz, src: (
|
||
eng.submitted.append((row['id'], biz, src)),
|
||
eng._set_state('SUBMIT'))
|
||
|
||
|
||
def last_focus():
|
||
for e, p in reversed(EVENTS):
|
||
if e == 'focus':
|
||
return p
|
||
return None
|
||
|
||
|
||
def manual_warn():
|
||
f = last_focus()
|
||
return (f or {}).get('warn')
|
||
|
||
|
||
def logs():
|
||
return [str(p) for e, p in EVENTS if e == 'log']
|
||
|
||
|
||
ok = fail = 0
|
||
|
||
|
||
def check(name, cond, extra=''):
|
||
global ok, fail
|
||
if cond:
|
||
ok += 1
|
||
print(' ✓', name)
|
||
else:
|
||
fail += 1
|
||
print(' ✗', name, extra)
|
||
|
||
|
||
print('=== 1. 19:21 事故复现:27.52 斤 vs 香菜应 1 斤(27.5 倍)===')
|
||
reset(xiangcai(), kg=13.760) # 13.76 kg = 27.52 斤
|
||
eng._run_recognition()
|
||
w = manual_warn() or ''
|
||
print(' state =', eng.state, '| submitted =', eng.submitted)
|
||
print(' warn =', w)
|
||
check('没有自动提交', eng.submitted == [])
|
||
check('停在确认条等人', eng.state == 'CONFIRM')
|
||
check('提示点明「名单里没有这件货」', '名单里没有这件货' in w)
|
||
check('提示写出倍数 27.5', '27.5' in w)
|
||
check('提示给出「确实要按它收 1.00 斤再点」', '再点它' in w)
|
||
check('提示不再只说「请人工确认」', '请人工确认' not in w)
|
||
check('日志里也有这条(不是 [dev] 隐掉)',
|
||
any('名单里没有这件货' in x for x in logs()))
|
||
|
||
print('=== 2. 普通超收(应 20 实 30,1.5 倍)→ 仍是原文案,不误报缺项 ===')
|
||
reset([{'id': 'b1', 'item_name': '血皮菜', 'unit': '斤',
|
||
'required_qty': 20.0, 'sku_code': 'S2'}], kg=15.0,
|
||
recog=FakeRecog('血皮菜', 92, ''))
|
||
eng._run_recognition()
|
||
w = manual_warn() or ''
|
||
print(' warn =', w)
|
||
check('提示是「超出应/拣量」', ('超出应验量' in w or '超出应拣量' in w))
|
||
check('不出现「名单里没有」', '名单里没有' not in w)
|
||
check('没有自动提交', eng.submitted == [])
|
||
|
||
print('=== 3. 边界:正好 3 倍(应 10 实 30)→ 走缺项文案 ===')
|
||
reset([{'id': 'c1', 'item_name': '茄子', 'unit': '斤',
|
||
'required_qty': 10.0, 'sku_code': 'S3'}], kg=15.0,
|
||
recog=FakeRecog('茄子', 92, ''))
|
||
eng._run_recognition()
|
||
w = manual_warn() or ''
|
||
print(' warn =', w)
|
||
check('3 倍算缺项', '名单里没有这件货' in w)
|
||
|
||
print('=== 4. over_receipt_ratio=0 → 关闭缺项判定,回到原文案 ===')
|
||
reset(xiangcai(), kg=13.760, ratio=0)
|
||
eng._run_recognition()
|
||
w = manual_warn() or ''
|
||
print(' warn =', w)
|
||
check('关闭后是「超出应/拣量」', ('超出应验量' in w or '超出应拣量' in w))
|
||
check('关闭后不提「名单里没有」', '名单里没有' not in w)
|
||
check('仍然不提交', eng.submitted == [])
|
||
|
||
print('=== 5. 模型答「认不出」→ 日志点明不在待办名单里 ===')
|
||
reset(xiangcai(), kg=13.760, recog=FakeRecog('', 0, ''))
|
||
eng._run_recognition()
|
||
lg = logs()
|
||
print(' logs =', lg)
|
||
check('日志说「不在待办名单里」',
|
||
any('不在待办名单里' in x for x in lg))
|
||
check('没有提交', eng.submitted == [])
|
||
|
||
print()
|
||
print('通过 %d 项,失败 %d 项' % (ok, fail))
|
||
sys.exit(1 if fail else 0)
|