Files
operating-room-monitor-server/tests/test_session_rank.py
Kevin 3d7bd70355 feat: 手术视频消耗、待确认与持久化改造
- 新增 Alembic 初始迁移、领域明细模型及归档持久化与重试链路\n- 拆分视频会话注册表、分类处理、推理时间窗聚合与流处理\n- 消耗日志:TSV/Markdown 含 top2/top3;item_id 优先产品编码;待确认记「待确认」行,语音确认后落正式行并更新汇总\n- 待确认时内存/DB 明细为占位行,确认后替换;拒绝时移除占位\n- 分类 probs 先 detach/cpu 再转 NumPy,修复 MPS/CUDA 上推理被静默跳过\n- 补充集成测试、归档与设备张量等单测

Made-with: Cursor
2026-04-23 20:42:21 +08:00

24 lines
828 B
Python

from app.services.consumable_vision_algorithm import PredictionCandidate
from app.services.video.classification_handler import (
rank_topk_for_candidates as _rank_topk_for_candidates,
)
def test_rank_respects_candidate_order() -> None:
topk = [
PredictionCandidate(label="缝线", confidence=0.9),
PredictionCandidate(label="纱布", confidence=0.5),
]
ordered = ["纱布", "缝线"]
ranked = _rank_topk_for_candidates(topk, ordered)
assert [c.label for c in ranked] == ["纱布", "缝线"]
def test_rank_without_candidates_keeps_model_order() -> None:
topk = [
PredictionCandidate(label="a", confidence=0.9),
PredictionCandidate(label="b", confidence=0.5),
]
ranked = _rank_topk_for_candidates(topk, [])
assert [c.label for c in ranked] == ["a", "b"]