Files
knowledge-governance/web/src/qaHistoricalTrend.ts
T
姚章浩 cb9f0c389f
build / build (push) Successful in 1m10s
feat(qaops): 看板改用自然月质量指标并增加统计口径
去掉看板个人月明细;十一卡悬停和键盘可读的真实统计范围、公式与排除数。
自然月独立计算;跨月周取周一所在月,保留旧周证据和已存周报正文。

验证:make verify;一次性PG全镜像套件-race;真实恢复数据7个月与周报calc_metrics对拍。
真实浏览器十一卡逐项悬停、Tab/Escape、30秒刷新、跨月周、390px和完整PNG通过。
没有写DobotAI源问答、触发付费模型、外发或应用新迁移。
2026-10-21 08:48:55 +08:00

74 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { QADashboardData } from './qaDashboardData'
import { currentQAWeek } from './qaWeeks'
export interface HistoricalPlotPoint {
label: string
value: number | null
hint: string
frozen?: boolean
source?: 'user_provided_history' | 'system_frozen' | 'master_live_cumulative_v1' | 'master_live_calendar_month_v1'
month?: string
week?: string
}
// Never manufacture row counts or connect a line across missing weeks/policy changes.
export function historicalTrend(data: QADashboardData, correctness: boolean): HistoricalPlotPoint[] {
if (data.quality_period) {
return (data.calendar_months ?? []).map((point) => {
const rate = correctness ? point.correctness : point.coverage
return {
label: point.month,
month: point.month,
value: rate.percent,
source: point.source,
hint: `${point.month}:${rate.percent === null ? '—' : rate.percent.toFixed(2) + '%'};${rate.numerator}/${rate.denominator};月内 ${point.records} 条,排除 ${point.records - rate.denominator} 条;[${point.month_start}, ${point.cutoff_at});每月独立,是÷(是+否),当前有效字段动态重算,非历史冻结`,
}
})
}
const frozen = new Map(data.frozen_weeks.map((p) => [Date.parse(p.week_start), p]))
const reported = new Map(data.reported_weeks.map((p) => [Date.parse(p.week_start), p]))
const cumulative = new Map((data.cumulative_weeks ?? []).map((p) => [Date.parse(p.week_start), p]))
const starts = [...frozen.keys(), ...reported.keys(), ...cumulative.keys()]
if (!starts.length) return []
const out: HistoricalPlotPoint[] = []
for (let at = Math.min(...starts); at < Date.parse(data.end) && out.length < 5200; at += 7 * 86400000) {
const w = currentQAWeek(new Date(at)),
label = `${w.year}W${String(w.week).padStart(2, '0')}`,
supplied = reported.get(at),
point = frozen.get(at)
const live = cumulative.get(at)
if (live) {
const rate = correctness ? live.correctness : live.coverage
out.push({
label,
week: live.week,
value: rate.percent,
source: 'master_live_cumulative_v1',
hint: `${live.week}:${rate.percent?.toFixed(2) ?? '—'}%;${rate.numerator}/${rate.denominator};总表累计 ${live.records} 条,截至 ${live.cutoff_at};当前有效字段动态重算,是÷(是+否),非历史冻结`,
})
continue
}
if (supplied) {
const value = correctness ? supplied.correctness_percent : supplied.coverage_percent
out.push({
label,
week: supplied.week,
value,
source: 'user_provided_history',
hint: `${supplied.week}:${value.toFixed(2)}%;用户提供历史统计,未提供分子/分母;不按当前规则重算`,
})
continue
}
const rate = point ? (correctness ? point.correctness : point.coverage) : null
out.push({
label,
week: `${w.year}WK${String(w.week).padStart(2, '0')}`,
value: rate?.percent ?? null,
frozen: point?.frozen_at !== null && point?.frozen_at !== undefined,
source: point?.frozen_at ? 'system_frozen' : undefined,
hint: point?.frozen_at
? `${label}:${rate?.percent?.toFixed(2) ?? '—'}%;${rate?.numerator}/${rate?.denominator};系统冻结于 ${point.frozen_at}`
: `${label}:未提供历史统计,缺少当时冻结快照`,
})
}
return out
}