用户提供的历史百分比独立持久化,按ISO自然周和截止范围读取,不伪造分子分母、记录数或冻结时间。现有两张趋势图与PNG共用来源分色/分段及两位小数;缺失周留空,关键词筛选不借用无明细历史,当前指标与原冻结证据不变。 验证:完整make verify退出0;镜像全量隔离PG race退出0,新增来源/精度/关键词/租户/截止/不可变和安全down回归先失败后通过。前端输入/来源及缺失周回归先红后绿。治理库上线前原生备份与真实恢复已完成,71表行数和28张QA表内容哈希一致,独立主密钥同时受限备份。 当前仅完成开发验证,真实数据候选浏览器验收、正式25周导入与应用上线需继续完成。不修改源生产数据库、原问答、已有模型自动开关或隧道;用户原始报表和图像只保存于私有证据目录,不入Git。
This commit is contained in:
@@ -26,6 +26,29 @@ it('draws all eleven panels as a self-contained exportable SVG without HTML exec
|
||||
expect(html).toContain('data-frozen="missing"')
|
||||
expect(html).toContain('data-frozen="available"')
|
||||
})
|
||||
it('renders reported history in both existing trend panels with exact values and honest provenance', () => {
|
||||
const data = parseQADashboard({
|
||||
...dashboardFixture,
|
||||
reported_weeks: [
|
||||
{
|
||||
week: '2026WK40',
|
||||
week_start: '2026-09-28T00:00:00+08:00',
|
||||
week_end: '2026-10-05T00:00:00+08:00',
|
||||
coverage_percent: 57.23,
|
||||
correctness_percent: 92.34,
|
||||
source: 'user_provided_history',
|
||||
},
|
||||
],
|
||||
})
|
||||
const html = renderToStaticMarkup(<QADashboardDrawing data={data} width={1280} />)
|
||||
expect(html).toContain('57.23%')
|
||||
expect(html).toContain('92.34%')
|
||||
expect(html).toContain('用户提供历史统计')
|
||||
expect(html).toContain('未提供分子/分母')
|
||||
expect((html.match(/data-source="user_provided_history"/g) || []).length).toBe(2)
|
||||
expect((html.match(/data-panel=/g) || []).length).toBe(11)
|
||||
expect(html).toContain('data-frozen="available"')
|
||||
})
|
||||
it('reflows the same complete eleven panels at mobile width rather than clipping the canvas', () => {
|
||||
const html = renderToStaticMarkup(<QADashboardDrawing data={parseQADashboard(dashboardFixture)} width={350} />)
|
||||
expect((html.match(/data-panel=/g) || []).length).toBe(11)
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { ReactNode, Ref } from 'react'
|
||||
import type { QADashboardData, DashboardCount, DashboardRegion } from './qaDashboardData'
|
||||
import type { QualityRate } from './qaQuality'
|
||||
import { currentQAWeek } from './qaWeeks'
|
||||
import { historicalTrend } from './qaHistoricalTrend'
|
||||
interface Box {
|
||||
x: number
|
||||
y: number
|
||||
@@ -271,6 +272,8 @@ interface PlotPoint {
|
||||
value: number | null
|
||||
hint: string
|
||||
frozen?: boolean
|
||||
source?: 'user_provided_history' | 'system_frozen'
|
||||
week?: string
|
||||
}
|
||||
function Plot({
|
||||
box,
|
||||
@@ -295,18 +298,37 @@ function Plot({
|
||||
x = (i: number) =>
|
||||
points.length === 1 ? (left + right) / 2 : left + (i * (right - left)) / Math.max(1, points.length - 1),
|
||||
y = (n: number) => bottom - (n / max) * (bottom - top)
|
||||
let path = '',
|
||||
open = false
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const value = points[i].value
|
||||
if (value === null) {
|
||||
const color = (source: PlotPoint['source']) => (source === 'system_frozen' ? '#8b68c7' : blue)
|
||||
const paths = [...new Set(points.map((p) => p.source))].map((source) => {
|
||||
let path = '',
|
||||
open = false
|
||||
continue
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const point = points[i]
|
||||
if (point.value === null || point.source !== source) {
|
||||
open = false
|
||||
continue
|
||||
}
|
||||
path += `${open ? 'L' : 'M'} ${x(i)} ${y(point.value)} `
|
||||
open = true
|
||||
}
|
||||
path += `${open ? 'L' : 'M'} ${x(i)} ${y(value)} `
|
||||
open = true
|
||||
}
|
||||
return { source, path }
|
||||
})
|
||||
const every = Math.max(1, Math.ceil(points.length / (box.w < 420 ? 5 : 8)))
|
||||
const labelled = new Set<number>()
|
||||
points.forEach((point, i) => {
|
||||
if (
|
||||
point.value !== null &&
|
||||
(i === 0 ||
|
||||
points[i - 1]?.source !== point.source ||
|
||||
i === points.length - 1 ||
|
||||
points[i + 1]?.source !== point.source)
|
||||
)
|
||||
labelled.add(i)
|
||||
})
|
||||
points.forEach((_, i) => {
|
||||
if ((i % every === 0 || i === points.length - 1) && [...labelled].every((k) => Math.abs(x(k) - x(i)) >= 52))
|
||||
labelled.add(i)
|
||||
})
|
||||
return (
|
||||
<Panel box={box} title={title} en={en} id={id}>
|
||||
{Array.from({ length: 5 }, (_, i) => (
|
||||
@@ -318,30 +340,58 @@ function Plot({
|
||||
</text>
|
||||
</g>
|
||||
))}
|
||||
{path ? <path d={path} fill="none" stroke={blue} strokeWidth={2} data-series={id} /> : null}
|
||||
{paths
|
||||
.filter((p) => p.path)
|
||||
.map((p, i) => (
|
||||
<path
|
||||
key={i}
|
||||
d={p.path}
|
||||
fill="none"
|
||||
stroke={color(p.source)}
|
||||
strokeWidth={2}
|
||||
data-series={id}
|
||||
data-series-source={p.source}
|
||||
/>
|
||||
))}
|
||||
{points.map((point, i) => (
|
||||
<g
|
||||
key={point.label}
|
||||
data-source={point.source}
|
||||
data-week={point.week}
|
||||
data-value={point.value ?? undefined}
|
||||
data-frozen={point.frozen === undefined ? undefined : point.frozen ? 'available' : 'missing'}
|
||||
>
|
||||
<title>{point.hint}</title>
|
||||
{point.value !== null ? (
|
||||
<>
|
||||
<circle cx={x(i)} cy={y(point.value)} r={3} fill="#fff" stroke={blue} strokeWidth={1.5} />
|
||||
{points.length <= 14 || i % every === 0 || i === points.length - 1 ? (
|
||||
<text x={x(i)} y={Math.max(top - 9, y(point.value) - 9)} fill={blue} fontSize={10} textAnchor="middle">
|
||||
{percent ? `${point.value.toFixed(1)}%` : number(point.value)}
|
||||
<circle cx={x(i)} cy={y(point.value)} r={3} fill="#fff" stroke={color(point.source)} strokeWidth={1.5} />
|
||||
{labelled.has(i) ? (
|
||||
<text
|
||||
x={x(i)}
|
||||
y={Math.max(top - 9, y(point.value) - 9)}
|
||||
fill={color(point.source)}
|
||||
fontSize={10}
|
||||
textAnchor="middle"
|
||||
>
|
||||
{percent ? `${point.value.toFixed(2)}%` : number(point.value)}
|
||||
</text>
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
{i % every === 0 || i === points.length - 1 ? (
|
||||
{labelled.has(i) ? (
|
||||
<text x={x(i)} y={bottom + 22} textAnchor="middle" fill={muted} fontSize={10}>
|
||||
{point.label}
|
||||
</text>
|
||||
) : null}
|
||||
</g>
|
||||
))}
|
||||
{percent ? (
|
||||
<text x={16} y={box.h - 7} fontSize={9} fill={muted}>
|
||||
{points.some((p) => p.source === 'user_provided_history')
|
||||
? '蓝:用户提供(未提供分子/分母);紫:系统冻结'
|
||||
: '缺失周留空;系统冻结与当前实时结果分开'}
|
||||
</text>
|
||||
) : null}
|
||||
{!points.some((p) => p.value !== null) ? (
|
||||
<text x={(left + right) / 2} y={(top + bottom) / 2} fill={muted} textAnchor="middle" fontSize={12}>
|
||||
{percent ? '暂无冻结快照' : '暂无数据'}
|
||||
@@ -489,19 +539,7 @@ export function QADashboardDrawing({
|
||||
h: 270,
|
||||
},
|
||||
height = mobile ? cursor + 540 + gap + pad : cursor + 270 + pad
|
||||
const frozen = (correctness: boolean): PlotPoint[] =>
|
||||
data.frozen_weeks.map((p) => {
|
||||
const rate = correctness ? p.correctness : p.coverage,
|
||||
week = currentQAWeek(new Date(p.week_start))
|
||||
return {
|
||||
label: `${week.year}W${String(week.week).padStart(2, '0')}`,
|
||||
value: rate.percent,
|
||||
frozen: p.frozen_at !== null,
|
||||
hint: p.frozen_at
|
||||
? `${week.year}年第${week.week}周:${rate.numerator}/${rate.denominator};冻结于 ${p.frozen_at}`
|
||||
: `${week.year}年第${week.week}周:缺少当时冻结快照`,
|
||||
}
|
||||
})
|
||||
const frozen = (correctness: boolean): PlotPoint[] => historicalTrend(data, correctness)
|
||||
const month = new Date(Date.parse(data.month_start) + 8 * 3600000).toISOString().slice(0, 7)
|
||||
return (
|
||||
<svg
|
||||
@@ -519,9 +557,7 @@ export function QADashboardDrawing({
|
||||
background: '#fff',
|
||||
}}
|
||||
>
|
||||
<title>
|
||||
问题统计看板 · {week.year}年第{week.week}周
|
||||
</title>
|
||||
<title>{`问题统计看板 · ${week.year}年第${week.week}周`}</title>
|
||||
<rect width={w} height={height} fill="#fff" />
|
||||
<text x={pad + 6} y={27} fontSize={mobile ? 17 : 21} fontWeight={700} fill={ink}>
|
||||
问题统计看板
|
||||
|
||||
@@ -1,6 +1,36 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { parseQADashboard } from './qaDashboardData'
|
||||
import { dashboardFixture } from './qaDashboard.fixture'
|
||||
const reported = {
|
||||
week: '2026WK40',
|
||||
week_start: '2026-09-28T00:00:00+08:00',
|
||||
week_end: '2026-10-05T00:00:00+08:00',
|
||||
coverage_percent: 57.23,
|
||||
correctness_percent: 92.34,
|
||||
source: 'user_provided_history',
|
||||
}
|
||||
describe('reported historical rates', () => {
|
||||
it('keeps supplied percentages without inventing denominator or freeze time', () => {
|
||||
const result = parseQADashboard({ ...dashboardFixture, reported_weeks: [reported] })
|
||||
expect(result.reported_weeks).toEqual([reported])
|
||||
expect(result.frozen_weeks).toEqual(parseQADashboard(dashboardFixture).frozen_weeks)
|
||||
expect(result.quality).toEqual(parseQADashboard(dashboardFixture).quality)
|
||||
})
|
||||
it('rejects invalid, duplicate, future, wrongly labelled and keyword-scoped supplied history', () => {
|
||||
for (const input of [
|
||||
{ ...dashboardFixture, reported_weeks: [reported, reported] },
|
||||
{ ...dashboardFixture, reported_weeks: [{ ...reported, denominator: 100 }] },
|
||||
{ ...dashboardFixture, reported_weeks: [{ ...reported, coverage_percent: 100.01 }] },
|
||||
{ ...dashboardFixture, reported_weeks: [{ ...reported, correctness_percent: null }] },
|
||||
{ ...dashboardFixture, reported_weeks: [{ ...reported, source: 'frozen' }] },
|
||||
{ ...dashboardFixture, reported_weeks: [{ ...reported, week: '2026WK41' }] },
|
||||
{ ...dashboardFixture, reported_weeks: [{ ...reported, week_end: '2027-01-01T00:00:00+08:00' }] },
|
||||
{ ...dashboardFixture, keyword: 'needle', reported_weeks: [reported] },
|
||||
])
|
||||
expect(() => parseQADashboard(input)).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('complete dashboard data contract', () => {
|
||||
it('keeps distinct cumulative, week, month and genuinely frozen periods', () => {
|
||||
const data = parseQADashboard(dashboardFixture)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { parseQAOrganizationVersion } from './qaOps'
|
||||
import { currentQAWeek } from './qaWeeks'
|
||||
import type { QAOrganizationVersion, QAQuery } from './qaOps'
|
||||
import { parseQualitySummary, parseQualityRate } from './qaQuality'
|
||||
import type { QualitySummary, QualityRate } from './qaQuality'
|
||||
@@ -6,6 +7,14 @@ export interface DashboardCount {
|
||||
label: string
|
||||
count: number
|
||||
}
|
||||
export interface DashboardReported {
|
||||
week: string
|
||||
week_start: string
|
||||
week_end: string
|
||||
coverage_percent: number
|
||||
correctness_percent: number
|
||||
source: 'user_provided_history'
|
||||
}
|
||||
export interface DashboardFrozen {
|
||||
week_start: string
|
||||
week_end: string
|
||||
@@ -41,6 +50,7 @@ export interface QADashboardData {
|
||||
daily: { date: string; count: number }[]
|
||||
regions: DashboardRegion[]
|
||||
frozen_weeks: DashboardFrozen[]
|
||||
reported_weeks: DashboardReported[]
|
||||
}
|
||||
const bad = (): never => {
|
||||
throw new Error('统计看板响应无效,未展示可能失真的指标')
|
||||
@@ -186,6 +196,43 @@ export function parseQADashboard(value: unknown): QADashboardData {
|
||||
(frozen_weeks.length && Date.parse(frozen_weeks[frozen_weeks.length - 1].week_end) < Date.parse(end))
|
||||
)
|
||||
return bad()
|
||||
const reported_weeks = list(v.reported_weeks === undefined ? [] : v.reported_weeks).map((raw, i) => {
|
||||
const p = obj(raw),
|
||||
week = text(p.week),
|
||||
begin = stamp(p.week_start),
|
||||
finish = stamp(p.week_end)
|
||||
const iso = currentQAWeek(new Date(begin))
|
||||
const percent = (value: unknown) =>
|
||||
typeof value === 'number' &&
|
||||
Number.isFinite(value) &&
|
||||
value >= 0 &&
|
||||
value <= 100 &&
|
||||
Math.abs(value * 100 - Math.round(value * 100)) < 1e-8
|
||||
? value
|
||||
: bad()
|
||||
if (
|
||||
Object.keys(p).some(
|
||||
(k) => !['week', 'week_start', 'week_end', 'coverage_percent', 'correctness_percent', 'source'].includes(k)
|
||||
) ||
|
||||
keyword !== '' ||
|
||||
p.source !== 'user_provided_history' ||
|
||||
week !== `${iso.year}WK${String(iso.week).padStart(2, '0')}` ||
|
||||
monday(Date.parse(begin)) !== Date.parse(begin) ||
|
||||
Date.parse(finish) - Date.parse(begin) !== 7 * dayMS ||
|
||||
Date.parse(finish) > Date.parse(end)
|
||||
)
|
||||
return bad()
|
||||
if (i > 0 && Date.parse(begin) <= Date.parse(text(obj(list(v.reported_weeks)[i - 1]).week_start))) return bad()
|
||||
return {
|
||||
week,
|
||||
week_start: begin,
|
||||
week_end: finish,
|
||||
coverage_percent: percent(p.coverage_percent),
|
||||
correctness_percent: percent(p.correctness_percent),
|
||||
source: 'user_provided_history' as const,
|
||||
}
|
||||
})
|
||||
if (reported_weeks.length > 5200) return bad()
|
||||
return {
|
||||
start,
|
||||
end,
|
||||
@@ -193,6 +240,7 @@ export function parseQADashboard(value: unknown): QADashboardData {
|
||||
as_of,
|
||||
week_start,
|
||||
month_start,
|
||||
reported_weeks,
|
||||
local_revision: count(v.local_revision),
|
||||
organization,
|
||||
total_issues,
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { it, expect } from 'vitest'
|
||||
import { parseQADashboard } from './qaDashboardData'
|
||||
import { dashboardFixture } from './qaDashboard.fixture'
|
||||
import { historicalTrend } from './qaHistoricalTrend'
|
||||
it('keeps absent weeks null, preserves supplied precision and never mutates real frozen evidence', () => {
|
||||
const input = parseQADashboard({
|
||||
...dashboardFixture,
|
||||
reported_weeks: [
|
||||
{
|
||||
week: '2026WK38',
|
||||
week_start: '2026-09-14T00:00:00+08:00',
|
||||
week_end: '2026-09-21T00:00:00+08:00',
|
||||
coverage_percent: 57.23,
|
||||
correctness_percent: 92.34,
|
||||
source: 'user_provided_history',
|
||||
},
|
||||
],
|
||||
})
|
||||
const before = JSON.stringify(input)
|
||||
const points = historicalTrend(input, false)
|
||||
expect(points.map((p) => p.week)).toEqual(['2026WK38', '2026WK39', '2026WK40', '2026WK41'])
|
||||
expect(points.map((p) => p.value)).toEqual([57.23, null, null, 50])
|
||||
expect(points[0].source).toBe('user_provided_history')
|
||||
expect(points[3].source).toBe('system_frozen')
|
||||
expect(historicalTrend(input, true)[0].value).toBe(92.34)
|
||||
expect(JSON.stringify(input)).toBe(before)
|
||||
})
|
||||
@@ -0,0 +1,47 @@
|
||||
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'
|
||||
week?: string
|
||||
}
|
||||
// Never manufacture row counts or connect a line across missing weeks/policy changes.
|
||||
export function historicalTrend(data: QADashboardData, correctness: boolean): HistoricalPlotPoint[] {
|
||||
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 starts = [...frozen.keys(), ...reported.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)
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user