69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
|
|
/**
|
|||
|
|
* 统计分析 API 骨架(Phase 3 Task 3)
|
|||
|
|
*
|
|||
|
|
* 端点事实源:app/platform/routes/stats_routes.py + app/platform/stats.py
|
|||
|
|
* (平台合并统计 / 单租户统计,?from/&to= 闭区间)。本文件只建类型与
|
|||
|
|
* 端点常量——调用函数在 Task 4(仪表盘)与 Task 8(统计分析)实装。
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
/** 指标卡(None 项为 null——如无推送时成功率无定义) */
|
|||
|
|
export interface StatsCards {
|
|||
|
|
conversations: number
|
|||
|
|
leads: number
|
|||
|
|
high_intent: number
|
|||
|
|
push_success_rate: number | null
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 漏斗计数 */
|
|||
|
|
export interface StatsFunnel {
|
|||
|
|
conversations: number
|
|||
|
|
leads: number
|
|||
|
|
evaluated: number
|
|||
|
|
push_succeeded: number
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 按日趋势行 */
|
|||
|
|
export interface StatsTrendPoint {
|
|||
|
|
date: string
|
|||
|
|
conversations: number
|
|||
|
|
leads: number
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 分布视图(intent 按枚举键、source/site 计数表、country Top 数组) */
|
|||
|
|
export interface StatsDistributions {
|
|||
|
|
intent: Record<string, number>
|
|||
|
|
source: Record<string, number>
|
|||
|
|
site: Record<string, number>
|
|||
|
|
country: Array<{ country: string; count: number }>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 推送健康计数 */
|
|||
|
|
export interface PushHealth {
|
|||
|
|
pending: number
|
|||
|
|
success: number
|
|||
|
|
failed: number
|
|||
|
|
skipped: number
|
|||
|
|
duplicated: number
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 统计响应(平台合并与单租户同构) */
|
|||
|
|
export interface StatsResponse {
|
|||
|
|
cards: StatsCards
|
|||
|
|
funnel: StatsFunnel
|
|||
|
|
trend: StatsTrendPoint[]
|
|||
|
|
distributions: StatsDistributions
|
|||
|
|
push_health: PushHealth
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 统计查询参数(from/to 闭区间,ISO 日期) */
|
|||
|
|
export interface StatsParams {
|
|||
|
|
from?: string
|
|||
|
|
to?: string
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 统计端点(platform 合并版仅超管;单租户版超管或本租户管理员) */
|
|||
|
|
export const STATS_ENDPOINTS = {
|
|||
|
|
platform: '/api/platform/stats',
|
|||
|
|
tenant: (slug: string) => `/api/platform/tenants/${slug}/stats`
|
|||
|
|
} as const
|