import type { Confidence } from './types'; type CostEvent = { dataSource: string }; type RevenueEvent = { dataSource: string }; const HIGH_QUALITY_COST_SOURCES = new Set(['plane_actual', 'manual']); /** * 对一个时间窗的事件计算置信度: * - High: 成本事件 80%+ 来自 plane_actual / manual,且收益事件存在 * - Low: 只有成本无收益,或所有成本都来自 auto_commits/auto_tasks 估算 * - Medium: 其他情况 */ export function evaluateConfidence( costEvents: CostEvent[], revenueEvents: RevenueEvent[] ): Confidence { const totalCost = costEvents.length; const totalRevenue = revenueEvents.length; if (totalCost === 0 && totalRevenue === 0) return 'low'; // 无收益 = 直接 low(无法判断盈亏) if (totalRevenue === 0) return 'low'; // 全自动估算 = low const highQualityCount = costEvents.filter(e => HIGH_QUALITY_COST_SOURCES.has(e.dataSource)).length; if (totalCost > 0 && highQualityCount === 0) return 'low'; // 80%+ 高质量 = high if (totalCost > 0 && highQualityCount / totalCost >= 0.8) return 'high'; return 'medium'; }