去掉看板个人月明细;十一卡悬停和键盘可读的真实统计范围、公式与排除数。 自然月独立计算;跨月周取周一所在月,保留旧周证据和已存周报正文。 验证:make verify;一次性PG全镜像套件-race;真实恢复数据7个月与周报calc_metrics对拍。 真实浏览器十一卡逐项悬停、Tab/Escape、30秒刷新、跨月周、390px和完整PNG通过。 没有写DobotAI源问答、触发付费模型、外发或应用新迁移。
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { qaDailySeries, qaCategorySeries } from './qaDashboard'
|
||||
import { QADashboardView } from './QADashboard'
|
||||
import { QADashboard, QADashboardView } from './QADashboard'
|
||||
import { parseQADashboard } from './qaDashboardData'
|
||||
import { dashboardFixture } from './qaDashboard.fixture'
|
||||
import type { QARecord, QAQuery } from './qaOps'
|
||||
@@ -11,6 +11,11 @@ const records = [
|
||||
{ id: 'b', asked_at: '2026-10-12T16:01:00Z' },
|
||||
] as QARecord[]
|
||||
describe('question dashboard projections', () => {
|
||||
it('does not render the personal monthly details entry on the statistics dashboard', () => {
|
||||
const html = renderToStaticMarkup(<QADashboard query={query} error={null} revision={0} onRetry={vi.fn()} />)
|
||||
expect(html).not.toContain('个人月明细')
|
||||
expect(html).not.toContain('qa-monthly-disclosure')
|
||||
})
|
||||
it('groups by Beijing day and keeps zero days instead of using the browser timezone', () => {
|
||||
expect(qaDailySeries(records, query)).toEqual([
|
||||
{ label: '2026-10-12', count: 1 },
|
||||
|
||||
@@ -5,7 +5,6 @@ import type { QADashboardData } from './qaDashboardData'
|
||||
import { QADashboardDrawing } from './QADashboardDrawing'
|
||||
import { createDashboardPNG } from './qaDashboardExport'
|
||||
import { currentQAWeek } from './qaWeeks'
|
||||
import { QAMonthly } from './QAMonthly'
|
||||
import './qaDashboard.css'
|
||||
export interface QADashboardProps {
|
||||
data: QADashboardData | null
|
||||
@@ -90,8 +89,7 @@ export function QADashboard({
|
||||
}) {
|
||||
const [data, setData] = useState<QADashboardData | null>(null),
|
||||
[failure, setFailure] = useState(''),
|
||||
[loading, setLoading] = useState(false),
|
||||
[monthly, setMonthly] = useState(false)
|
||||
[loading, setLoading] = useState(false)
|
||||
useEffect(() => {
|
||||
setData(null)
|
||||
setFailure('')
|
||||
@@ -127,10 +125,6 @@ export function QADashboard({
|
||||
return (
|
||||
<div className="qa-dashboard-scroll">
|
||||
<QADashboardView data={data} loading={loading} error={error || failure} onRetry={onRetry} />
|
||||
<details className="qa-monthly-disclosure" onToggle={(e) => setMonthly(e.currentTarget.open)}>
|
||||
<summary>个人月明细</summary>
|
||||
{monthly ? <QAMonthly /> : null}
|
||||
</details>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,26 @@ import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import { it, expect } from 'vitest'
|
||||
import { QADashboardDrawing } from './QADashboardDrawing'
|
||||
import { dashboardFixture } from './qaDashboard.fixture'
|
||||
import { calendarDashboardFixture } from './qaDashboardMonthly.fixture'
|
||||
it('keeps the month identifiers intact on a narrow monthly-dashboard heading', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<QADashboardDrawing data={parseQADashboard(calendarDashboardFixture)} width={362} />
|
||||
)
|
||||
expect(html).toContain('区域统计 2026-10 月累计')
|
||||
const accuracy = html.split('data-panel="accuracy-trend"')[1]
|
||||
expect(accuracy).toMatch(/<text[^>]*>2026-09<\/text>/)
|
||||
expect(accuracy).toMatch(/<text[^>]*>—<\/text>/)
|
||||
})
|
||||
import { parseQADashboard } from './qaDashboardData'
|
||||
it('places a keyboard-accessible statistics definition in the upper-right of every card', () => {
|
||||
const html = renderToStaticMarkup(<QADashboardDrawing data={parseQADashboard(dashboardFixture)} width={1280} />)
|
||||
expect((html.match(/data-statistics-help=/g) || []).length).toBe(11)
|
||||
expect((html.match(/统计口径<\/text>/g) || []).length).toBe(11)
|
||||
expect((html.match(/aria-label="[^"]*统计口径[^"]*"/g) || []).length).toBe(11)
|
||||
expect(html).toContain('tabindex="0"')
|
||||
expect(html).toContain('原始提问时间')
|
||||
expect(html).toContain('是÷(是+否)')
|
||||
})
|
||||
it('draws all eleven panels as a self-contained exportable SVG without HTML execution', () => {
|
||||
const html = renderToStaticMarkup(<QADashboardDrawing data={parseQADashboard(dashboardFixture)} width={1280} />)
|
||||
expect((html.match(/data-panel=/g) || []).length).toBe(11)
|
||||
|
||||
+190
-86
@@ -1,4 +1,6 @@
|
||||
import { createContext, useContext, useState } from 'react'
|
||||
import type { ReactNode, Ref } from 'react'
|
||||
import { dashboardStatisticsHelp } from './qaDashboardStatistics'
|
||||
import type { QADashboardData, DashboardCount, DashboardRegion } from './qaDashboardData'
|
||||
import type { QualityRate } from './qaQuality'
|
||||
import { currentQAWeek } from './qaWeeks'
|
||||
@@ -10,6 +12,17 @@ interface Box {
|
||||
w: number
|
||||
h: number
|
||||
}
|
||||
interface StatisticsTip {
|
||||
id: string
|
||||
box: Box
|
||||
baseline: number
|
||||
}
|
||||
const StatisticsContext = createContext<{
|
||||
definitions: Record<string, string>
|
||||
show: (tip: StatisticsTip) => void
|
||||
hide: (id: string) => void
|
||||
active: string | null
|
||||
} | null>(null)
|
||||
const blue = '#3274e6',
|
||||
ink = '#23344d',
|
||||
muted = '#7a8799',
|
||||
@@ -79,6 +92,9 @@ function Panel({
|
||||
children: ReactNode
|
||||
tint?: string
|
||||
}) {
|
||||
const statistics = useContext(StatisticsContext),
|
||||
hint = statistics?.definitions[id] ?? '',
|
||||
baseline = box.w < 140 ? 59 : 25
|
||||
return (
|
||||
<g data-panel={id} transform={`translate(${box.x} ${box.y})`}>
|
||||
<rect width={box.w} height={box.h} rx={7} fill={tint} />
|
||||
@@ -89,6 +105,33 @@ function Panel({
|
||||
{en}
|
||||
</text>
|
||||
{children}
|
||||
<g
|
||||
data-statistics-help={id}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={`${title}统计口径`}
|
||||
aria-describedby={`qa-statistics-description-${id}`}
|
||||
aria-expanded={statistics?.active === id}
|
||||
style={{ cursor: 'help' }}
|
||||
onMouseEnter={() => statistics?.show({ id, box, baseline })}
|
||||
onMouseLeave={() => statistics?.hide(id)}
|
||||
onFocus={() => statistics?.show({ id, box, baseline })}
|
||||
onBlur={() => statistics?.hide(id)}
|
||||
onClick={() => statistics?.show({ id, box, baseline })}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Escape') statistics?.hide(id)
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
statistics?.show({ id, box, baseline })
|
||||
}
|
||||
}}
|
||||
>
|
||||
<desc id={`qa-statistics-description-${id}`}>{hint}</desc>
|
||||
<rect x={box.w - 72} y={baseline - 17} width={62} height={24} rx={3} fill="transparent" />
|
||||
<text x={box.w - 16} y={baseline} textAnchor="end" fontSize={10.5} fill={muted}>
|
||||
统计口径
|
||||
</text>
|
||||
</g>
|
||||
</g>
|
||||
)
|
||||
}
|
||||
@@ -276,6 +319,7 @@ function Plot({
|
||||
id,
|
||||
points,
|
||||
percent = false,
|
||||
monthly = false,
|
||||
}: {
|
||||
box: Box
|
||||
title: string
|
||||
@@ -283,6 +327,7 @@ function Plot({
|
||||
id: string
|
||||
points: PlotPoint[]
|
||||
percent?: boolean
|
||||
monthly?: boolean
|
||||
}) {
|
||||
const left = 44,
|
||||
right = box.w - 22,
|
||||
@@ -293,7 +338,11 @@ function Plot({
|
||||
points.length === 1 ? (left + right) / 2 : left + (i * (right - left)) / Math.max(1, points.length - 1),
|
||||
y = (n: number) => bottom - (n / max) * (bottom - top)
|
||||
const color = (source: PlotPoint['source']) =>
|
||||
source === 'master_live_cumulative_v1' ? '#249c86' : source === 'system_frozen' ? '#8b68c7' : blue
|
||||
source === 'master_live_cumulative_v1' || source === 'master_live_calendar_month_v1'
|
||||
? '#249c86'
|
||||
: source === 'system_frozen'
|
||||
? '#8b68c7'
|
||||
: blue
|
||||
const paths = [...new Set(points.map((p) => p.source))].map((source) => {
|
||||
let path = '',
|
||||
open = false
|
||||
@@ -311,7 +360,7 @@ function Plot({
|
||||
const every = Math.max(1, Math.ceil(points.length / (box.w < 420 ? 5 : 8)))
|
||||
const labelled = new Set<number>()
|
||||
const label = (i: number) => {
|
||||
if (points[i]?.value !== null && points[i] && [...labelled].every((k) => Math.abs(x(k) - x(i)) >= 52))
|
||||
if ((monthly || points[i]?.value !== null) && points[i] && [...labelled].every((k) => Math.abs(x(k) - x(i)) >= 52))
|
||||
labelled.add(i)
|
||||
}
|
||||
label(0)
|
||||
@@ -355,6 +404,7 @@ function Plot({
|
||||
key={point.label}
|
||||
data-source={point.source}
|
||||
data-week={point.week}
|
||||
data-month={point.month}
|
||||
data-value={point.value ?? undefined}
|
||||
data-frozen={point.frozen === undefined ? undefined : point.frozen ? 'available' : 'missing'}
|
||||
>
|
||||
@@ -375,6 +425,11 @@ function Plot({
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
{monthly && point.value === null ? (
|
||||
<text x={x(i)} y={bottom - 9} textAnchor="middle" fill={muted} fontSize={11}>
|
||||
—
|
||||
</text>
|
||||
) : null}
|
||||
{labelled.has(i) ? (
|
||||
<text x={x(i)} y={bottom + 22} textAnchor="middle" fill={muted} fontSize={10}>
|
||||
{point.label}
|
||||
@@ -384,11 +439,13 @@ function Plot({
|
||||
))}
|
||||
{percent ? (
|
||||
<text x={16} y={box.h - 7} fontSize={9} fill={muted}>
|
||||
{points.some((p) => p.source === 'master_live_cumulative_v1')
|
||||
? '蓝:历史上报;紫:系统冻结;绿:总表累计'
|
||||
: points.some((p) => p.source === 'user_provided_history')
|
||||
? '蓝:用户提供(未提供分子/分母);紫:系统冻结'
|
||||
: '缺失周留空;系统冻结与当前实时结果分开'}
|
||||
{monthly
|
||||
? '自然月独立计算 · 当前有效结论 · 空分母留空'
|
||||
: points.some((p) => p.source === 'master_live_cumulative_v1')
|
||||
? '蓝:历史上报;紫:系统冻结;绿:总表累计'
|
||||
: points.some((p) => p.source === 'user_provided_history')
|
||||
? '蓝:用户提供(未提供分子/分母);紫:系统冻结'
|
||||
: '缺失周留空;系统冻结与当前实时结果分开'}
|
||||
</text>
|
||||
) : null}
|
||||
{!points.some((p) => p.value !== null) ? (
|
||||
@@ -477,15 +534,22 @@ export function QADashboardDrawing({
|
||||
width: number
|
||||
svgRef?: Ref<SVGSVGElement>
|
||||
}) {
|
||||
const [tip, setTip] = useState<StatisticsTip | null>(null)
|
||||
const definitions = dashboardStatisticsHelp(data)
|
||||
const w = Math.max(240, Math.round(width)),
|
||||
pad = w < 700 ? 10 : 16,
|
||||
gap = w < 700 ? 12 : 18,
|
||||
inner = w - pad * 2,
|
||||
mobile = w < 700,
|
||||
mobile = w < 900,
|
||||
unit = (inner - gap * 3) / 4,
|
||||
week = currentQAWeek(new Date(data.week_start)),
|
||||
filterLines = wrap(data.keyword ? `关键词:${data.keyword}` : '', inner - 16, 11),
|
||||
header = 62 + (data.keyword ? filterLines.length * 15 : 0),
|
||||
heading = `${data.week_start.slice(0, 10)} 起的自然周${data.quality_period ? ` · 质量 ${data.quality_period.month} 月内累计` : ''} · 区域统计 ${new Date(Date.parse(data.month_start) + 8 * 3600000).toISOString().slice(0, 7)} 月累计`,
|
||||
headingLines = (mobile ? [heading.split(' · ')[0], heading.split(' · ').slice(1).join(' · ')] : [heading]).flatMap(
|
||||
(row) => wrap(row, inner - 16, 10.5)
|
||||
),
|
||||
filterY = 47 + headingLines.length * 14,
|
||||
header = filterY + (data.keyword ? filterLines.length * 15 : 0) + 4,
|
||||
metricH = mobile ? 154 : 166
|
||||
const metrics: Box[] = Array.from({ length: 4 }, (_, i) =>
|
||||
mobile
|
||||
@@ -540,85 +604,125 @@ export function QADashboardDrawing({
|
||||
height = mobile ? cursor + 540 + gap + pad : cursor + 270 + pad
|
||||
const frozen = (correctness: boolean): PlotPoint[] => historicalTrend(data, correctness)
|
||||
const month = new Date(Date.parse(data.month_start) + 8 * 3600000).toISOString().slice(0, 7)
|
||||
const tipWidth = Math.min(334, inner),
|
||||
tipLines = wrap(tip ? definitions[tip.id] : '', tipWidth - 26, 11.5),
|
||||
tipHeight = tipLines.length * 15.525 + 26,
|
||||
tipX = tip ? Math.max(pad, Math.min(w - pad - tipWidth, tip.box.x + tip.box.w - tipWidth - 10)) : 0,
|
||||
tipY = tip ? Math.max(pad, Math.min(height - pad - tipHeight, tip.box.y + tip.baseline + 10)) : 0
|
||||
return (
|
||||
<svg
|
||||
ref={svgRef}
|
||||
className="qa-dashboard-svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="100%"
|
||||
viewBox={`0 0 ${w} ${height}`}
|
||||
role="img"
|
||||
aria-label="完整十一项问题统计看板"
|
||||
style={{
|
||||
display: 'block',
|
||||
fontFamily: 'Arial, "Noto Sans CJK SC", "Microsoft YaHei", sans-serif',
|
||||
fontVariantNumeric: 'tabular-nums',
|
||||
background: '#fff',
|
||||
<StatisticsContext.Provider
|
||||
value={{
|
||||
definitions,
|
||||
show: setTip,
|
||||
hide: (id) => setTip((current) => (current?.id === id ? null : current)),
|
||||
active: tip?.id ?? null,
|
||||
}}
|
||||
>
|
||||
<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}>
|
||||
问题统计看板
|
||||
</text>
|
||||
<text x={w - pad - 6} y={27} textAnchor="end" fontSize={12} fill={muted}>
|
||||
{week.year} · W{String(week.week).padStart(2, '0')}
|
||||
</text>
|
||||
<text x={pad + 6} y={46} fontSize={10.5} fill={muted}>
|
||||
{data.week_start.slice(0, 10)} 起的自然周 · 区域统计 {month} 月累计
|
||||
</text>
|
||||
{data.keyword ? (
|
||||
<Text x={pad + 6} y={62} width={inner - 16} value={`关键词:${data.keyword}`} size={11} fill={muted} />
|
||||
) : null}
|
||||
<Metric
|
||||
box={metrics[0]}
|
||||
title="问题总数"
|
||||
en="Total Issues"
|
||||
id="total"
|
||||
value={data.total_issues}
|
||||
tint="#fff4e2"
|
||||
color="#c69b00"
|
||||
subtitle="所选周截止前累计"
|
||||
/>
|
||||
<Metric
|
||||
box={metrics[1]}
|
||||
title="本周新增"
|
||||
en="New This week"
|
||||
id="new-week"
|
||||
value={data.new_this_week}
|
||||
tint="#ececff"
|
||||
color="#4056d6"
|
||||
subtitle="所选自然周"
|
||||
/>
|
||||
<Gauge box={metrics[2]} title="覆盖率" en="Coverage Rate" id="coverage" rate={data.quality.rates.coverage} />
|
||||
<Gauge box={metrics[3]} title="正确率" en="Accuracy Rate" id="accuracy" rate={data.quality.rates.correctness} />
|
||||
<Pie box={pie} points={data.issue_types} />
|
||||
<Products box={products} points={data.products} />
|
||||
<Plot
|
||||
box={trend}
|
||||
title="问题趋势"
|
||||
en="Issue Trend"
|
||||
id="issue-trend"
|
||||
points={data.daily.map((p) => ({ label: p.date.slice(5), value: p.count, hint: `${p.date}:${p.count} 条` }))}
|
||||
/>
|
||||
<RegionTable box={freq} regions={data.regions} frequency month={month} />
|
||||
<RegionTable box={usage} regions={data.regions} frequency={false} month={month} />
|
||||
<Plot
|
||||
box={coverage}
|
||||
title="覆盖率趋势"
|
||||
en="Coverage Rate Trend"
|
||||
id="coverage-trend"
|
||||
points={frozen(false)}
|
||||
percent
|
||||
/>
|
||||
<Plot
|
||||
box={accuracy}
|
||||
title="正确率趋势"
|
||||
en="Accuracy Rate Trend"
|
||||
id="accuracy-trend"
|
||||
points={frozen(true)}
|
||||
percent
|
||||
/>
|
||||
</svg>
|
||||
<svg
|
||||
ref={svgRef}
|
||||
className="qa-dashboard-svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="100%"
|
||||
viewBox={`0 0 ${w} ${height}`}
|
||||
role="group"
|
||||
aria-label="完整十一项问题统计看板"
|
||||
style={{
|
||||
display: 'block',
|
||||
fontFamily: 'Arial, "Noto Sans CJK SC", "Microsoft YaHei", sans-serif',
|
||||
fontVariantNumeric: 'tabular-nums',
|
||||
background: '#fff',
|
||||
}}
|
||||
>
|
||||
<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}>
|
||||
问题统计看板
|
||||
</text>
|
||||
<text x={w - pad - 6} y={27} textAnchor="end" fontSize={12} fill={muted}>
|
||||
{week.year} · W{String(week.week).padStart(2, '0')}
|
||||
</text>
|
||||
{headingLines.map((row, index) => (
|
||||
<Text key={index} x={pad + 6} y={46 + index * 14} width={inner - 16} size={10.5} fill={muted} value={row} />
|
||||
))}
|
||||
{data.keyword ? (
|
||||
<Text x={pad + 6} y={filterY} width={inner - 16} value={`关键词:${data.keyword}`} size={11} fill={muted} />
|
||||
) : null}
|
||||
<Metric
|
||||
box={metrics[0]}
|
||||
title="问题总数"
|
||||
en="Total Issues"
|
||||
id="total"
|
||||
value={data.total_issues}
|
||||
tint="#fff4e2"
|
||||
color="#c69b00"
|
||||
subtitle="所选周截止前累计"
|
||||
/>
|
||||
<Metric
|
||||
box={metrics[1]}
|
||||
title="本周新增"
|
||||
en="New This week"
|
||||
id="new-week"
|
||||
value={data.new_this_week}
|
||||
tint="#ececff"
|
||||
color="#4056d6"
|
||||
subtitle="所选自然周"
|
||||
/>
|
||||
<Gauge
|
||||
box={metrics[2]}
|
||||
title="覆盖率"
|
||||
en={`Coverage Rate${data.quality_period ? ` · ${data.quality_period.month}` : ''}`}
|
||||
id="coverage"
|
||||
rate={data.monthly_quality?.coverage ?? data.quality.rates.coverage}
|
||||
/>
|
||||
<Gauge
|
||||
box={metrics[3]}
|
||||
title="正确率"
|
||||
en={`Accuracy Rate${data.quality_period ? ` · ${data.quality_period.month}` : ''}`}
|
||||
id="accuracy"
|
||||
rate={data.monthly_quality?.correctness ?? data.quality.rates.correctness}
|
||||
/>
|
||||
<Pie box={pie} points={data.issue_types} />
|
||||
<Products box={products} points={data.products} />
|
||||
<Plot
|
||||
box={trend}
|
||||
title="问题趋势"
|
||||
en="Issue Trend"
|
||||
id="issue-trend"
|
||||
points={data.daily.map((p) => ({ label: p.date.slice(5), value: p.count, hint: `${p.date}:${p.count} 条` }))}
|
||||
/>
|
||||
<RegionTable box={freq} regions={data.regions} frequency month={month} />
|
||||
<RegionTable box={usage} regions={data.regions} frequency={false} month={month} />
|
||||
<Plot
|
||||
box={coverage}
|
||||
title="覆盖率趋势"
|
||||
en="Coverage Rate Trend"
|
||||
id="coverage-trend"
|
||||
points={frozen(false)}
|
||||
monthly={!!data.quality_period}
|
||||
percent
|
||||
/>
|
||||
<Plot
|
||||
box={accuracy}
|
||||
title="正确率趋势"
|
||||
en="Accuracy Rate Trend"
|
||||
id="accuracy-trend"
|
||||
points={frozen(true)}
|
||||
monthly={!!data.quality_period}
|
||||
percent
|
||||
/>
|
||||
{tip ? (
|
||||
<g
|
||||
role="tooltip"
|
||||
data-statistics-tooltip={tip.id}
|
||||
pointerEvents="none"
|
||||
transform={`translate(${tipX} ${tipY})`}
|
||||
>
|
||||
<rect x={2} y={3} width={tipWidth} height={tipHeight} rx={5} fill="#dce4ee" opacity={0.65} />
|
||||
<rect width={tipWidth} height={tipHeight} rx={5} fill="#fff" stroke="#ccd8e8" />
|
||||
<Text x={13} y={22} width={tipWidth - 26} size={11.5} value={definitions[tip.id]} />
|
||||
</g>
|
||||
) : null}
|
||||
</svg>
|
||||
</StatisticsContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { fetchAllQARecords } from './qaOps'
|
||||
import { currentQAWeekValue, qaDateTimeToISO, qaWeekQueryRange } from './qaWeeks'
|
||||
import { WeeklyDraftEditorModel } from './qaWeeklyDrafts'
|
||||
import { weeklyTransport } from './qaWeeklyDraftAPI'
|
||||
import { buildQAWeeklyCSV, downloadQAWeekly } from './qaWeekly'
|
||||
import { buildQAWeeklyCSV, downloadQAWeekly, weeklyQualitySourceLabel } from './qaWeekly'
|
||||
import { QAAnswerMarkdown } from './QAAnswerMarkdown'
|
||||
import { QAPeriodInput } from './QAPeriodInput'
|
||||
import './qaWeeklyEditor.css'
|
||||
@@ -258,10 +258,7 @@ export function QAWeekly({ onBeforeLeave }: Props) {
|
||||
{typeof source.end === 'string'
|
||||
? new Date(source.end).toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai', hour12: false })
|
||||
: '—'}{' '}
|
||||
·{' '}
|
||||
{{ 'live-week': '当周实时质量指标', 'frozen-week': '已冻结周指标', 'reported-history': '历史上报指标' }[
|
||||
String(source.quality_source)
|
||||
] ?? '指标来源未确认'}
|
||||
· {weeklyQualitySourceLabel(source.quality_source)}
|
||||
</p>
|
||||
<p>
|
||||
问题总数与新增是可编辑的系统统计建议;区域采用已保存配置及当前通讯录。未做新的FAQ调整,重点与英文文字请自行填写。草稿不会自动发送。
|
||||
|
||||
+3
-14
@@ -24,20 +24,9 @@
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
.qa-monthly-disclosure {
|
||||
margin-top: 14px;
|
||||
border-top: 1px solid var(--border-base);
|
||||
padding: 14px 0;
|
||||
}
|
||||
.qa-monthly-disclosure > summary {
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.qa-monthly-disclosure .qa-monthly {
|
||||
min-height: 400px;
|
||||
max-height: 650px;
|
||||
margin-top: 12px;
|
||||
overflow: auto;
|
||||
.qa-dashboard-svg [data-statistics-help]:focus-visible {
|
||||
outline: 2px solid #3274e6;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.qa-weekly {
|
||||
display: flex;
|
||||
|
||||
@@ -36,6 +36,28 @@ export interface DashboardCumulative {
|
||||
source: 'master_live_cumulative_v1'
|
||||
policy_version: 'weekly-strict-yes-over-yes-no-v1'
|
||||
}
|
||||
export interface DashboardStrictQuality {
|
||||
records: number
|
||||
coverage: QualityRate
|
||||
correctness: QualityRate
|
||||
}
|
||||
export interface DashboardQualityPeriod {
|
||||
month: string
|
||||
start: string
|
||||
cutoff_at: string
|
||||
calculated_at: string
|
||||
source: 'master_live_calendar_month_v1'
|
||||
policy_version: 'calendar-month-strict-yes-over-yes-no-v1'
|
||||
}
|
||||
export interface DashboardMonth extends DashboardStrictQuality {
|
||||
month: string
|
||||
month_start: string
|
||||
month_end: string
|
||||
cutoff_at: string
|
||||
calculated_at: string
|
||||
source: 'master_live_calendar_month_v1'
|
||||
policy_version: 'calendar-month-strict-yes-over-yes-no-v1'
|
||||
}
|
||||
export interface DashboardRegion {
|
||||
id: string
|
||||
name: string
|
||||
@@ -64,6 +86,9 @@ export interface QADashboardData {
|
||||
frozen_weeks: DashboardFrozen[]
|
||||
reported_weeks: DashboardReported[]
|
||||
cumulative_weeks?: DashboardCumulative[]
|
||||
quality_period?: DashboardQualityPeriod
|
||||
monthly_quality?: DashboardStrictQuality
|
||||
calendar_months?: DashboardMonth[]
|
||||
}
|
||||
const bad = (): never => {
|
||||
throw new Error('统计看板响应无效,未展示可能失真的指标')
|
||||
@@ -305,7 +330,127 @@ export function parseQADashboard(value: unknown): QADashboardData {
|
||||
}
|
||||
}
|
||||
)
|
||||
let quality_period: DashboardQualityPeriod | undefined
|
||||
let monthly_quality: DashboardStrictQuality | undefined
|
||||
let calendar_months: DashboardMonth[] | undefined
|
||||
const monthlySource = 'master_live_calendar_month_v1' as const,
|
||||
monthlyPolicy = 'calendar-month-strict-yes-over-yes-no-v1' as const,
|
||||
nextMonth = (at: number) => {
|
||||
const d = new Date(at + offset)
|
||||
return Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + 1, 1) - offset
|
||||
},
|
||||
monthLabel = (at: number) => new Date(at + offset).toISOString().slice(0, 7),
|
||||
strictRates = (raw: Record<string, unknown>): DashboardStrictQuality => {
|
||||
const records = count(raw.records),
|
||||
coverage = parseQualityRate(raw.coverage),
|
||||
correctness = parseQualityRate(raw.correctness)
|
||||
if (records > total_issues || coverage.denominator > records || correctness.denominator > records) return bad()
|
||||
return { records, coverage, correctness }
|
||||
}
|
||||
if (
|
||||
v.quality_period !== undefined ||
|
||||
v.monthly_quality !== undefined ||
|
||||
(v.calendar_months !== undefined && list(v.calendar_months).length)
|
||||
) {
|
||||
const p = obj(v.quality_period),
|
||||
begin = stamp(p.start),
|
||||
cutoff = stamp(p.cutoff_at),
|
||||
calculated = stamp(p.calculated_at),
|
||||
expectedBegin = month(Date.parse(week_start))
|
||||
if (
|
||||
p.source !== monthlySource ||
|
||||
p.policy_version !== monthlyPolicy ||
|
||||
text(p.month) !== monthLabel(expectedBegin) ||
|
||||
Date.parse(begin) !== expectedBegin ||
|
||||
Date.parse(cutoff) <= expectedBegin ||
|
||||
Date.parse(cutoff) !== Math.min(nextMonth(expectedBegin), Date.parse(end), Date.parse(calculated))
|
||||
)
|
||||
return bad()
|
||||
if (
|
||||
Object.keys(p).some(
|
||||
(key) => !['month', 'start', 'cutoff_at', 'calculated_at', 'source', 'policy_version'].includes(key)
|
||||
)
|
||||
)
|
||||
return bad()
|
||||
const rawQuality = obj(v.monthly_quality)
|
||||
if (Object.keys(rawQuality).some((key) => !['records', 'coverage', 'correctness'].includes(key))) return bad()
|
||||
quality_period = {
|
||||
month: text(p.month),
|
||||
start: begin,
|
||||
cutoff_at: cutoff,
|
||||
calculated_at: calculated,
|
||||
source: monthlySource,
|
||||
policy_version: monthlyPolicy,
|
||||
}
|
||||
monthly_quality = strictRates(rawQuality)
|
||||
const rawMonths = list(v.calendar_months)
|
||||
calendar_months = rawMonths.map((raw, i): DashboardMonth => {
|
||||
const point = obj(raw),
|
||||
month_start = stamp(point.month_start),
|
||||
month_end = stamp(point.month_end),
|
||||
cutoff_at = stamp(point.cutoff_at),
|
||||
calculated_at = stamp(point.calculated_at),
|
||||
at = Date.parse(month_start),
|
||||
rates = strictRates(point)
|
||||
if (
|
||||
at !== month(at) ||
|
||||
text(point.month) !== monthLabel(at) ||
|
||||
Date.parse(month_end) !== nextMonth(at) ||
|
||||
Date.parse(cutoff_at) <= at ||
|
||||
Date.parse(cutoff_at) !== Math.min(Date.parse(month_end), Date.parse(cutoff), Date.parse(calculated_at)) ||
|
||||
calculated_at !== calculated ||
|
||||
point.source !== monthlySource ||
|
||||
point.policy_version !== monthlyPolicy ||
|
||||
(i > 0 && at !== Date.parse(text(obj(rawMonths[i - 1]).month_end)))
|
||||
)
|
||||
return bad()
|
||||
if (
|
||||
Object.keys(point).some(
|
||||
(key) =>
|
||||
![
|
||||
'month',
|
||||
'month_start',
|
||||
'month_end',
|
||||
'cutoff_at',
|
||||
'calculated_at',
|
||||
'records',
|
||||
'coverage',
|
||||
'correctness',
|
||||
'source',
|
||||
'policy_version',
|
||||
].includes(key)
|
||||
)
|
||||
)
|
||||
return bad()
|
||||
return {
|
||||
month: text(point.month),
|
||||
month_start,
|
||||
month_end,
|
||||
cutoff_at,
|
||||
calculated_at,
|
||||
...rates,
|
||||
source: monthlySource,
|
||||
policy_version: monthlyPolicy,
|
||||
}
|
||||
})
|
||||
if (calendar_months.length > 1200 || calendar_months.reduce((n, point) => n + point.records, 0) > total_issues)
|
||||
return bad()
|
||||
const last = calendar_months.at(-1)
|
||||
if (last) {
|
||||
if (
|
||||
last.month !== quality_period.month ||
|
||||
last.cutoff_at !== quality_period.cutoff_at ||
|
||||
last.records !== monthly_quality.records ||
|
||||
JSON.stringify(last.coverage) !== JSON.stringify(monthly_quality.coverage) ||
|
||||
JSON.stringify(last.correctness) !== JSON.stringify(monthly_quality.correctness)
|
||||
)
|
||||
return bad()
|
||||
} else if (monthly_quality.records !== 0) return bad()
|
||||
}
|
||||
return {
|
||||
quality_period,
|
||||
monthly_quality,
|
||||
calendar_months,
|
||||
start,
|
||||
end,
|
||||
keyword,
|
||||
|
||||
@@ -13,6 +13,7 @@ export async function createDashboardPNG(svg: SVGSVGElement): Promise<Blob> {
|
||||
copy.querySelector('foreignObject,image,script,iframe,use')
|
||||
)
|
||||
throw new Error('看板内容不完整,未生成图片')
|
||||
copy.querySelectorAll('[data-statistics-tooltip]').forEach((popover) => popover.remove())
|
||||
copy.setAttribute('width', String(box.width))
|
||||
copy.setAttribute('height', String(box.height))
|
||||
copy.style.width = `${box.width}px`
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { dashboardFixture } from './qaDashboard.fixture'
|
||||
export const calendarDashboardFixture = {
|
||||
...dashboardFixture,
|
||||
quality_period: {
|
||||
month: '2026-10',
|
||||
start: '2026-10-01T00:00:00+08:00',
|
||||
cutoff_at: dashboardFixture.end,
|
||||
calculated_at: dashboardFixture.as_of,
|
||||
source: 'master_live_calendar_month_v1',
|
||||
policy_version: 'calendar-month-strict-yes-over-yes-no-v1',
|
||||
},
|
||||
monthly_quality: {
|
||||
records: 3,
|
||||
coverage: { numerator: 2, denominator: 3, percent: 200 / 3 },
|
||||
correctness: { numerator: 1, denominator: 2, percent: 50 },
|
||||
},
|
||||
calendar_months: [
|
||||
{
|
||||
month: '2026-09',
|
||||
month_start: '2026-09-01T00:00:00+08:00',
|
||||
month_end: '2026-10-01T00:00:00+08:00',
|
||||
cutoff_at: '2026-10-01T00:00:00+08:00',
|
||||
calculated_at: dashboardFixture.as_of,
|
||||
records: 1,
|
||||
coverage: { numerator: 0, denominator: 1, percent: 0 },
|
||||
correctness: { numerator: 0, denominator: 0, percent: null },
|
||||
source: 'master_live_calendar_month_v1',
|
||||
policy_version: 'calendar-month-strict-yes-over-yes-no-v1',
|
||||
},
|
||||
{
|
||||
month: '2026-10',
|
||||
month_start: '2026-10-01T00:00:00+08:00',
|
||||
month_end: '2026-11-01T00:00:00+08:00',
|
||||
cutoff_at: dashboardFixture.end,
|
||||
calculated_at: dashboardFixture.as_of,
|
||||
records: 3,
|
||||
coverage: { numerator: 2, denominator: 3, percent: 200 / 3 },
|
||||
correctness: { numerator: 1, denominator: 2, percent: 50 },
|
||||
source: 'master_live_calendar_month_v1',
|
||||
policy_version: 'calendar-month-strict-yes-over-yes-no-v1',
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { it, expect } from 'vitest'
|
||||
import { parseQADashboard } from './qaDashboardData'
|
||||
import { calendarDashboardFixture as fixture } from './qaDashboardMonthly.fixture'
|
||||
import { historicalTrend } from './qaHistoricalTrend'
|
||||
it('uses month-axis points and leaves unknown rates empty instead of reusing weekly snapshots', () => {
|
||||
const data = parseQADashboard(fixture)
|
||||
const coverage = historicalTrend(data, false),
|
||||
accuracy = historicalTrend(data, true)
|
||||
expect(coverage.map((p) => p.label)).toEqual(['2026-09', '2026-10'])
|
||||
expect(accuracy.map((p) => p.value)).toEqual([null, 50])
|
||||
expect(coverage.every((p) => p.source === 'master_live_calendar_month_v1')).toBe(true)
|
||||
expect(coverage[1].hint).toContain('是÷(是+否)')
|
||||
expect(accuracy[0].hint).toContain('月内 1 条')
|
||||
})
|
||||
it('rejects extra private payload fields in every calendar-month projection', () => {
|
||||
for (const input of [
|
||||
{ ...fixture, quality_period: { ...fixture.quality_period, answer: 'not part of statistics' } },
|
||||
{ ...fixture, monthly_quality: { ...fixture.monthly_quality, staff_id: 'not part of statistics' } },
|
||||
{
|
||||
...fixture,
|
||||
calendar_months: fixture.calendar_months.map((p, i) => (i ? p : { ...p, payload: 'not part of statistics' })),
|
||||
},
|
||||
])
|
||||
expect(() => parseQADashboard(input)).toThrow()
|
||||
})
|
||||
it('parses independent calendar-month strict rates without restricting correctness to covered rows', () => {
|
||||
const data = parseQADashboard(fixture)
|
||||
expect(data).toHaveProperty('quality_period', fixture.quality_period)
|
||||
expect(data).toHaveProperty('monthly_quality', fixture.monthly_quality)
|
||||
expect(data).toHaveProperty('calendar_months', fixture.calendar_months)
|
||||
})
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { QADashboardData } from './qaDashboardData'
|
||||
const beijing = (at: string) => new Date(Date.parse(at) + 8 * 3600000).toISOString().slice(0, 19).replace('T', ' ')
|
||||
const windowText = (start: string, end: string) => `北京时间 ${beijing(start)} 至 ${beijing(end)}(终点不含)。`
|
||||
export function dashboardStatisticsHelp(data: QADashboardData): Record<string, string> {
|
||||
const filter = '沿用已执行关键词筛选。',
|
||||
week = windowText(data.start, data.end),
|
||||
regionMonth = windowText(data.month_start, data.end),
|
||||
period = data.quality_period,
|
||||
rates = data.monthly_quality,
|
||||
qualityRange = period ? windowText(period.start, period.cutoff_at) : week,
|
||||
qualityRecords = rates?.records ?? data.quality.total,
|
||||
coverage = rates?.coverage ?? data.quality.rates.coverage,
|
||||
correctness = rates?.correctness ?? data.quality.rates.correctness,
|
||||
calendar =
|
||||
'每月1日重新累计,不累计之前月份,不平均周百分比;按原始提问时间归月,使用当前有效结论及点踩否,空分母留空。',
|
||||
qualityScope = period
|
||||
? `统计月 ${period.month}。跨月周取周一所在月;当前未结束只截至实际时点。`
|
||||
: '旧接口按所选查询范围统计。'
|
||||
return {
|
||||
total: `截至北京时间 ${beijing(data.end)}(不含),治理总表历史导入和2.0收录的去重问题记录数,共 ${data.total_issues} 条;不把当前页条数当总数,不因缺少分析字段排除。${filter}`,
|
||||
'new-week': `${windowText(data.week_start, data.end)}本周新增=原始提问时间落在本自然周内的问题数,共 ${data.new_this_week} 条;当前周截至当前,不按导入时间算新增。${filter}`,
|
||||
coverage: `${qualityScope}${qualityRange}${rates ? '覆盖率=覆盖是÷(是+否)×100%。部分覆盖、待确认、未知、空白、失效等不计分母。' : '旧覆盖率=覆盖是÷(覆盖是+覆盖否+部分覆盖)×100%。'}本范围 ${qualityRecords} 条;分子 ${coverage.numerator},分母 ${coverage.denominator},排除 ${qualityRecords - coverage.denominator} 条。${filter}`,
|
||||
accuracy: `${qualityScope}${qualityRange}${rates ? '正确率=正确是÷(是+否)×100%;不限定仅已覆盖问题。' : '旧正确率=已覆盖样本内的正确是÷(是+否)×100%。'}本范围 ${qualityRecords} 条;分子 ${correctness.numerator},分母 ${correctness.denominator},排除 ${qualityRecords - correctness.denominator} 条。待确认、未知、空白、失效等排除;已判定样本正确率不代表全部问题已确认。${filter}`,
|
||||
'issue-types': `${week}按本查询范围内每条问题的当前有效“问题类型”归组,每条计1次;缺失保留“未分类”。饼图占比=该类型条数÷范围内 ${data.quality.total} 条×100%。${filter}`,
|
||||
products: `${week}按当前有效“产品分类”归组,每条问题计1次,数量降序;缺失保留“未分类”,不与问题类型混用。范围共 ${data.quality.total} 条。${filter}`,
|
||||
'issue-trend': `${windowText(data.week_start, data.end)}按原始提问时间在北京时间逐日计数,零提问日保留;各日合计=本周新增 ${data.new_this_week} 条,不按导入日计算。${filter}`,
|
||||
frequency: `${regionMonth}区域平均使用频率=能稳定关联该区域的月内提问条数÷当前配置通讯录去重人数。缺失/待核对身份不强行归属,零分母显示“—”;当前名册不是在职或绩效名单。${filter}`,
|
||||
'usage-coverage': `${regionMonth}区域使用覆盖率=月内稳定身份去重使用人数÷同一区域当前配置通讯录去重人数×100%。零使用者保留在分母,无法关联者不凑人数;无名单或零分母显示“—”,不是绩效结论。${filter}`,
|
||||
'coverage-trend': period
|
||||
? `每个点是一个北京时间自然月,覆盖率=覆盖是÷(是+否)×100%。${calendar}最后截止北京时间 ${beijing(period.cutoff_at)}(不含)。旧周上报/冻结仅保留证据,不混入月曲线。${filter}`
|
||||
: `旧接口逐自然周分别保留上报、冻结及总表累计来源;不把旧周百分比换算成月比例。${filter}`,
|
||||
'accuracy-trend': period
|
||||
? `每个点是一个北京时间自然月,正确率=正确是÷(是+否)×100%;待确认等排除,各点保留月内条数及分子/分母。${calendar}最后截止北京时间 ${beijing(period.cutoff_at)}(不含)。${filter}`
|
||||
: `旧接口逐周保留来源;正确是÷(是+否),缺失留空,不复制当前比例凑历史曲线。${filter}`,
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,24 @@ export interface HistoricalPlotPoint {
|
||||
value: number | null
|
||||
hint: string
|
||||
frozen?: boolean
|
||||
source?: 'user_provided_history' | 'system_frozen' | 'master_live_cumulative_v1'
|
||||
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]))
|
||||
|
||||
@@ -2,7 +2,11 @@ import { describe, it, expect } from 'vitest'
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import { createElement } from 'react'
|
||||
import { QAAnswerMarkdown } from './QAAnswerMarkdown'
|
||||
import { buildQAWeeklyDraft } from './qaWeekly'
|
||||
import { buildQAWeeklyDraft, weeklyQualitySourceLabel } from './qaWeekly'
|
||||
it('identifies the calendar-month prefill policy rather than labelling it unknown or weekly', () => {
|
||||
expect(weeklyQualitySourceLabel('master_live_calendar_month_v1')).toBe('自然月累计质量指标(跨月周按上月)')
|
||||
expect(weeklyQualitySourceLabel('reported-history')).toBe('历史上报指标')
|
||||
})
|
||||
import type { QARecordPage, QAQuery } from './qaOps'
|
||||
import type { QualitySummary } from './qaQuality'
|
||||
const query: QAQuery = { start: '2026-10-11T16:00:00Z', end: '2026-10-18T10:00:00Z', keyword: '', cursor: '' }
|
||||
|
||||
@@ -2,6 +2,16 @@ import type { QARecordPage, QAQuery } from './qaOps'
|
||||
import { qaCellValue, qaColumns } from './qaOps'
|
||||
import type { QualitySummary, QualityRate } from './qaQuality'
|
||||
import { qaDailySeries, qaCategorySeries } from './qaDashboard'
|
||||
export function weeklyQualitySourceLabel(source: unknown): string {
|
||||
return (
|
||||
new Map([
|
||||
['live-week', '当周实时质量指标'],
|
||||
['frozen-week', '已冻结周指标'],
|
||||
['reported-history', '历史上报指标'],
|
||||
['master_live_calendar_month_v1', '自然月累计质量指标(跨月周按上月)'],
|
||||
]).get(String(source)) ?? '指标来源未确认'
|
||||
)
|
||||
}
|
||||
export interface QAWeeklyDraft {
|
||||
markdown: string
|
||||
csv: string
|
||||
|
||||
Reference in New Issue
Block a user