2026-09-04 10:20:40 +08:00

75 lines
1.7 KiB
Python

"""Dashboard aggregation response contracts."""
from typing import Literal
from pydantic import Field
from app.schemas.common import ApiSchema
class DashboardMetric(ApiSchema):
value: int | float | None = None
label: str
change_percent: float | None = None
class DashboardStage(ApiSchema):
name: str
count: int
share: float
risk_level: str
class DashboardCategory(ApiSchema):
name: str
count: int
share: float
risk_level: str
top_material: str | None = None
class DashboardMatrixRow(ApiSchema):
name: str
party_type: str
categories: dict[str, int]
cooperation_total: int
anomaly_count: int
anomaly_rate: float
tier: str
class DashboardDefect(ApiSchema):
level: str
label: str
count: int
share: float
class DashboardSupplierRank(ApiSchema):
name: str
party_type: str
count: int
tier: str
top_problem: str | None = None
class DashboardTrendPoint(ApiSchema):
month: str
label: str
count: int
class DashboardData(ApiSchema):
year: Literal["all", "2024", "2025", "2026"]
total_cases: int
metrics: list[DashboardMetric] = Field(default_factory=list)
stages: list[DashboardStage] = Field(default_factory=list)
categories: list[DashboardCategory] = Field(default_factory=list)
matrix_categories: list[str] = Field(default_factory=list)
matrix: list[DashboardMatrixRow] = Field(default_factory=list)
defects: list[DashboardDefect] = Field(default_factory=list)
supplier_ranking: list[DashboardSupplierRank] = Field(default_factory=list)
trend: list[DashboardTrendPoint] = Field(default_factory=list)
insight: str
warnings: list[str] = Field(default_factory=list)