123 lines
3.9 KiB
Python
123 lines
3.9 KiB
Python
"""Pydantic-модели JSON-ответов (docs/05 §5.4.2, §5.4.4)."""
|
|
from __future__ import annotations
|
|
|
|
from typing import Literal
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class PairMetricsModel(BaseModel):
|
|
good_matches: int = Field(description="Число пар после теста Лоу")
|
|
inliers: int = Field(description="Число инлаеров RANSAC")
|
|
inlier_ratio: float = Field(description="inliers / good_matches")
|
|
coverage: float = Field(description="Доля площади пробы под оболочкой инлаеров")
|
|
|
|
|
|
class ThresholdsModel(BaseModel):
|
|
"""Эффективные пороги сравнения лучшей пары (+ аддитивные поля диагностики)."""
|
|
|
|
inliers_match: int
|
|
inlier_ratio_match: float
|
|
coverage_min: float
|
|
inliers_uncertain_min: int
|
|
geometry_model: str
|
|
lowe_ratio: float
|
|
ransac_reproj_threshold: float
|
|
|
|
|
|
class VerifyDetailsModel(BaseModel):
|
|
references_compared: int
|
|
best_reference_index: int = Field(description="Индекс части reference (0-based)")
|
|
metrics: PairMetricsModel
|
|
thresholds: ThresholdsModel
|
|
|
|
|
|
class VerifyResponse(BaseModel):
|
|
verdict: Literal["match", "uncertain", "no_match"]
|
|
is_match: bool = Field(description="true только при verdict = match")
|
|
confidence: float = Field(ge=0.0, le=1.0)
|
|
details: VerifyDetailsModel
|
|
probe_sha256: str
|
|
processing_ms: int
|
|
|
|
|
|
class ProfileModel(BaseModel):
|
|
name: str
|
|
description: str
|
|
extraction: dict
|
|
comparison: dict
|
|
|
|
|
|
class ProfilesResponse(BaseModel):
|
|
profiles: list[ProfileModel]
|
|
defaults: dict = Field(description="Базовые значения (env-умолчания) для наследования")
|
|
|
|
|
|
class CalibrateComboModel(BaseModel):
|
|
"""Одна комбинация pipeline-параметров с подобранными порогами (docs/05 §5.4.5)."""
|
|
|
|
geometry_model: str
|
|
lowe_ratio: float
|
|
ransac_reproj_threshold: float
|
|
thresholds: dict = Field(
|
|
description="Подобранные пороги вердикта: inliers_match, inlier_ratio_match, "
|
|
"coverage_min, inliers_uncertain_min"
|
|
)
|
|
tp: int = Field(description="Позитивные пары с вердиктом match")
|
|
fp: int = Field(description="Ложные match на негативных парах")
|
|
fn: int
|
|
f1: float
|
|
uncertain_rate: float
|
|
margin: float = Field(description="Нормированный зазор между классами (устойчивость)")
|
|
|
|
|
|
class CalibratePairModel(BaseModel):
|
|
probe: str
|
|
ref: str
|
|
is_positive: bool
|
|
good_matches: int
|
|
inliers: int
|
|
inlier_ratio: float
|
|
coverage: float
|
|
verdict: Literal["match", "uncertain", "no_match"]
|
|
|
|
|
|
class CalibrateImageModel(BaseModel):
|
|
name: str
|
|
group: Literal["positive", "negative"]
|
|
keypoints: int
|
|
|
|
|
|
class CalibrateSkippedModel(BaseModel):
|
|
name: str
|
|
group: str
|
|
reason: str
|
|
|
|
|
|
class CalibrateResponse(BaseModel):
|
|
"""Полный отчёт калибровки (docs/05 §5.4.5)."""
|
|
|
|
settings: dict = Field(
|
|
description="Готовый фрагмент settings: передать в /features при регистрации "
|
|
"эталонов и/или в /verify для этого объекта"
|
|
)
|
|
metrics: dict
|
|
best: CalibrateComboModel
|
|
ranking: list[CalibrateComboModel] = Field(description="Все комбинации, от лучшей к худшей")
|
|
pairs: list[CalibratePairModel]
|
|
presets: dict = Field(description="tp/fp стандартных профилей на тех же данных")
|
|
images: list[CalibrateImageModel]
|
|
skipped: list[CalibrateSkippedModel]
|
|
warnings: list[str]
|
|
selfcheck: dict
|
|
processing_ms: int
|
|
|
|
|
|
class StatusResponse(BaseModel):
|
|
status: str
|
|
|
|
|
|
class UnreadyResponse(BaseModel):
|
|
status: str
|
|
reasons: list[str]
|