143 lines
4.0 KiB
Python
143 lines
4.0 KiB
Python
"""仪表盘 Schema
|
|
|
|
仪表盘数据相关的响应模型
|
|
"""
|
|
|
|
from typing import Optional, List, Dict
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class ProjectOverview(BaseModel):
|
|
"""项目概览"""
|
|
|
|
total_projects: int = Field(..., description="总项目数")
|
|
active_projects: int = Field(..., description="启用项目数")
|
|
projects_with_pricing: int = Field(..., description="已定价项目数")
|
|
|
|
|
|
class CostProjectInfo(BaseModel):
|
|
"""成本项目信息"""
|
|
|
|
id: int
|
|
name: str
|
|
cost: float
|
|
|
|
|
|
class CostOverview(BaseModel):
|
|
"""成本概览"""
|
|
|
|
avg_project_cost: float = Field(..., description="平均项目成本")
|
|
highest_cost_project: Optional[CostProjectInfo] = Field(None, description="最高成本项目")
|
|
lowest_cost_project: Optional[CostProjectInfo] = Field(None, description="最低成本项目")
|
|
|
|
|
|
class MarketOverview(BaseModel):
|
|
"""市场概览"""
|
|
|
|
competitors_tracked: int = Field(..., description="跟踪竞品数")
|
|
price_records_this_month: int = Field(..., description="本月价格记录数")
|
|
avg_market_price: Optional[float] = Field(None, description="市场平均价")
|
|
|
|
|
|
class StrategiesDistribution(BaseModel):
|
|
"""策略分布"""
|
|
|
|
traffic: int = Field(0, description="引流款数量")
|
|
profit: int = Field(0, description="利润款数量")
|
|
premium: int = Field(0, description="高端款数量")
|
|
|
|
|
|
class PricingOverview(BaseModel):
|
|
"""定价概览"""
|
|
|
|
pricing_plans_count: int = Field(..., description="定价方案总数")
|
|
avg_target_margin: Optional[float] = Field(None, description="平均目标毛利率")
|
|
strategies_distribution: StrategiesDistribution = Field(..., description="策略分布")
|
|
|
|
|
|
class ProviderDistribution(BaseModel):
|
|
"""服务商分布"""
|
|
|
|
primary: int = Field(0, alias="4sapi", description="4sapi 调用次数")
|
|
fallback: int = Field(0, alias="openrouter", description="OpenRouter 调用次数")
|
|
|
|
class Config:
|
|
populate_by_name = True
|
|
|
|
|
|
class AIUsageOverview(BaseModel):
|
|
"""AI 使用概览"""
|
|
|
|
total_calls: int = Field(..., description="总调用次数")
|
|
total_tokens: int = Field(..., description="总 Token 消耗")
|
|
total_cost_usd: float = Field(..., description="总费用(美元)")
|
|
provider_distribution: Dict[str, int] = Field(..., description="服务商分布")
|
|
|
|
|
|
class RecentActivity(BaseModel):
|
|
"""最近活动"""
|
|
|
|
type: str = Field(..., description="活动类型")
|
|
project_name: str = Field(..., description="项目名称")
|
|
user: Optional[str] = Field(None, description="用户")
|
|
time: datetime = Field(..., description="时间")
|
|
|
|
|
|
class DashboardSummaryResponse(BaseModel):
|
|
"""仪表盘概览响应"""
|
|
|
|
project_overview: ProjectOverview
|
|
cost_overview: CostOverview
|
|
market_overview: MarketOverview
|
|
pricing_overview: PricingOverview
|
|
ai_usage_this_month: Optional[AIUsageOverview] = None
|
|
recent_activities: List[RecentActivity] = Field(default_factory=list)
|
|
|
|
|
|
# 趋势数据
|
|
|
|
class TrendDataPoint(BaseModel):
|
|
"""趋势数据点"""
|
|
|
|
date: str = Field(..., description="日期")
|
|
value: float = Field(..., description="值")
|
|
|
|
|
|
class CostTrendResponse(BaseModel):
|
|
"""成本趋势响应"""
|
|
|
|
period: str = Field(..., description="统计周期")
|
|
data: List[TrendDataPoint]
|
|
avg_cost: float = Field(..., description="平均成本")
|
|
|
|
|
|
class MarketTrendResponse(BaseModel):
|
|
"""市场趋势响应"""
|
|
|
|
period: str = Field(..., description="统计周期")
|
|
data: List[TrendDataPoint]
|
|
avg_price: float = Field(..., description="平均价格")
|
|
|
|
|
|
# AI 使用统计
|
|
|
|
class AIUsageStatItem(BaseModel):
|
|
"""AI 使用统计项"""
|
|
|
|
date: str
|
|
calls: int
|
|
tokens: int
|
|
cost: float
|
|
|
|
|
|
class AIUsageStatsResponse(BaseModel):
|
|
"""AI 使用统计响应"""
|
|
|
|
period: str = Field(..., description="统计周期")
|
|
total_calls: int
|
|
total_tokens: int
|
|
total_cost: float
|
|
daily_stats: List[AIUsageStatItem]
|