以治理库单一只读事务分开聚合累计、自然周、截止月及当前通讯录使用分母;浏览器不再读取全量长答案来构建看板。 新增迁移52与普通worker周质量冻结,保留真实冻结时点、规则和标量贡献;缺少当时快照留空。提交后冻结头与贡献不可修改、删除或追加;只读接口保留管理员、固定租户、严格JSON与输入冲突保护。 已验证:make verify退出0,686个Go用例和305个前端用例通过,必需跳过0;镜像与组织隔离PostgreSQL竞态回归退出0。真实治理副本浏览器核对第41周累计1885与新增471、十一项和完整PNG下载,390px无外溢、JS异常0;明确模拟503后不伪零且重试恢复。没有修改DobotAI原始问答、真实区域规则或生产发布门禁。
This commit is contained in:
+74
-172
@@ -1,219 +1,121 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import type { QARecordPage, QAQuery } from './qaOps'
|
||||
import type { QualitySummary, QualityRate } from './qaQuality'
|
||||
import type { QAUsage } from './qaUsage'
|
||||
import { fetchQAUsage, usageLabels } from './qaUsage'
|
||||
import { qaDailySeries, qaCategorySeries, fetchQADashboardQuality } from './qaDashboard'
|
||||
import type { QACountPoint } from './qaDashboard'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import type { QAQuery } from './qaOps'
|
||||
import { fetchQADashboard } from './qaDashboardData'
|
||||
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 {
|
||||
page: QARecordPage | null
|
||||
query: QAQuery | null
|
||||
quality: QualitySummary | null
|
||||
usage: QAUsage | null
|
||||
data: QADashboardData | null
|
||||
loading: boolean
|
||||
error: string
|
||||
onRetry: () => void
|
||||
}
|
||||
const percent = (r: QualityRate | undefined) => (r?.percent == null ? '—' : `${r.percent.toFixed(1)}%`)
|
||||
function Bars({ points }: { points: QACountPoint[] }) {
|
||||
const max = Math.max(1, ...points.map((p) => p.count))
|
||||
return points.length ? (
|
||||
<div className="qa-chart-bars">
|
||||
{points.map((p) => (
|
||||
<div className="qa-chart-bar" key={p.label}>
|
||||
<span title={p.label}>{p.label}</span>
|
||||
<div className="qa-chart-track">
|
||||
<i style={{ width: `${(p.count / max) * 100}%` }} />
|
||||
</div>
|
||||
<b>{p.count}</b>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="qa-chart-empty">暂无数据</p>
|
||||
)
|
||||
}
|
||||
export function QADashboardView(p: QADashboardProps) {
|
||||
const page = p.loading ? null : p.page,
|
||||
items = page?.items || [],
|
||||
q = page && p.quality?.summary.total === page.total ? p.quality : null
|
||||
const b = q?.summary.rates.breakdown
|
||||
const daily = page && p.query ? qaDailySeries(items, p.query) : []
|
||||
const max = Math.max(1, ...daily.map((d) => d.count))
|
||||
const outcomes = b
|
||||
? [
|
||||
['已覆盖', b.covered],
|
||||
['未覆盖', b.uncovered],
|
||||
['部分覆盖', b.partial],
|
||||
['待确认', b.pending],
|
||||
['未评估', b.unassessed],
|
||||
['不计入', b.excluded],
|
||||
['待重新核对', b.stale],
|
||||
].map(([label, count]) => ({ label: String(label), count: Number(count) }))
|
||||
: []
|
||||
export function QADashboardView({ data, loading, error, onRetry }: QADashboardProps) {
|
||||
const host = useRef<HTMLDivElement>(null),
|
||||
svg = useRef<SVGSVGElement>(null)
|
||||
const [width, setWidth] = useState(1280),
|
||||
[exporting, setExporting] = useState(false),
|
||||
[exportError, setExportError] = useState('')
|
||||
useEffect(() => {
|
||||
const element = host.current
|
||||
if (!element) return
|
||||
const update = () => setWidth(Math.max(240, Math.floor(element.clientWidth)))
|
||||
update()
|
||||
const observer = new ResizeObserver(update)
|
||||
observer.observe(element)
|
||||
return () => observer.disconnect()
|
||||
}, [])
|
||||
useEffect(() => setExportError(''), [data])
|
||||
async function download() {
|
||||
if (!svg.current || !data || loading || error || exporting) return
|
||||
setExporting(true)
|
||||
setExportError('')
|
||||
try {
|
||||
const blob = await createDashboardPNG(svg.current),
|
||||
url = URL.createObjectURL(blob),
|
||||
link = document.createElement('a'),
|
||||
week = currentQAWeek(new Date(data.week_start))
|
||||
link.href = url
|
||||
link.download = `DobotAI_QA_Dashboard_${week.year}_W${String(week.week).padStart(2, '0')}.png`
|
||||
document.body.append(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
window.setTimeout(() => URL.revokeObjectURL(url), 1000)
|
||||
} catch (e) {
|
||||
setExportError(e instanceof Error ? e.message : '看板图片生成失败')
|
||||
} finally {
|
||||
setExporting(false)
|
||||
}
|
||||
}
|
||||
return (
|
||||
<section className="qa-dashboard" aria-label="问题统计看板">
|
||||
{p.error ? (
|
||||
<div className="qa-dashboard-toolbar">
|
||||
<button type="button" disabled={!data || loading || !!error || exporting} onClick={() => void download()}>
|
||||
{exporting ? '正在生成图片…' : '导出看板图片'}
|
||||
</button>
|
||||
</div>
|
||||
{error ? (
|
||||
<div role="alert" className="error-banner">
|
||||
{p.error}{' '}
|
||||
<button type="button" onClick={p.onRetry}>
|
||||
{error}{' '}
|
||||
<button type="button" onClick={onRetry}>
|
||||
重新读取
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
{p.loading ? <p role="status">正在读取完整统计范围…</p> : null}
|
||||
<div className="qa-dashboard-metrics" aria-label="问题概览">
|
||||
<div>
|
||||
<span>问题总量</span>
|
||||
<strong>{page?.total ?? '—'}</strong>
|
||||
<small>条</small>
|
||||
{exportError ? (
|
||||
<div role="alert" className="error-banner">
|
||||
{exportError}
|
||||
</div>
|
||||
<div>
|
||||
<span>知识覆盖率</span>
|
||||
<strong>{percent(q?.summary.rates.coverage)}</strong>
|
||||
<small>
|
||||
{q ? `${q.summary.rates.coverage.numerator} / ${q.summary.rates.coverage.denominator}` : '分子 / 分母'}
|
||||
</small>
|
||||
</div>
|
||||
<div>
|
||||
<span>回答正确率</span>
|
||||
<strong>{percent(q?.summary.rates.correctness)}</strong>
|
||||
<small>
|
||||
{q
|
||||
? `${q.summary.rates.correctness.numerator} / ${q.summary.rates.correctness.denominator}`
|
||||
: '分子 / 分母'}
|
||||
</small>
|
||||
</div>
|
||||
<div>
|
||||
<span>已人工复核</span>
|
||||
<strong>{q?.summary.reviewed ?? '—'}</strong>
|
||||
<small>{q ? `待复核 ${q.summary.unreviewed}` : '条'}</small>
|
||||
</div>
|
||||
</div>
|
||||
<div className="qa-dashboard-grid">
|
||||
<section className="qa-chart qa-chart-wide">
|
||||
<h3>每日提问趋势</h3>
|
||||
{daily.length ? (
|
||||
<div className="qa-daily-chart" role="img" aria-label="北京时间每日提问量">
|
||||
{daily.map((d) => (
|
||||
<div key={d.label} title={`${d.label}:${d.count} 条`}>
|
||||
<b>{d.count}</b>
|
||||
<div>
|
||||
<i style={{ height: `${(d.count / max) * 100}%` }} />
|
||||
</div>
|
||||
<span>{d.label.slice(5)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="qa-chart-empty">暂无数据</p>
|
||||
)}
|
||||
</section>
|
||||
<section className="qa-chart">
|
||||
<h3>质量分布</h3>
|
||||
<Bars points={outcomes} />
|
||||
</section>
|
||||
<section className="qa-chart qa-chart-wide">
|
||||
<h3>区域分布</h3>
|
||||
<Bars
|
||||
points={
|
||||
p.usage?.rows
|
||||
.filter((r) => r.questions > 0)
|
||||
.map((r) => ({ label: usageLabels[r.key] || r.key, count: r.questions })) || []
|
||||
}
|
||||
/>
|
||||
{p.usage ? (
|
||||
<div className="qa-dashboard-region-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>区域</th>
|
||||
<th>提问量</th>
|
||||
<th>已关联使用人数</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{p.usage.rows
|
||||
.filter((r) => r.questions > 0 || r.roster_people !== null)
|
||||
.map((r) => (
|
||||
<tr key={r.key}>
|
||||
<td>{usageLabels[r.key] || r.key}</td>
|
||||
<td>{r.questions}</td>
|
||||
<td>{r.users ?? '—'}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
<section className="qa-chart">
|
||||
<h3>问题类型</h3>
|
||||
<Bars points={qaCategorySeries(items, 'problem_type')} />
|
||||
</section>
|
||||
<section className="qa-chart qa-chart-full">
|
||||
<h3>产品分类</h3>
|
||||
<Bars points={qaCategorySeries(items, 'product_category')} />
|
||||
</section>
|
||||
) : null}
|
||||
{loading ? <p role="status">正在读取完整统计范围…</p> : null}
|
||||
<div className="qa-dashboard-canvas" ref={host}>
|
||||
{!loading && !error && data ? <QADashboardDrawing data={data} width={width} svgRef={svg} /> : null}
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
export function QADashboard({
|
||||
page,
|
||||
query,
|
||||
loading,
|
||||
error,
|
||||
revision,
|
||||
onRetry,
|
||||
}: {
|
||||
page: QARecordPage | null
|
||||
query: QAQuery | null
|
||||
loading: boolean
|
||||
error: string | null
|
||||
revision: number
|
||||
onRetry: () => void
|
||||
}) {
|
||||
const [quality, setQuality] = useState<QualitySummary | null>(null),
|
||||
[usage, setUsage] = useState<QAUsage | null>(null),
|
||||
const [data, setData] = useState<QADashboardData | null>(null),
|
||||
[failure, setFailure] = useState(''),
|
||||
[loading, setLoading] = useState(false),
|
||||
[monthly, setMonthly] = useState(false)
|
||||
useEffect(() => {
|
||||
setQuality(null)
|
||||
setUsage(null)
|
||||
setData(null)
|
||||
setFailure('')
|
||||
if (!query) return
|
||||
if (!query) {
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
const abort = new AbortController()
|
||||
void fetchQADashboardQuality(query, abort.signal)
|
||||
setLoading(true)
|
||||
void fetchQADashboard(query, abort.signal)
|
||||
.then((v) => {
|
||||
if (!abort.signal.aborted) setQuality(v)
|
||||
if (!abort.signal.aborted) setData(v)
|
||||
})
|
||||
.catch((e) => {
|
||||
if (!abort.signal.aborted) setFailure(e instanceof Error ? e.message : '质量统计读取失败')
|
||||
if (!abort.signal.aborted) setFailure(e instanceof Error ? e.message : '统计看板读取失败')
|
||||
})
|
||||
void fetchQAUsage(query, abort.signal)
|
||||
.then((v) => {
|
||||
if (!abort.signal.aborted) setUsage(v)
|
||||
})
|
||||
.catch((e) => {
|
||||
if (!abort.signal.aborted) setFailure(e instanceof Error ? e.message : '区域统计读取失败')
|
||||
.finally(() => {
|
||||
if (!abort.signal.aborted) setLoading(false)
|
||||
})
|
||||
return () => abort.abort()
|
||||
}, [query, revision])
|
||||
const mismatch = !!page && !!quality && page.total !== quality.summary.total
|
||||
return (
|
||||
<div className="qa-dashboard-scroll">
|
||||
<QADashboardView
|
||||
page={page}
|
||||
query={query}
|
||||
quality={quality}
|
||||
usage={usage}
|
||||
loading={loading}
|
||||
error={error || failure || (mismatch ? '统计范围已更新,请重新查询' : '')}
|
||||
onRetry={onRetry}
|
||||
/>
|
||||
<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}
|
||||
|
||||
Reference in New Issue
Block a user