5e1395db18
The app plumbing for venue-modules.md §"Vehicle category from vision"; the model is the open half (no bundled recognizer emits body_type yet, so the desk shows nothing until phase A lands in the vision service). - Shared: VEHICLE_CLASSES vocabulary, VehicleRead, CARWASH_VISION_THRESHOLD_DEFAULT, reason code carwash.categoryDowngrade; settings/order/lookup views carry the read. - Vision contract: /analyze vehicle.body_type + confidence (service schema); the Node client normalises to the vocabulary and drops the rest. - Record: snapshot.ts stores the read in the plate's device_events row (or its own when the plate was unreadable); vehicleForIdentity() resolves it like the plate. - Car wash: carwash_categories.vision_classes (site mapping "car, sedan → Vetura"), carwash_config.vision_threshold (signed config_change when it moves), four vision columns on orders — migration 0030. Lookup returns vision + suggestedCategoryId. - Desk pre-selects the mapped category and shows the read + snapshot thumbnail; Setup offers class chips per category and the threshold. Operator decides. - Flag: a read at/above the threshold whose mapped category prices HIGHER than the chosen one signs one `anomaly` (both categories/prices, operator, snapshot) and stores its id on the order. Equal/upgrade/unsure/unmapped → nothing. Recorded only, never blocks, no reason prompt (user, 2026-09-06). Tests in carwash.test.ts; wiki venue-modules (As built), opencv-anpr-service, log. Claude-Session: https://claude.ai/code/session_01FWncR69HgGPuei1dLrW3cU
69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
"""The /analyze response contract — the shape the Node VisionClient adapter consumes.
|
||
|
||
Mirrors the first-cut API in wiki/entities/opencv-anpr-service.md:
|
||
{ plate: {text, confidence, bbox}|null, vehicle: {...}|null, modelVersion, tookMs }
|
||
Job 2 (vehicle attributes) is scaffolded as an optional field, not yet populated —
|
||
fast-alpr is plate-only; the vehicle stage is built later on the same ONNX runtime.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from pydantic import BaseModel, Field
|
||
|
||
|
||
class BBox(BaseModel):
|
||
"""Plate bounding box in pixels (top-left origin)."""
|
||
|
||
x1: int
|
||
y1: int
|
||
x2: int
|
||
y2: int
|
||
|
||
|
||
class PlateResult(BaseModel):
|
||
text: str
|
||
# The plate's confidence = the MIN of fast-alpr's per-character confidences (a plate
|
||
# is only as trustworthy as its weakest character). See recognizer.py.
|
||
confidence: float = Field(ge=0.0, le=1.0)
|
||
bbox: BBox | None = None
|
||
# Predicted issuing region/country (advisory; fast-alpr's global model emits this).
|
||
region: str | None = None
|
||
|
||
|
||
class VehicleResult(BaseModel):
|
||
"""Job 2 — vehicle attributes. `body_type` is ADVISORY: the Node server records it
|
||
beside the plate and the Car Wash desk pre-selects the site category it maps to; the
|
||
operator decides, a disagreement is flagged, nothing is ever gated on it. Values come
|
||
from the shared vocabulary (car, sedan, hatchback, suv, minivan, pickup, van, truck,
|
||
bus, motorcycle) — anything else is ignored by Node. Phase A (a COCO detector) emits
|
||
car/truck/bus/motorcycle; the finer classes need the body-type classifier. Not yet
|
||
produced by any bundled recognizer."""
|
||
|
||
colour: str | None = None
|
||
body_type: str | None = None
|
||
# Confidence of `body_type` (0–1). Node compares it to the site's threshold.
|
||
confidence: float | None = Field(default=None, ge=0.0, le=1.0)
|
||
make: str | None = None
|
||
model: str | None = None
|
||
|
||
|
||
class AnalyzeResponse(BaseModel):
|
||
# The single best plate, or null when none was found.
|
||
plate: PlateResult | None = None
|
||
# All plates found (a frame may contain several vehicles).
|
||
plates: list[PlateResult] = Field(default_factory=list)
|
||
vehicle: VehicleResult | None = None
|
||
# True when the best plate is below the confidence floor — Node should treat the
|
||
# read as advisory only and prefer the ticket path. See fail-state-safety.
|
||
low_confidence: bool = False
|
||
model_version: str
|
||
took_ms: float
|
||
|
||
|
||
class HealthResponse(BaseModel):
|
||
status: str
|
||
recognizer: str
|
||
ready: bool
|
||
model_version: str
|
||
detail: str | None = None
|