feat(qa-ops): 增加北京时间自然周年份与周次筛选
按确认口径展示周次及起止日期,处理跨年、52/53周和本周截至当前。保留自定义时间及查询操作,固定UTC+8边界,不改后端源查询。 验证:目标日期、非法53周、北京时间解析、本周截止及渲染回归均先红后绿;前端266通过,完整make verify成功;洛杉矶时区真实浏览器核对查询UTC边界、切年、自定义和390px布局通过,JS异常0。
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- 问答记录新增年份与自然周选择,周次展示起止日期,支持跨年及每年实际周数;按北京时间周一至周日填入查询范围,默认本周且仅查询截至当前的数据。保留自定义时间与原查询按钮,浏览器时区不改变查询边界。
|
||||||
|
|
||||||
- 问答运营按已确认口径显示知识覆盖率、回答正确率及原始分子/分母、排除数量与构成。使用完整筛选范围和当前有效人工优先结论,精确规则命中的未覆盖可进入覆盖分母;部分覆盖不算完全覆盖,待确认/未评估/失效/不计入按对应指标排除,零分母显示“暂无可计算数据”。返回独立规则版本,AI 模型与绩效范围仍未接入。
|
- 问答运营按已确认口径显示知识覆盖率、回答正确率及原始分子/分母、排除数量与构成。使用完整筛选范围和当前有效人工优先结论,精确规则命中的未覆盖可进入覆盖分母;部分覆盖不算完全覆盖,待确认/未评估/失效/不计入按对应指标排除,零分母显示“暂无可计算数据”。返回独立规则版本,AI 模型与绩效范围仍未接入。
|
||||||
|
|
||||||
- 问答详情支持治理侧人工复核及不可变审计:覆盖、正确性、产品分类、问题类型、根因与理由由管理员明确填写,操作人取登录身份;保存后独立读回复核历史。保留源端判断和自动规则,输入变化使旧人工结论失效,已观测的内容回退不自动恢复旧结论;并发修改冲突、重复请求不重复留档。
|
- 问答详情支持治理侧人工复核及不可变审计:覆盖、正确性、产品分类、问题类型、根因与理由由管理员明确填写,操作人取登录身份;保存后独立读回复核历史。保留源端判断和自动规则,输入变化使旧人工结论失效,已观测的内容回退不自动恢复旧结论;并发修改冲突、重复请求不重复留档。
|
||||||
|
|||||||
+29
-15
@@ -10,6 +10,8 @@ import { QAMonthly } from './QAMonthly'
|
|||||||
import { QAQualityEditor, QAQualityCounts } from './QAQuality'
|
import { QAQualityEditor, QAQualityCounts } from './QAQuality'
|
||||||
import { qualityLabels } from './qaQuality'
|
import { qualityLabels } from './qaQuality'
|
||||||
import { usageLabels } from './qaUsage'
|
import { usageLabels } from './qaUsage'
|
||||||
|
import { QAWeekPicker } from './QAWeekPicker'
|
||||||
|
import { currentQAWeek, qaDateTimeToISO, qaWeekQueryRange } from './qaWeeks'
|
||||||
|
|
||||||
interface ViewProps {
|
interface ViewProps {
|
||||||
onQualitySaved?: (record: QARecord) => void
|
onQualitySaved?: (record: QARecord) => void
|
||||||
@@ -290,12 +292,10 @@ export function QAOperationsView(props: ViewProps) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function localInput(value: Date): string {
|
|
||||||
return new Date(value.getTime() - value.getTimezoneOffset() * 60_000).toISOString().slice(0, 16)
|
|
||||||
}
|
|
||||||
function initialDraft() {
|
function initialDraft() {
|
||||||
const end = new Date()
|
const current = currentQAWeek()
|
||||||
return { start: localInput(new Date(end.getTime() - 7 * 24 * 3600_000)), end: localInput(end), keyword: '' }
|
const { year, week, start, end } = qaWeekQueryRange(current.year, current.week)
|
||||||
|
return { year, week: week as number | null, start, end, keyword: '' }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function QAOperations() {
|
export function QAOperations() {
|
||||||
@@ -322,8 +322,8 @@ export function QAOperations() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!canRead || query) return
|
if (!canRead || query) return
|
||||||
setQuery({
|
setQuery({
|
||||||
start: new Date(draft.start).toISOString(),
|
start: qaDateTimeToISO(draft.start),
|
||||||
end: new Date(draft.end).toISOString(),
|
end: qaDateTimeToISO(draft.end),
|
||||||
keyword: draft.keyword,
|
keyword: draft.keyword,
|
||||||
cursor: '',
|
cursor: '',
|
||||||
})
|
})
|
||||||
@@ -377,10 +377,11 @@ export function QAOperations() {
|
|||||||
const submit = (event: FormEvent) => {
|
const submit = (event: FormEvent) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
try {
|
try {
|
||||||
const start = new Date(draft.start),
|
const start = qaDateTimeToISO(draft.start),
|
||||||
end = new Date(draft.end)
|
end = qaDateTimeToISO(draft.end)
|
||||||
if (!(start < end)) throw new Error('开始时间必须早于结束时间')
|
if (!(Date.parse(start) < Date.parse(end))) throw new Error('开始时间必须早于结束时间')
|
||||||
setQuery({ start: start.toISOString(), end: end.toISOString(), keyword: draft.keyword, cursor: '' })
|
if (Date.parse(start) >= Date.now()) throw new Error('所选周或时间尚未开始,请选择已开始的时间范围')
|
||||||
|
setQuery({ start, end, keyword: draft.keyword, cursor: '' })
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
setError(reason instanceof Error ? reason.message : '时间格式无效')
|
setError(reason instanceof Error ? reason.message : '时间格式无效')
|
||||||
}
|
}
|
||||||
@@ -470,22 +471,35 @@ export function QAOperations() {
|
|||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<form className="qa-ops-query" onSubmit={submit}>
|
<form className="qa-ops-query" onSubmit={submit}>
|
||||||
|
{view === 'records' ? (
|
||||||
|
<QAWeekPicker
|
||||||
|
year={draft.year}
|
||||||
|
week={draft.week}
|
||||||
|
onChange={(year, week) => {
|
||||||
|
setDraft((old) => {
|
||||||
|
if (week === null) return { ...old, year, week }
|
||||||
|
const { start, end } = qaWeekQueryRange(year, week)
|
||||||
|
return { ...old, year, week, start, end }
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
<label>
|
<label>
|
||||||
开始时间
|
开始时间(北京时间)
|
||||||
<input
|
<input
|
||||||
type="datetime-local"
|
type="datetime-local"
|
||||||
required
|
required
|
||||||
value={draft.start}
|
value={draft.start}
|
||||||
onChange={(event) => setDraft({ ...draft, start: event.target.value })}
|
onChange={(event) => setDraft({ ...draft, start: event.target.value, week: null })}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
结束时间(不含)
|
结束时间(北京时间,不含)
|
||||||
<input
|
<input
|
||||||
type="datetime-local"
|
type="datetime-local"
|
||||||
required
|
required
|
||||||
value={draft.end}
|
value={draft.end}
|
||||||
onChange={(event) => setDraft({ ...draft, end: event.target.value })}
|
onChange={(event) => setDraft({ ...draft, end: event.target.value, week: null })}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label className="qa-ops-keyword">
|
<label className="qa-ops-keyword">
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { renderToStaticMarkup } from 'react-dom/server'
|
||||||
|
import { describe, expect, it, vi } from 'vitest'
|
||||||
|
import { QAWeekPicker } from './QAWeekPicker'
|
||||||
|
|
||||||
|
describe('QA week picker', () => {
|
||||||
|
it('shows a year and numbered weeks with visible inclusive date ranges', () => {
|
||||||
|
const html = renderToStaticMarkup(<QAWeekPicker year={2026} week={40} onChange={vi.fn()} />)
|
||||||
|
expect(html).toContain('aria-label="年份"')
|
||||||
|
expect(html).toContain('2026年')
|
||||||
|
expect(html).toContain('aria-label="周次"')
|
||||||
|
expect(html).toContain('value="40" selected=""')
|
||||||
|
expect(html).toContain('第40周(09-28 到 10-04)')
|
||||||
|
expect(html).toContain('第53周(2026-12-28 到 2027-01-03)')
|
||||||
|
expect(html).toContain('北京时间')
|
||||||
|
expect(html).toContain('周一至周日')
|
||||||
|
})
|
||||||
|
it('preserves custom range mode and does not offer invalid week 53', () => {
|
||||||
|
const html = renderToStaticMarkup(<QAWeekPicker year={2027} week={null} onChange={vi.fn()} />)
|
||||||
|
expect(html).toContain('value="" selected=""')
|
||||||
|
expect(html).toContain('自定义时间')
|
||||||
|
expect(html).not.toContain('第53周')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { currentQAWeek, qaWeek, qaWeeksInYear } from './qaWeeks'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
year: number
|
||||||
|
week: number | null
|
||||||
|
onChange: (year: number, week: number | null) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function QAWeekPicker({ year, week, onChange }: Props) {
|
||||||
|
const currentYear = currentQAWeek().year
|
||||||
|
const firstYear = Math.min(currentYear - 5, year)
|
||||||
|
const lastYear = Math.max(currentYear + 1, year)
|
||||||
|
return (
|
||||||
|
<div className="qa-week-picker" role="group" aria-label="按周选择">
|
||||||
|
<label>
|
||||||
|
年份
|
||||||
|
<select
|
||||||
|
aria-label="年份"
|
||||||
|
value={year}
|
||||||
|
onChange={(event) => {
|
||||||
|
const nextYear = Number(event.target.value)
|
||||||
|
onChange(nextYear, Math.min(week ?? 1, qaWeeksInYear(nextYear)))
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{Array.from({ length: lastYear - firstYear + 1 }, (_, i) => firstYear + i)
|
||||||
|
.reverse()
|
||||||
|
.map((value) => (
|
||||||
|
<option key={value} value={value}>
|
||||||
|
{value}年
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
周次
|
||||||
|
<select
|
||||||
|
aria-label="周次"
|
||||||
|
value={week ?? ''}
|
||||||
|
onChange={(event) => onChange(year, event.target.value === '' ? null : Number(event.target.value))}
|
||||||
|
>
|
||||||
|
<option value="">自定义时间</option>
|
||||||
|
{Array.from({ length: qaWeeksInYear(year) }, (_, i) => i + 1).map((value) => (
|
||||||
|
<option key={value} value={value}>
|
||||||
|
{qaWeek(year, value).label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<span className="qa-ops-muted">北京时间 · 周一至周日 · 本周截至当前</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
+21
-1
@@ -163,7 +163,8 @@
|
|||||||
color: var(--ink-mute);
|
color: var(--ink-mute);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
.qa-ops-query input {
|
.qa-ops-query input,
|
||||||
|
.qa-week-picker select {
|
||||||
min-height: 36px;
|
min-height: 36px;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
padding: 7px 10px;
|
padding: 7px 10px;
|
||||||
@@ -172,6 +173,24 @@
|
|||||||
border-radius: var(--r-sm);
|
border-radius: var(--r-sm);
|
||||||
background: var(--bg-panel);
|
background: var(--bg-panel);
|
||||||
}
|
}
|
||||||
|
.qa-week-picker {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: end;
|
||||||
|
flex-basis: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
.qa-week-picker label {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.qa-week-picker select {
|
||||||
|
max-width: 100%;
|
||||||
|
font: inherit;
|
||||||
|
}
|
||||||
|
.qa-week-picker > span {
|
||||||
|
padding-bottom: 8px;
|
||||||
|
}
|
||||||
.qa-ops-keyword {
|
.qa-ops-keyword {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 170px;
|
min-width: 170px;
|
||||||
@@ -185,6 +204,7 @@
|
|||||||
}
|
}
|
||||||
.qa-ops button:focus-visible,
|
.qa-ops button:focus-visible,
|
||||||
.qa-ops input:focus-visible,
|
.qa-ops input:focus-visible,
|
||||||
|
.qa-ops select:focus-visible,
|
||||||
.qa-ops-table-scroll:focus-visible {
|
.qa-ops-table-scroll:focus-visible {
|
||||||
outline: 2px solid var(--c-run);
|
outline: 2px solid var(--c-run);
|
||||||
outline-offset: 2px;
|
outline-offset: 2px;
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import { currentQAWeek, qaDateTimeToISO, qaWeek, qaWeeksInYear, qaWeekQueryRange } from './qaWeeks'
|
||||||
|
|
||||||
|
describe('QA natural-week query ranges', () => {
|
||||||
|
it('caps the in-progress week at now but leaves completed weeks intact', () => {
|
||||||
|
const now = new Date('2026-10-18T06:00:00Z')
|
||||||
|
expect(qaWeekQueryRange(2026, 42, now).end).toBe('2026-10-18T14:00')
|
||||||
|
expect(qaWeekQueryRange(2026, 40, now).end).toBe('2026-10-05T00:00')
|
||||||
|
expect(qaWeekQueryRange(2026, 53, now).start).toBe('2026-12-28T00:00')
|
||||||
|
})
|
||||||
|
it('resolves the current ISO week at the Beijing midnight boundary', () => {
|
||||||
|
expect(currentQAWeek(new Date('2026-10-18T15:59:00Z'))).toMatchObject({ year: 2026, week: 42 })
|
||||||
|
expect(currentQAWeek(new Date('2026-10-18T16:01:00Z'))).toMatchObject({ year: 2026, week: 43 })
|
||||||
|
expect(currentQAWeek(new Date('2027-01-01T12:00:00Z'))).toMatchObject({ year: 2026, week: 53 })
|
||||||
|
})
|
||||||
|
it('converts Beijing form input to UTC without relying on the browser timezone', () => {
|
||||||
|
expect(qaDateTimeToISO('2026-09-28T00:00')).toBe('2026-09-27T16:00:00.000Z')
|
||||||
|
expect(qaDateTimeToISO('2026-10-05T00:00')).toBe('2026-10-04T16:00:00.000Z')
|
||||||
|
for (const input of ['', '2026-02-30T00:00', '2026-10-04', '2026-10-04T24:00', 'invalid']) {
|
||||||
|
expect(() => qaDateTimeToISO(input)).toThrow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
it('counts only the valid weeks for each year', () => {
|
||||||
|
expect(qaWeeksInYear(2026)).toBe(53)
|
||||||
|
expect(qaWeeksInYear(2027)).toBe(52)
|
||||||
|
expect(qaWeeksInYear(2020)).toBe(53)
|
||||||
|
expect(qaWeeksInYear(2021)).toBe(52)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows week dates inclusively and queries through the exclusive next Monday', () => {
|
||||||
|
expect(qaWeek(2026, 40)).toEqual({
|
||||||
|
year: 2026,
|
||||||
|
week: 40,
|
||||||
|
start: '2026-09-28T00:00',
|
||||||
|
end: '2026-10-05T00:00',
|
||||||
|
label: '第40周(09-28 到 10-04)',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
it('rejects nonexistent weeks instead of spilling into the next year', () => {
|
||||||
|
expect(() => qaWeek(2027, 53)).toThrow()
|
||||||
|
for (const week of [0, -1, 54, 1.5, Number.NaN]) expect(() => qaWeek(2026, week)).toThrow()
|
||||||
|
for (const year of [0, 2026.5, Number.NaN]) expect(() => qaWeek(year, 1)).toThrow()
|
||||||
|
})
|
||||||
|
it('keeps the ISO week-year and shows years on crossing ranges', () => {
|
||||||
|
expect(qaWeek(2026, 1)).toMatchObject({
|
||||||
|
start: '2025-12-29T00:00',
|
||||||
|
end: '2026-01-05T00:00',
|
||||||
|
label: '第1周(2025-12-29 到 2026-01-04)',
|
||||||
|
})
|
||||||
|
expect(qaWeek(2026, 53)).toMatchObject({
|
||||||
|
start: '2026-12-28T00:00',
|
||||||
|
end: '2027-01-04T00:00',
|
||||||
|
label: '第53周(2026-12-28 到 2027-01-03)',
|
||||||
|
})
|
||||||
|
expect(qaWeek(2024, 9)).toMatchObject({ start: '2024-02-26T00:00', end: '2024-03-04T00:00' })
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
export interface QAWeek {
|
||||||
|
year: number
|
||||||
|
week: number
|
||||||
|
start: string
|
||||||
|
end: string
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const day = 86_400_000
|
||||||
|
const dateOnly = (value: number) => new Date(value).toISOString().slice(0, 10)
|
||||||
|
|
||||||
|
export function currentQAWeek(now = new Date()): QAWeek {
|
||||||
|
const beijing = new Date(now.getTime() + 8 * 3_600_000)
|
||||||
|
beijing.setUTCHours(0, 0, 0, 0)
|
||||||
|
beijing.setUTCDate(beijing.getUTCDate() + 3 - ((beijing.getUTCDay() + 6) % 7))
|
||||||
|
const year = beijing.getUTCFullYear()
|
||||||
|
const week = Math.floor((beijing.getTime() - firstMonday(year)) / (7 * day)) + 1
|
||||||
|
return qaWeek(year, week)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function qaDateTimeToISO(value: string): string {
|
||||||
|
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/.test(value)) throw new Error('时间格式无效')
|
||||||
|
const parsed = new Date(`${value}:00+08:00`)
|
||||||
|
if (
|
||||||
|
!Number.isFinite(parsed.getTime()) ||
|
||||||
|
new Date(parsed.getTime() + 8 * 3_600_000).toISOString().slice(0, 16) !== value
|
||||||
|
) {
|
||||||
|
throw new Error('时间格式无效')
|
||||||
|
}
|
||||||
|
return parsed.toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function qaWeekQueryRange(year: number, week: number, now = new Date()): QAWeek {
|
||||||
|
const range = qaWeek(year, week)
|
||||||
|
if (
|
||||||
|
Date.parse(qaDateTimeToISO(range.start)) < now.getTime() &&
|
||||||
|
now.getTime() < Date.parse(qaDateTimeToISO(range.end))
|
||||||
|
) {
|
||||||
|
return { ...range, end: new Date(now.getTime() + 8 * 3_600_000).toISOString().slice(0, 16) }
|
||||||
|
}
|
||||||
|
return range
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstMonday = (year: number) => {
|
||||||
|
const jan4 = new Date(Date.UTC(year, 0, 4))
|
||||||
|
return jan4.getTime() - ((jan4.getUTCDay() + 6) % 7) * day
|
||||||
|
}
|
||||||
|
|
||||||
|
export function qaWeeksInYear(year: number): number {
|
||||||
|
if (!Number.isInteger(year) || year < 1900 || year > 9998) throw new Error('年份无效')
|
||||||
|
return (firstMonday(year + 1) - firstMonday(year)) / (7 * day)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function qaWeek(year: number, week: number): QAWeek {
|
||||||
|
if (!Number.isInteger(week) || week < 1 || week > qaWeeksInYear(year)) throw new Error('周次无效')
|
||||||
|
const start = firstMonday(year) + (week - 1) * 7 * day
|
||||||
|
const first = dateOnly(start)
|
||||||
|
const last = dateOnly(start + 6 * day)
|
||||||
|
const crossYear = first.slice(0, 4) !== String(year) || last.slice(0, 4) !== String(year)
|
||||||
|
return {
|
||||||
|
year,
|
||||||
|
week,
|
||||||
|
start: `${first}T00:00`,
|
||||||
|
end: `${dateOnly(start + 7 * day)}T00:00`,
|
||||||
|
label: `第${week}周(${crossYear ? first : first.slice(5)} 到 ${crossYear ? last : last.slice(5)})`,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user