refactor: 统一耗材视觉算法并扩展语音确认至全量候选清单
- 以 ConsumableVisionAlgorithmService 替代 consumable_classifier 与 tear_action; 可选手部检测权重,未配置时全帧分类;时间窗众数与 Excel 白名单配置。 - 语音待确认:ASR 先匹配 pending topk,再匹配本台 candidate_consumables; 记账 item_id 与 vision 一致使用 name_to_code。 - 更新 config、Compose、.env.example、依赖(pandas/openpyxl)与测试。 Made-with: Cursor
This commit is contained in:
@@ -61,20 +61,24 @@ def _make_service(
|
||||
def _active_session_with_pending(
|
||||
surgery_id: str = "123456",
|
||||
confirmation_id: str = "cid-a",
|
||||
*,
|
||||
candidate_consumables: list[str] | None = None,
|
||||
pending_options: list[tuple[str, float]] | None = None,
|
||||
) -> tuple[CameraSessionManager, str]:
|
||||
settings = Settings()
|
||||
mgr = CameraSessionManager(
|
||||
settings=settings,
|
||||
consumable_classifier=MagicMock(),
|
||||
tear_action=MagicMock(),
|
||||
vision_algorithm=MagicMock(),
|
||||
hikvision_runtime=None,
|
||||
result_repository=None,
|
||||
)
|
||||
st = SurgerySessionState(candidate_consumables=["纱布", "缝线"])
|
||||
cands = candidate_consumables or ["纱布", "缝线"]
|
||||
opts = pending_options or [("纱布", 0.4), ("缝线", 0.3)]
|
||||
st = SurgerySessionState(candidate_consumables=cands)
|
||||
st.pending_by_id[confirmation_id] = PendingConsumableConfirmation(
|
||||
id=confirmation_id,
|
||||
status="pending",
|
||||
options=[("纱布", 0.4), ("缝线", 0.3)],
|
||||
options=opts,
|
||||
prompt_text="请确认",
|
||||
created_at=datetime.now(timezone.utc),
|
||||
model_top1_label="x",
|
||||
@@ -193,6 +197,55 @@ async def test_resolve_rejected_audit(
|
||||
assert row.status == "rejected"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_recognizes_label_not_in_topk_but_in_surgery_candidates(
|
||||
sqlite_session_factory,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""医生说出候选清单中的耗材(未出现在本次 pending 的模型 topk 里)也应记账。"""
|
||||
settings = Settings()
|
||||
sessions, cid = _active_session_with_pending(
|
||||
candidate_consumables=["纱布", "缝线", "止血钳"],
|
||||
pending_options=[("纱布", 0.4), ("缝线", 0.3)],
|
||||
)
|
||||
minio = MagicMock()
|
||||
minio.configured = True
|
||||
minio.ensure_bucket = MagicMock()
|
||||
minio.upload_voice_wav = MagicMock(
|
||||
return_value=StoredAudio(
|
||||
object_key="k2.wav",
|
||||
sha256_hex="d" * 64,
|
||||
size_bytes=10,
|
||||
)
|
||||
)
|
||||
baidu = MagicMock()
|
||||
baidu.configured = True
|
||||
baidu.asr = MagicMock(
|
||||
return_value={"err_no": 0, "result": ["刚才用的是止血钳"]}
|
||||
)
|
||||
svc = _make_service(
|
||||
settings=settings,
|
||||
sessions=sessions,
|
||||
minio=minio,
|
||||
baidu=baidu,
|
||||
sqlite_factory=sqlite_session_factory,
|
||||
monkeypatch=monkeypatch,
|
||||
)
|
||||
result = await svc.resolve_from_wav(
|
||||
surgery_id="123456",
|
||||
confirmation_id=cid,
|
||||
wav_bytes=_minimal_wav_16k_mono(),
|
||||
filename="a.wav",
|
||||
content_type="audio/wav",
|
||||
)
|
||||
assert result.rejected is False
|
||||
assert result.resolved_label == "止血钳"
|
||||
st = sessions._active["123456"].state
|
||||
assert len(st.details) == 1
|
||||
assert st.details[0].item_name == "止血钳"
|
||||
assert st.details[0].source == "voice"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_audio_too_large_audit(
|
||||
sqlite_session_factory,
|
||||
|
||||
Reference in New Issue
Block a user