feat: 配置写死与 baked 模块,Alembic 建表,百度仅 BAIDU_*
- 新增 app/baked/algorithm|pipeline,非部署参数不再走 env;Settings 保留 DB/HTTP/RTSP/海康/百度/MinIO/Demo - 移除 init_db_schema 与 reload 配置;main 仅 check_database;start*.sh 在 uvicorn 前执行 alembic upgrade head - 依赖 psycopg[binary] 供 Alembic 同步 URL;alembic/env 注释与预发清单更新 - 撕段门控消费管线、各视频/语音/归档调用改为 baked - 百度环境变量仅 BAIDU_APP_ID、BAIDU_API_KEY、BAIDU_SECRET_KEY 与 BAIDU_* 超时/ASR;人脸脚本与 baidu_speech 文案同步 - 全量单测与 .env.example 更新;.gitignore 忽略 refs/(本地权重/视频不入库) Made-with: Cursor
This commit is contained in:
@@ -14,7 +14,7 @@ from dataclasses import dataclass, field
|
||||
from datetime import datetime, timezone
|
||||
from typing import Literal
|
||||
|
||||
from app.config import Settings
|
||||
from app.baked import pipeline as bp
|
||||
from app.domain.consumption import SurgeryConsumptionStored
|
||||
from app.services.consumable_vision_algorithm import (
|
||||
ClsTop3,
|
||||
@@ -89,8 +89,7 @@ class SurgerySessionRegistry:
|
||||
生命周期归 ``CameraSessionManager`` 负责,新增/停止会话都走本类。
|
||||
"""
|
||||
|
||||
def __init__(self, *, settings: Settings) -> None:
|
||||
self._s = settings
|
||||
def __init__(self) -> None:
|
||||
self._active: dict[str, RunningSurgery] = {}
|
||||
self._manager_lock = asyncio.Lock()
|
||||
|
||||
@@ -168,7 +167,7 @@ class SurgerySessionRegistry:
|
||||
if run is None:
|
||||
return 0, 0
|
||||
st = run.state
|
||||
max_r = int(self._s.voice_confirm_max_failed_parse_rounds)
|
||||
max_r = int(bp.VOICE_CONFIRM_MAX_FAILED_PARSE_ROUNDS)
|
||||
async with st.lock:
|
||||
p = st.pending_by_id.get(confirmation_id)
|
||||
if p is None or p.status != "pending":
|
||||
@@ -250,7 +249,7 @@ class SurgerySessionRegistry:
|
||||
item_id=item_id,
|
||||
item_name=label,
|
||||
qty=1,
|
||||
doctor_id=self._s.video_voice_confirm_doctor_id,
|
||||
doctor_id=bp.VIDEO_VOICE_CONFIRM_DOCTOR_ID,
|
||||
timestamp=datetime.now(timezone.utc),
|
||||
source="voice",
|
||||
pending_confirmation_id=None,
|
||||
@@ -272,7 +271,7 @@ class SurgerySessionRegistry:
|
||||
state=st,
|
||||
item_id=item_id,
|
||||
item_name=label,
|
||||
doctor_id=self._s.video_voice_confirm_doctor_id,
|
||||
doctor_id=bp.VIDEO_VOICE_CONFIRM_DOCTOR_ID,
|
||||
source="voice",
|
||||
)
|
||||
self._finalize_voice_confirmed_consumption_log(
|
||||
@@ -305,9 +304,9 @@ class SurgerySessionRegistry:
|
||||
confirmation_id=confirmation_id,
|
||||
name_to_code=state.name_to_code,
|
||||
chosen_label=cl,
|
||||
doctor_id=self._s.video_voice_confirm_doctor_id,
|
||||
doctor_id=bp.VIDEO_VOICE_CONFIRM_DOCTOR_ID,
|
||||
wall_epoch=time.time(),
|
||||
tsv_enabled=self._s.consumption_tsv_log_enabled,
|
||||
tsv_enabled=bp.CONSUMPTION_TSV_LOG_ENABLED,
|
||||
)
|
||||
|
||||
def _append_confirmed_detail_locked(
|
||||
@@ -318,21 +317,29 @@ class SurgerySessionRegistry:
|
||||
item_name: str,
|
||||
doctor_id: str,
|
||||
source: str,
|
||||
cooldown_key: str | None = None,
|
||||
detail_timestamp: datetime | None = None,
|
||||
) -> None:
|
||||
"""在已持有 ``state.lock`` 时追加一条消耗明细。"""
|
||||
"""在已持有 ``state.lock`` 时追加一条消耗明细。
|
||||
|
||||
``cooldown_key``:非空时用于 `video_detail_cooldown_sec` 去重(例如撕段每段独立键,避免同 SKU 多段被吞)。
|
||||
``detail_timestamp``:非空时写入该 UTC 时刻,否则为当前时间。
|
||||
"""
|
||||
dedupe = cooldown_key if cooldown_key is not None else item_id
|
||||
now_m = time.monotonic()
|
||||
cooldown = self._s.video_detail_cooldown_sec
|
||||
prev = state.last_detail_monotonic.get(item_id)
|
||||
cooldown = bp.VIDEO_DETAIL_COOLDOWN_SEC
|
||||
prev = state.last_detail_monotonic.get(dedupe)
|
||||
if prev is not None and (now_m - prev) < cooldown:
|
||||
return
|
||||
state.last_detail_monotonic[item_id] = now_m
|
||||
state.last_detail_monotonic[dedupe] = now_m
|
||||
ts = detail_timestamp if detail_timestamp is not None else datetime.now(timezone.utc)
|
||||
state.details.append(
|
||||
SurgeryConsumptionStored(
|
||||
item_id=item_id,
|
||||
item_name=item_name,
|
||||
qty=1,
|
||||
doctor_id=doctor_id,
|
||||
timestamp=datetime.now(timezone.utc),
|
||||
timestamp=ts,
|
||||
source=source,
|
||||
pending_confirmation_id=None,
|
||||
)
|
||||
@@ -380,6 +387,8 @@ class SurgerySessionRegistry:
|
||||
item_name: str,
|
||||
doctor_id: str,
|
||||
source: str,
|
||||
cooldown_key: str | None = None,
|
||||
detail_timestamp: datetime | None = None,
|
||||
) -> None:
|
||||
async with state.lock:
|
||||
self._append_confirmed_detail_locked(
|
||||
@@ -388,6 +397,8 @@ class SurgerySessionRegistry:
|
||||
item_name=item_name,
|
||||
doctor_id=doctor_id,
|
||||
source=source,
|
||||
cooldown_key=cooldown_key,
|
||||
detail_timestamp=detail_timestamp,
|
||||
)
|
||||
|
||||
async def enqueue_pending_confirmation(
|
||||
@@ -403,7 +414,7 @@ class SurgerySessionRegistry:
|
||||
if not opts:
|
||||
return None
|
||||
now_m = time.monotonic()
|
||||
cooldown = self._s.video_detail_cooldown_sec
|
||||
cooldown = bp.VIDEO_DETAIL_COOLDOWN_SEC
|
||||
dedupe_key = f"pending_confirm:{top_key}:{opts[0][0]}"
|
||||
async with state.lock:
|
||||
prev = state.last_detail_monotonic.get(dedupe_key)
|
||||
|
||||
Reference in New Issue
Block a user