63 lines
2.6 KiB
Python
63 lines
2.6 KiB
Python
"""Dashboard API schemas."""
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class PlatformScoreItem(BaseModel):
|
|
"""平台评分项"""
|
|
platform: str = Field(..., description="平台标识")
|
|
score: float = Field(..., ge=0.0, le=100.0, description="评分 0-100")
|
|
competitor_score: float | None = Field(None, description="竞品评分")
|
|
competitor_name: str | None = Field(None, description="竞品名称")
|
|
|
|
|
|
class RecentQueryItem(BaseModel):
|
|
"""最近查询项"""
|
|
id: str = Field(..., description="查询ID")
|
|
keyword: str = Field(..., description="查询关键词")
|
|
target_brand: str = Field(..., description="目标品牌")
|
|
citation_count: int = Field(0, description="引用数量")
|
|
queried_at: datetime = Field(..., description="查询时间")
|
|
|
|
|
|
class BrandOverviewScore(BaseModel):
|
|
"""品牌概览评分"""
|
|
brand_id: str = Field(..., description="品牌ID")
|
|
brand_name: str = Field(..., description="品牌名称")
|
|
overall_score: float = Field(..., ge=0.0, le=100.0, description="综合评分")
|
|
score_change: float = Field(..., description="较昨日变化")
|
|
platform_scores: list[PlatformScoreItem] = Field(
|
|
default_factory=list, description="各平台评分"
|
|
)
|
|
|
|
|
|
class DimensionScoreItem(BaseModel):
|
|
"""维度评分项"""
|
|
name: str = Field(..., description="维度名称")
|
|
score: float = Field(..., ge=0.0, description="该维度得分")
|
|
max_score: float = Field(..., description="该维度满分")
|
|
percentage: float = Field(..., ge=0.0, le=100.0, description="得分率百分比")
|
|
|
|
|
|
class DashboardStatsResponse(BaseModel):
|
|
"""看板统计数据响应"""
|
|
overall_score: float = Field(..., ge=0.0, le=100.0, description="综合评分 0-100")
|
|
health_level: str = Field("danger", description="健康等级: excellent/good/pass/danger")
|
|
score_change: float = Field(..., description="较昨日变化")
|
|
platform_scores: list[PlatformScoreItem] = Field(
|
|
default_factory=list, description="平台评分列表"
|
|
)
|
|
recent_queries: list[RecentQueryItem] = Field(
|
|
default_factory=list, description="最近查询记录"
|
|
)
|
|
# V2新增字段
|
|
dimensions: list[DimensionScoreItem] = Field(
|
|
default_factory=list, description="五维度评分详情"
|
|
)
|
|
competitors_ahead: int = Field(0, description="领先竞品数")
|
|
competitors_behind: int = Field(0, description="落后竞品数")
|
|
monitored_platforms: int = Field(0, description="已监控平台数")
|
|
total_platforms: int = Field(7, description="总平台数")
|
|
brand_name: str | None = Field(None, description="品牌名称")
|