diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9e4a212..2559756 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -76,6 +76,14 @@
> `0.1.12`),由 `scripts/version.py` 从 git **算出来**;开发交付的独立说明写入本文件“开发快照”章节,并打 `snapshot/vX.Y.Z` 注释标签 ⇒ 每次开发交付均可追溯,
> 但"发布版本"仍然只能由人定(CI 不会自动升版本、不会打 tag)。
+## 开发快照 snapshot/v0.1.44 - 2026-10-21
+
+### Changed
+
+- 问题统计看板去掉个人月明细入口,十一张卡片右上角新增“统计口径”,悬停、键盘聚焦及触屏可查看实际范围、公式与排除数量;图片导出保留完整十一项及口径入口,不包含交互浮层。
+- 覆盖率与正确率趋势改为北京时间逐自然月独立计算,每月1日重新累计;使用总表当前有效结论、人工优先及点踩否,分别按是÷(是+否)计算,待确认等排除,空月/零分母留空。旧周上报、冻结及第40–43周累计证据保留,不再混画到月轴。
+- 每周看板的两项质量仪表与新建/主动重新预填周报使用月内累计;跨月周取周一所在月并截止该月底,非跨月周截止该周实际时点,当前周不预读未来。保留已保存周报正文、修订与重试标识,不自动改写旧稿,不修改源问答或触发付费模型及对外发送。
+
## 开发快照 snapshot/v0.1.43 - 2026-10-20
### Added
diff --git a/api/openapi.yaml b/api/openapi.yaml
index e3b1822..94a2263 100644
--- a/api/openapi.yaml
+++ b/api/openapi.yaml
@@ -125,7 +125,7 @@
"get": {"tags":["QA operations"],"operationId":"getQAOrganizationSync","summary":"管理员读取通讯录同步执行器状态及最近任务的安全汇总,不返回人员名单或运行配置","responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"仅管理员"},"500":{"$ref":"#/components/responses/InternalError"},"503":{"description":"状态存储不可用,不伪装为空记录"}}},
"post": {"tags":["QA operations"],"operationId":"startQAOrganizationSync","summary":"管理员同源发起持久化通讯录同步;重复请求重放同一任务,进行中任务合并;失败保留现有快照","parameters":[{"$ref":"#/components/parameters/IdempotencyKey"},{"name":"X-Governance-Action","in":"header","required":true,"schema":{"const":"qa-organization"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":false}}}},"responses":{"202":{"$ref":"#/components/responses/OperationEnvelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"仅管理员同源操作"},"409":{"description":"操作标识与原请求冲突"},"500":{"$ref":"#/components/responses/InternalError"},"503":{"description":"同步未接线、执行器离线或入队失败;未创建新任务"}}}
},
- "/api/v1/qa-ops/dashboard": {"post":{"operationId":"readQAOperationsDashboard","tags":["QA operations"],"summary":"管理员只读正式总表一致性看板:累计、所选周及区域统计;第40–43周动态累计、历史上报与真实冻结分别保留","description":"同一只读可重复读事务读取独立正式总表有效字段、质量及组织版本。不访问源端,不冻结或写入指标;区域分母为当前配置通讯录去重人数而非在职/绩效名单。冻结记录按保存的原始标量分子分母及问题文字支持字面关键词筛选,不用当前评估回填历史。reported_weeks 独立返回用户提供的历史百分比(QAReportedHistoricalRate),没有分子分母或冻结时间;只含所选截止前已结束周,关键词非空时为空,原冻结记录与当前指标保持不变。cumulative_weeks 独立返回2026WK40–WK43的master_live_cumulative_v1实时累计曲线,policy_version为weekly-strict-yes-over-yes-no-v1:各周成员为整张总表中提问时间早于北京时间下周一的记录,当前周截止min(查询end,事务当前时点),不被查询start截断;字段取当前有效结论,补值和后续点踩会追溯更新相关累计周。覆盖率与正确率分别按是÷(是+否),待确认/部分覆盖及其他值不入严格分母,零分母percent=null;各点保留成员数、两组分子分母、周边界、实际截止和计算时点。仅查询治理本地总表,不写历史上报/冻结证据;网页30秒顺序刷新,已闭查询周不推进到后周。","parameters":[{"name":"X-Governance-Action","in":"header","required":true,"schema":{"const":"qa-dashboard"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":false,"required":["start","end"],"properties":{"start":{"type":"string","format":"date-time"},"end":{"type":"string","format":"date-time"},"keyword":{"type":"string","maxLength":200}}}}}},"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"仅管理员同源读取"},"409":{"description":"质量输入指纹变化,拒绝混合数据"},"500":{"$ref":"#/components/responses/InternalError"},"503":{"description":"本地副本或一致性投影不可用,不返回伪零"}}}},
+ "/api/v1/qa-ops/dashboard": {"post":{"operationId":"readQAOperationsDashboard","tags":["QA operations"],"summary":"管理员只读正式总表一致性看板:累计数量、自然月质量及区域统计;跨月周展示上月月报","description":"同一只读可重复读事务读取独立正式总表有效字段、质量及组织版本。不访问源端,不冻结或写入指标;区域分母为当前配置通讯录去重人数而非在职/绩效名单。冻结记录按保存的原始标量分子分母及问题文字支持字面关键词筛选,不用当前评估回填历史。reported_weeks 独立返回用户提供的历史百分比(QAReportedHistoricalRate),没有分子分母或冻结时间;只含所选截止前已结束周,关键词非空时为空,原冻结记录与当前指标保持不变。cumulative_weeks 独立返回2026WK40–WK43的master_live_cumulative_v1实时累计曲线,policy_version为weekly-strict-yes-over-yes-no-v1:各周成员为整张总表中提问时间早于北京时间下周一的记录,当前周截止min(查询end,事务当前时点),不被查询start截断;字段取当前有效结论,补值和后续点踩会追溯更新相关累计周。覆盖率与正确率分别按是÷(是+否),待确认/部分覆盖及其他值不入严格分母,零分母percent=null;各点保留成员数、两组分子分母、周边界、实际截止和计算时点。仅查询治理本地总表,不写历史上报/冻结证据。新增 quality_period(统计月、月初、实际截止、计算时点及规则)和 monthly_quality(该月内成员数、独立覆盖及正确率分子分母);以所选周周一所在月为质量归属月,跨月周截止该月下月1日,非跨月周截止查询end,均不超过事务当前时点。calendar_months 返回从首个总表数据月起逐自然月独立计算的月点,policy_version=calendar-month-strict-yes-over-yes-no-v1,source=master_live_calendar_month_v1;每月重置,使用当前有效字段,待确认等排除,零分母null,空月保留,最后点与仪表使用相同截止。旧 reported_weeks、frozen_weeks、cumulative_weeks 保留但不混画到月轴;不平均旧周百分比。网页30秒顺序刷新,已闭查询周不推进到后周。","parameters":[{"name":"X-Governance-Action","in":"header","required":true,"schema":{"const":"qa-dashboard"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":false,"required":["start","end"],"properties":{"start":{"type":"string","format":"date-time"},"end":{"type":"string","format":"date-time"},"keyword":{"type":"string","maxLength":200}}}}}},"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"仅管理员同源读取"},"409":{"description":"质量输入指纹变化,拒绝混合数据"},"500":{"$ref":"#/components/responses/InternalError"},"503":{"description":"本地副本或一致性投影不可用,不返回伪零"}}}},
"/api/v1/qa-ops/organization": {
"get": {
"tags": ["QA operations"],
diff --git a/internal/qaopsmirror/dashboard.go b/internal/qaopsmirror/dashboard.go
index 01d6173..3017848 100644
--- a/internal/qaopsmirror/dashboard.go
+++ b/internal/qaopsmirror/dashboard.go
@@ -60,6 +60,9 @@ type Dashboard struct {
FrozenWeeks []DashboardFrozen `json:"frozen_weeks"`
ReportedWeeks []DashboardReported `json:"reported_weeks"`
CumulativeWeeks []DashboardCumulative `json:"cumulative_weeks"`
+ QualityPeriod *DashboardQualityPeriod `json:"quality_period,omitempty"`
+ MonthlyQuality *DashboardStrictQuality `json:"monthly_quality,omitempty"`
+ CalendarMonths []DashboardMonth `json:"calendar_months"`
}
var dashboardLocation = time.FixedZone("Asia/Shanghai", 8*60*60)
diff --git a/internal/qaopsmirror/dashboard_cumulative.go b/internal/qaopsmirror/dashboard_cumulative.go
index 2c969a2..97868b4 100644
--- a/internal/qaopsmirror/dashboard_cumulative.go
+++ b/internal/qaopsmirror/dashboard_cumulative.go
@@ -23,25 +23,25 @@ type DashboardCumulative struct {
PolicyVersion string `json:"policy_version"`
}
-// Membership closes at each week's cutoff; labels deliberately stay live. This is
-// not a frozen snapshot and must never replace the older reported/frozen evidence.
-func (s *Store) readMasterCumulativeDashboard(ctx context.Context, tx pgx.Tx, keyword string, end time.Time) ([]DashboardCumulative, error) {
- out := []DashboardCumulative{}
+type dashboardTimedQuality struct {
+ at time.Time
+ view qaopsquality.View
+}
+
+// Resolve effective labels once in the same read-only repeatable-read snapshot.
+// Both legacy cumulative evidence and calendar-month statistics share this input.
+func (s *Store) readMasterQualityTimeline(ctx context.Context, tx pgx.Tx, keyword string, end time.Time) ([]dashboardTimedQuality, time.Time, error) {
var now time.Time
if e := tx.QueryRow(ctx, "SELECT transaction_timestamp()").Scan(&now); e != nil {
- return nil, e
+ return nil, now, e
}
cutoff := end
if now.Before(cutoff) {
cutoff = now
}
- first := time.Date(2026, time.September, 28, 0, 0, 0, 0, dashboardLocation)
- if !first.Before(cutoff) {
- return out, nil
- }
rows, e := tx.Query(ctx, `SELECT id,asked_at,quality_hash,effective_fields,inline_fields,coverage_result,current_feedback FROM qa_ops_master_read_model WHERE tenant_key=$1 AND asked_at<$2 AND ($3='' OR position(lower($3) IN lower(question||E'\n'||chinese_question||E'\n'||COALESCE(ai_fields->>'question_chinese','')))>0) ORDER BY asked_at,id LIMIT 100001`, s.tenant, cutoff, keyword)
if e != nil {
- return nil, dobotaiops.ErrUnavailable
+ return nil, now, dobotaiops.ErrUnavailable
}
records := []dashboardRecord{}
keys := []dobotaiops.QualityKey{}
@@ -50,11 +50,11 @@ func (s *Store) readMasterCumulativeDashboard(ctx context.Context, tx pgx.Tx, ke
var f, ed, cov, fb []byte
if e = rows.Scan(&r.id, &r.at, &r.hash, &f, &ed, &cov, &fb); e != nil {
rows.Close()
- return nil, e
+ return nil, now, e
}
if json.Unmarshal(f, &r.fields) != nil || json.Unmarshal(ed, &r.edits) != nil || json.Unmarshal(cov, &r.coverage) != nil || json.Unmarshal(fb, &r.feedback) != nil {
rows.Close()
- return nil, dobotaiops.ErrUnavailable
+ return nil, now, dobotaiops.ErrUnavailable
}
records = append(records, r)
keys = append(keys, dobotaiops.QualityKey{ID: r.id, InputHash: r.hash})
@@ -62,23 +62,49 @@ func (s *Store) readMasterCumulativeDashboard(ctx context.Context, tx pgx.Tx, ke
e = rows.Err()
rows.Close()
if e != nil {
- return nil, e
+ return nil, now, e
}
if len(records) > dobotaiops.MaxMirrorRecords {
- return nil, dobotaiops.ErrInvalidQuery
+ return nil, now, dobotaiops.ErrInvalidQuery
}
views := map[string]qaopsquality.View{}
store := qaopsquality.NewStore(s.pool, s.tenant+"::master")
for begin := 0; begin < len(keys); begin += 5000 {
- limit := min(begin+5000, len(keys))
- part, e := store.ReadViewsInTx(ctx, tx, keys[begin:limit])
+ part, e := store.ReadViewsInTx(ctx, tx, keys[begin:min(begin+5000, len(keys))])
if e != nil {
- return nil, e
+ return nil, now, e
}
for id, v := range part {
views[id] = v
}
}
+ out := make([]dashboardTimedQuality, 0, len(records))
+ for _, r := range records {
+ v, ok := views[r.id]
+ if !ok {
+ return nil, now, qaopsquality.ErrUnavailable
+ }
+ out = append(out, dashboardTimedQuality{at: r.at, view: qaopsquality.ProjectMasterWithEdits(v, r.fields, r.coverage, r.edits, r.feedback)})
+ }
+ return out, now, nil
+}
+
+// Membership closes at each week's cutoff; labels deliberately stay live. This is
+// not a frozen snapshot and must never replace older reported/frozen evidence.
+func (s *Store) readMasterCumulativeDashboard(ctx context.Context, tx pgx.Tx, keyword string, end time.Time) ([]DashboardCumulative, error) {
+ records, now, e := s.readMasterQualityTimeline(ctx, tx, keyword, end)
+ if e != nil {
+ return nil, e
+ }
+ return dashboardCumulativeFromTimeline(records, end, now), nil
+}
+func dashboardCumulativeFromTimeline(records []dashboardTimedQuality, end, now time.Time) []DashboardCumulative {
+ out := []DashboardCumulative{}
+ cutoff := end
+ if now.Before(cutoff) {
+ cutoff = now
+ }
+ first := time.Date(2026, time.September, 28, 0, 0, 0, 0, dashboardLocation)
for i := 0; i < 4; i++ {
start := first.AddDate(0, 0, 7*i)
if !start.Before(cutoff) {
@@ -90,37 +116,8 @@ func (s *Store) readMasterCumulativeDashboard(ctx context.Context, tx pgx.Tx, ke
until = cutoff
}
year, week := start.ISOWeek()
- point := DashboardCumulative{Week: fmt.Sprintf("%dWK%02d", year, week), WeekStart: start, WeekEnd: finish, CutoffAt: until, CalculatedAt: now, Source: "master_live_cumulative_v1", PolicyVersion: "weekly-strict-yes-over-yes-no-v1"}
- covered, uncovered, correct, incorrect := 0, 0, 0, 0
- for _, r := range records {
- if !r.at.Before(until) {
- continue
- }
- point.Records++
- v, ok := views[r.id]
- if !ok {
- return nil, qaopsquality.ErrUnavailable
- }
- v = qaopsquality.ProjectMasterWithEdits(v, r.fields, r.coverage, r.edits, r.feedback)
- if v.State == "stale" {
- continue
- }
- switch v.Effective.Coverage {
- case "covered":
- covered++
- case "uncovered":
- uncovered++
- }
- switch v.Effective.Correctness {
- case "correct":
- correct++
- case "incorrect":
- incorrect++
- }
- }
- point.Coverage = dashboardRate(covered, covered+uncovered)
- point.Correctness = dashboardRate(correct, correct+incorrect)
- out = append(out, point)
+ rates := dashboardStrictQuality(records, time.Time{}, until)
+ out = append(out, DashboardCumulative{Week: fmt.Sprintf("%dWK%02d", year, week), WeekStart: start, WeekEnd: finish, CutoffAt: until, CalculatedAt: now, Records: rates.Records, Coverage: rates.Coverage, Correctness: rates.Correctness, Source: "master_live_cumulative_v1", PolicyVersion: "weekly-strict-yes-over-yes-no-v1"})
}
- return out, nil
+ return out
}
diff --git a/internal/qaopsmirror/dashboard_monthly.go b/internal/qaopsmirror/dashboard_monthly.go
new file mode 100644
index 0000000..a330990
--- /dev/null
+++ b/internal/qaopsmirror/dashboard_monthly.go
@@ -0,0 +1,107 @@
+package qaopsmirror
+
+import (
+ "knowledge-governance/internal/qaopsquality"
+ "time"
+)
+
+const dashboardMonthlySource = "master_live_calendar_month_v1"
+const dashboardMonthlyPolicy = "calendar-month-strict-yes-over-yes-no-v1"
+
+type DashboardQualityPeriod struct {
+ Month string `json:"month"`
+ Start time.Time `json:"start"`
+ CutoffAt time.Time `json:"cutoff_at"`
+ CalculatedAt time.Time `json:"calculated_at"`
+ Source string `json:"source"`
+ PolicyVersion string `json:"policy_version"`
+}
+type DashboardStrictQuality struct {
+ Records int `json:"records"`
+ Coverage qaopsquality.Rate `json:"coverage"`
+ Correctness qaopsquality.Rate `json:"correctness"`
+}
+type DashboardMonth struct {
+ Month string `json:"month"`
+ MonthStart time.Time `json:"month_start"`
+ MonthEnd time.Time `json:"month_end"`
+ CutoffAt time.Time `json:"cutoff_at"`
+ CalculatedAt time.Time `json:"calculated_at"`
+ Source string `json:"source"`
+ PolicyVersion string `json:"policy_version"`
+ DashboardStrictQuality
+}
+
+// The weekly skill uses strict yes/(yes+no) independently for each metric.
+// In particular, correctness is NOT restricted to covered questions and partial
+// coverage is NOT a negative vote. Keep the old Summary policy unchanged.
+func dashboardStrictQuality(records []dashboardTimedQuality, start, end time.Time) DashboardStrictQuality {
+ out := DashboardStrictQuality{}
+ covered, uncovered, correct, incorrect := 0, 0, 0, 0
+ for _, r := range records {
+ if r.at.Before(start) || !r.at.Before(end) {
+ continue
+ }
+ out.Records++
+ if r.view.State == "stale" {
+ continue
+ }
+ switch r.view.Effective.Coverage {
+ case "covered":
+ covered++
+ case "uncovered":
+ uncovered++
+ }
+ switch r.view.Effective.Correctness {
+ case "correct":
+ correct++
+ case "incorrect":
+ incorrect++
+ }
+ }
+ out.Coverage = dashboardRate(covered, covered+uncovered)
+ out.Correctness = dashboardRate(correct, correct+incorrect)
+ return out
+}
+
+func dashboardCalendarMonths(records []dashboardTimedQuality, end, now time.Time) []DashboardMonth {
+ out := []DashboardMonth{}
+ cutoff := end
+ if now.Before(cutoff) {
+ cutoff = now
+ }
+ var first time.Time
+ for _, r := range records {
+ if r.at.Before(cutoff) && (first.IsZero() || r.at.Before(first)) {
+ first = r.at
+ }
+ }
+ if first.IsZero() {
+ return out
+ }
+ first = first.In(dashboardLocation)
+ begin := time.Date(first.Year(), first.Month(), 1, 0, 0, 0, 0, dashboardLocation)
+ for ; begin.Before(cutoff); begin = begin.AddDate(0, 1, 0) {
+ finish := begin.AddDate(0, 1, 0)
+ until := finish
+ if cutoff.Before(until) {
+ until = cutoff
+ }
+ out = append(out, DashboardMonth{Month: begin.Format("2006-01"), MonthStart: begin, MonthEnd: finish, CutoffAt: until, CalculatedAt: now, Source: dashboardMonthlySource, PolicyVersion: dashboardMonthlyPolicy, DashboardStrictQuality: dashboardStrictQuality(records, begin, until)})
+ }
+ return out
+}
+
+// dashboardQualityMonth resolves the quality month for a selected week.
+func dashboardQualityMonth(start, end, now time.Time) (time.Time, time.Time) {
+ weekMonday := dashboardWeek(start)
+ month := time.Date(weekMonday.Year(), weekMonday.Month(), 1, 0, 0, 0, 0, dashboardLocation)
+ cutoff := month.AddDate(0, 1, 0)
+ if end.Before(cutoff) {
+ cutoff = end
+ }
+ if now.Before(cutoff) {
+ cutoff = now
+ }
+ return month, cutoff
+}
diff --git a/internal/qaopsmirror/dashboard_monthly_test.go b/internal/qaopsmirror/dashboard_monthly_test.go
new file mode 100644
index 0000000..cf0ca58
--- /dev/null
+++ b/internal/qaopsmirror/dashboard_monthly_test.go
@@ -0,0 +1,33 @@
+package qaopsmirror
+
+import (
+ "testing"
+ "time"
+)
+
+func monthlyTestTime(t *testing.T, value string) time.Time {
+ t.Helper()
+ at, err := time.Parse(time.RFC3339, value)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return at
+}
+
+func TestQualityMonthCrossingWeekIsPreviousMonthReport(t *testing.T) {
+ for _, c := range []struct{ name, start, end, now, wantStart, wantEnd string }{
+ {"cross-month", "2026-09-28T00:00:00+08:00", "2026-10-05T00:00:00+08:00", "2026-10-21T08:00:00+08:00", "2026-09-01T00:00:00+08:00", "2026-10-01T00:00:00+08:00"},
+ {"within-month", "2026-10-05T00:00:00+08:00", "2026-10-12T00:00:00+08:00", "2026-10-21T08:00:00+08:00", "2026-10-01T00:00:00+08:00", "2026-10-12T00:00:00+08:00"},
+ {"current-week-clamps-now", "2026-10-19T00:00:00+08:00", "2026-10-26T00:00:00+08:00", "2026-10-21T08:00:00+08:00", "2026-10-01T00:00:00+08:00", "2026-10-21T08:00:00+08:00"},
+ {"cross-year", "2025-12-29T00:00:00+08:00", "2026-01-05T00:00:00+08:00", "2026-10-21T08:00:00+08:00", "2025-12-01T00:00:00+08:00", "2026-01-01T00:00:00+08:00"},
+ {"utc-same-boundary", "2026-09-27T16:00:00Z", "2026-10-04T16:00:00Z", "2026-10-21T00:00:00Z", "2026-09-01T00:00:00+08:00", "2026-10-01T00:00:00+08:00"},
+ {"crossing-week-before-month-complete", "2026-09-28T00:00:00+08:00", "2026-09-29T08:00:00+08:00", "2026-09-29T08:00:00+08:00", "2026-09-01T00:00:00+08:00", "2026-09-29T08:00:00+08:00"},
+ } {
+ t.Run(c.name, func(t *testing.T) {
+ begin, end := dashboardQualityMonth(monthlyTestTime(t, c.start), monthlyTestTime(t, c.end), monthlyTestTime(t, c.now))
+ if !begin.Equal(monthlyTestTime(t, c.wantStart)) || !end.Equal(monthlyTestTime(t, c.wantEnd)) {
+ t.Fatalf("quality month = [%s,%s), want [%s,%s)", begin, end, c.wantStart, c.wantEnd)
+ }
+ })
+ }
+}
diff --git a/internal/qaopsmirror/dashboard_store.go b/internal/qaopsmirror/dashboard_store.go
index fc8cd4e..10b9ee2 100644
--- a/internal/qaopsmirror/dashboard_store.go
+++ b/internal/qaopsmirror/dashboard_store.go
@@ -265,12 +265,19 @@ func (s *Store) readDashboard(ctx context.Context, q dobotaiops.RecordQuery, mas
}
}
if master {
- out.CumulativeWeeks, e = s.readMasterCumulativeDashboard(ctx, tx, q.Keyword, q.Window.End)
- if e != nil {
- return out, e
+ timeline, calculated, err := s.readMasterQualityTimeline(ctx, tx, q.Keyword, q.Window.End)
+ if err != nil {
+ return out, err
}
+ out.CumulativeWeeks = dashboardCumulativeFromTimeline(timeline, q.Window.End, calculated)
+ month, cutoff := dashboardQualityMonth(out.WeekStart, q.Window.End, calculated)
+ out.QualityPeriod = &DashboardQualityPeriod{Month: month.Format("2006-01"), Start: month, CutoffAt: cutoff, CalculatedAt: calculated, Source: dashboardMonthlySource, PolicyVersion: dashboardMonthlyPolicy}
+ rates := dashboardStrictQuality(timeline, month, cutoff)
+ out.MonthlyQuality = &rates
+ out.CalendarMonths = dashboardCalendarMonths(timeline, cutoff, calculated)
} else {
out.CumulativeWeeks = []DashboardCumulative{}
+ out.CalendarMonths = []DashboardMonth{}
}
out.ReportedWeeks, e = s.readReportedDashboard(ctx, tx, q.Keyword, q.Window.End)
if e != nil {
diff --git a/internal/qaopsmirror/master_monthly_integration_test.go b/internal/qaopsmirror/master_monthly_integration_test.go
new file mode 100644
index 0000000..91cd55e
--- /dev/null
+++ b/internal/qaopsmirror/master_monthly_integration_test.go
@@ -0,0 +1,115 @@
+package qaopsmirror
+
+import (
+ "context"
+ "encoding/json"
+ "knowledge-governance/internal/dobotaiops"
+ pg "knowledge-governance/internal/platform/postgres"
+ "strings"
+ "testing"
+ "time"
+)
+
+func TestMasterCalendarMonthsResetAndCrossingWeekReadsPreviousMonth(t *testing.T) {
+ p := mirrorFixture(t)
+ ctx := context.Background()
+ s := NewStore(p, "fixture-calendar-month")
+ queue := pg.NewStore(p)
+ dates := []string{"2026-08-31T08:00:00+08:00", "2026-09-01T00:00:00+08:00", "2026-09-15T08:00:00+08:00", "2026-09-30T23:59:59+08:00", "2026-10-01T00:00:00+08:00", "2026-10-07T08:00:00+08:00", "2026-10-12T00:00:00+08:00"}
+ ids := []string{"aug", "sep1", "sep15", "sep30pending", "oct1", "oct7", "oct12boundary"}
+ cov := []string{"是", "是", "否", "是", "否", "是", "是"}
+ correct := []string{"否", "是", "否", "待确认", "否", "是", "是"}
+ source := &fixtureSource{}
+ for i, at := range dates {
+ entry := fixtureEntry(ids[i], "已有正文")
+ var wire map[string]any
+ _ = json.Unmarshal(entry.Payload, &wire)
+ wire["asked_at"] = at
+ entry.Payload, _ = json.Marshal(wire)
+ source.rows = append(source.rows, entry)
+ }
+ job := claimMirrorJob(t, s, queue, "seed-monthly")
+ if e := s.HandleSync(ctx, *job, func(context.Context) (Source, error) { return source, nil }); e != nil {
+ t.Fatal(e)
+ }
+ if e := queue.Complete(ctx, job.ID, job.LeaseOwner, time.Now()); e != nil {
+ t.Fatal(e)
+ }
+ for i, id := range ids {
+ fields, _ := json.Marshal(map[string]string{"coverage": cov[i], "is_correct": correct[i]})
+ if _, e := p.Exec(ctx, "UPDATE qa_ops_master_records SET local_fields=local_fields||$3::jsonb WHERE tenant_key=$1 AND id=$2", s.tenant, id, fields); e != nil {
+ t.Fatal(e)
+ }
+ }
+ read := func(start, end string) map[string]any {
+ t.Helper()
+ data, e := s.ReadMasterDashboard(ctx, dobotaiops.RecordQuery{Window: dobotaiops.Window{TenantKey: s.tenant, Start: monthlyTestTime(t, start), End: monthlyTestTime(t, end)}})
+ if e != nil {
+ t.Fatal(e)
+ }
+ raw, _ := json.Marshal(data)
+ var v map[string]any
+ _ = json.Unmarshal(raw, &v)
+ return v
+ }
+ crossing := read("2026-09-28T00:00:00+08:00", "2026-10-05T00:00:00+08:00")
+ period, ok := crossing["quality_period"].(map[string]any)
+ if !ok {
+ t.Fatal("missing calendar-month quality period; weekly/cumulative rates cannot substitute")
+ }
+ if period["month"] != "2026-09" || !monthlyTestTime(t, period["start"].(string)).Equal(monthlyTestTime(t, "2026-09-01T00:00:00+08:00")) || !monthlyTestTime(t, period["cutoff_at"].(string)).Equal(monthlyTestTime(t, "2026-10-01T00:00:00+08:00")) {
+ t.Fatal("crossing week did not select the previous month")
+ }
+ assertRates := func(raw any, records, covN, covD, accN, accD float64) {
+ t.Helper()
+ point := raw.(map[string]any)
+ rates := point
+ if v, ok := point["rates"].(map[string]any); ok {
+ rates = v
+ if point["total"] != records {
+ t.Fatal("monthly quality member count differs", point)
+ }
+ } else if point["records"] != records {
+ t.Fatal("monthly point member count differs", point)
+ }
+ coverage := rates["coverage"].(map[string]any)
+ accuracy := rates["correctness"].(map[string]any)
+ if coverage["numerator"] != covN || coverage["denominator"] != covD || accuracy["numerator"] != accN || accuracy["denominator"] != accD {
+ t.Fatalf("monthly rates did not reset or pending entered denominator: %v", point)
+ }
+ }
+ assertRates(crossing["monthly_quality"], 3, 2, 3, 1, 2)
+ months, ok := crossing["calendar_months"].([]any)
+ if !ok || len(months) != 2 {
+ t.Fatal("expected August and September independent month points, no October fragment")
+ }
+ assertRates(months[0], 1, 1, 1, 0, 1)
+ assertRates(months[1], 3, 2, 3, 1, 2)
+ inside := read("2026-10-05T00:00:00+08:00", "2026-10-12T00:00:00+08:00")
+ assertRates(inside["monthly_quality"], 2, 1, 2, 1, 2)
+ if len(inside["calendar_months"].([]any)) != 3 {
+ t.Fatal("missing October monthly point")
+ }
+ prefill, e := s.PrefillWeeklyDraft(ctx, "2026-W40", WeeklyDraftPrefillRequest{BaseRevision: 0, Nonce: "fixture_monthly_prefill_0001"}, "fixture-admin", time.Now())
+ if e != nil || !strings.Contains(prefill.Draft.Markdown, "质量统计月:2026-09") || !strings.Contains(prefill.Draft.Markdown, "Coverage Rate: 66.67%") || !strings.Contains(prefill.Draft.Markdown, "Accuracy Rate: 50.00%") {
+ t.Fatal("new prefill did not use the same September rates", e)
+ }
+ var before string
+ if e := p.QueryRow(ctx, `SELECT md5(string_agg(md5(payload::text||original_fields::text||local_fields::text),'' ORDER BY id)) FROM qa_ops_master_records WHERE tenant_key=$1`, s.tenant).Scan(&before); e != nil {
+ t.Fatal(e)
+ }
+ if _, e := p.Exec(ctx, `UPDATE qa_ops_mirror_records SET payload=jsonb_set(payload,'{feedback}','{"asker_value":"down","down":1,"up":0}') WHERE tenant_key=$1 AND id='sep1'`, s.tenant); e != nil {
+ t.Fatal(e)
+ }
+ fresh := read("2026-09-28T00:00:00+08:00", "2026-10-05T00:00:00+08:00")
+ assertRates(fresh["monthly_quality"], 3, 2, 3, 0, 2)
+ assertRates(fresh["calendar_months"].([]any)[1], 3, 2, 3, 0, 2)
+ saved, e := s.ReadWeeklyDraft(ctx, "2026-W40", time.Now())
+ if e != nil || saved.Markdown != prefill.Draft.Markdown || saved.Revision != prefill.Draft.Revision {
+ t.Fatal("live rate refresh overwrote a previously saved weekly draft", e)
+ }
+ var after string
+ if e := p.QueryRow(ctx, `SELECT md5(string_agg(md5(payload::text||original_fields::text||local_fields::text),'' ORDER BY id)) FROM qa_ops_master_records WHERE tenant_key=$1`, s.tenant).Scan(&after); e != nil || before != after {
+ t.Fatal("monthly read modified master original/local labels")
+ }
+}
diff --git a/internal/qaopsmirror/weekly_template.go b/internal/qaopsmirror/weekly_template.go
index 86f0d0f..592000b 100644
--- a/internal/qaopsmirror/weekly_template.go
+++ b/internal/qaopsmirror/weekly_template.go
@@ -90,6 +90,21 @@ func renderWeeklyTemplate(week string, data Dashboard, now time.Time) (string, j
qualitySourceWeekKey = p.Week
}
}
+ qualityPeriodEN, qualityPeriodZH := "", ""
+ if data.QualityPeriod != nil || data.MonthlyQuality != nil {
+ period, rates := data.QualityPeriod, data.MonthlyQuality
+ if period == nil || rates == nil || period.Source != dashboardMonthlySource || period.PolicyVersion != dashboardMonthlyPolicy || rates.Records < 0 {
+ return "", nil, dobotaiops.ErrInvalidQuery
+ }
+ wantStart, wantEnd := dashboardQualityMonth(start, end, period.CalculatedAt)
+ if !period.Start.Equal(wantStart) || !period.CutoffAt.Equal(wantEnd) || period.Month != wantStart.Format("2006-01") {
+ return "", nil, dobotaiops.ErrInvalidQuery
+ }
+ coverage, accuracy = rates.Coverage.Percent, rates.Correctness.Percent
+ qualitySource, qualitySourceWeekKey = dashboardMonthlySource, ""
+ qualityPeriodEN = fmt.Sprintf("Quality month (Beijing): %s; [%s, %s). Each rate is yes / (yes + no); pending and other unresolved values are excluded.", period.Month, period.Start.In(dashboardLocation).Format(time.RFC3339), period.CutoffAt.In(dashboardLocation).Format(time.RFC3339))
+ qualityPeriodZH = fmt.Sprintf("质量统计月:%s(北京时间);范围 [%s, %s)。分别按是÷(是+否)计算,待确认等不计分母;跨月周按周一所在月。", period.Month, period.Start.In(dashboardLocation).Format(time.RFC3339), period.CutoffAt.In(dashboardLocation).Format(time.RFC3339))
+ }
if !validWeeklyValue(coverage, true) || !validWeeklyValue(accuracy, true) {
return "", nil, dobotaiops.ErrInvalidQuery
}
@@ -103,13 +118,14 @@ func renderWeeklyTemplate(week string, data Dashboard, now time.Time) (string, j
"{{YEAR}}", week[:4], "{{WEEK}}", week[6:],
"{{TOTAL_QUESTIONS}}", fmt.Sprint(data.TotalIssues), "{{NEW_THIS_WEEK}}", fmt.Sprint(data.NewThisWeek),
"{{COVERAGE_RATE}}", weeklyPercent(coverage), "{{ACCURACY_RATE}}", weeklyPercent(accuracy),
+ "{{QUALITY_PERIOD_EN}}", qualityPeriodEN, "{{QUALITY_PERIOD_ZH}}", qualityPeriodZH,
"{{MONTH_EN}}", month.Format("January 2006"), "{{MONTH_ZH}}", fmt.Sprintf("%d年%d月", month.Year(), month.Month()),
"{{AVERAGE_USAGE_RANKING_EN}}", weeklyRegionRanking(data.Regions, false, true), "{{AVERAGE_USAGE_RANKING_ZH}}", weeklyRegionRanking(data.Regions, false, false),
"{{USAGE_COVERAGE_RANKING_EN}}", weeklyRegionRanking(data.Regions, true, true), "{{USAGE_COVERAGE_RANKING_ZH}}", weeklyRegionRanking(data.Regions, true, false),
"{{WEEKLY_HIGHLIGHTS_EN}}", "[To be completed]", "{{NEXT_WEEK_PRIORITIES_EN}}", "[To be completed]",
"{{WEEKLY_HIGHLIGHTS_ZH}}", "[待填写]", "{{NEXT_WEEK_PRIORITIES_ZH}}", "[待填写]"}
markdown := strings.NewReplacer(replacements...).Replace(weeklySkillTemplate)
- seed, _ := json.Marshal(map[string]any{"template_version": "dobot-weekly-six-sections-v1", "week": week, "start": start, "end": end, "generated_at": now, "source": "governance-master", "local_revision": data.LocalRevision, "source_observed_at": data.AsOf, "organization": data.Organization, "quality_source": qualitySource, "quality_source_week_key": qualitySourceWeekKey, "total_issues": data.TotalIssues, "new_this_week": data.NewThisWeek, "coverage_percent": coverage, "correctness_percent": accuracy, "month": month.Format("2006-01"), "regions": data.Regions})
+ seed, _ := json.Marshal(map[string]any{"template_version": "dobot-weekly-six-sections-v1", "week": week, "start": start, "end": end, "generated_at": now, "source": "governance-master", "local_revision": data.LocalRevision, "source_observed_at": data.AsOf, "organization": data.Organization, "quality_source": qualitySource, "quality_source_week_key": qualitySourceWeekKey, "quality_period": data.QualityPeriod, "quality_counts": data.MonthlyQuality, "total_issues": data.TotalIssues, "new_this_week": data.NewThisWeek, "coverage_percent": coverage, "correctness_percent": accuracy, "month": month.Format("2006-01"), "regions": data.Regions})
return markdown, seed, nil
}
@@ -127,6 +143,8 @@ Coverage Rate: {{COVERAGE_RATE}}
Accuracy Rate: {{ACCURACY_RATE}}
+{{QUALITY_PERIOD_EN}}
+
## 3. {{MONTH_EN}} Regional Average Usage Ranking
{{AVERAGE_USAGE_RANKING_EN}}
@@ -157,6 +175,8 @@ Accuracy Rate: {{ACCURACY_RATE}}
正确率:{{ACCURACY_RATE}}
+{{QUALITY_PERIOD_ZH}}
+
## 三、{{MONTH_ZH}}区域人均使用次数排名
{{AVERAGE_USAGE_RANKING_ZH}}
diff --git a/internal/qaopsmirror/weekly_template_test.go b/internal/qaopsmirror/weekly_template_test.go
index f78e8d6..cf6f200 100644
--- a/internal/qaopsmirror/weekly_template_test.go
+++ b/internal/qaopsmirror/weekly_template_test.go
@@ -8,6 +8,34 @@ import (
"time"
)
+func TestWeeklyTemplateCalendarMonthOverridesOnlyNewPrefillNotHistoricalEvidence(t *testing.T) {
+ now := monthlyTestTime(t, "2026-10-21T08:00:00+08:00")
+ start, end, e := weeklyDraftBounds("2026-W40", now)
+ if e != nil {
+ t.Fatal(e)
+ }
+ data := Dashboard{Start: start, End: end, MonthStart: monthlyTestTime(t, "2026-10-01T00:00:00+08:00"), ReportedWeeks: []DashboardReported{{Week: "2026WK40", WeekStart: start, WeekEnd: end, CoveragePercent: 57.23, CorrectnessPercent: 92.34, Source: "user_provided_history"}}, QualityPeriod: &DashboardQualityPeriod{Month: "2026-09", Start: monthlyTestTime(t, "2026-09-01T00:00:00+08:00"), CutoffAt: monthlyTestTime(t, "2026-10-01T00:00:00+08:00"), CalculatedAt: now, Source: dashboardMonthlySource, PolicyVersion: dashboardMonthlyPolicy}, MonthlyQuality: &DashboardStrictQuality{Records: 3, Coverage: dashboardRate(2, 3), Correctness: dashboardRate(1, 2)}}
+ md, seed, e := renderWeeklyTemplate("2026-W40", data, now)
+ if e != nil {
+ t.Fatal(e)
+ }
+ var meta map[string]any
+ _ = json.Unmarshal(seed, &meta)
+ if !strings.Contains(md, "Coverage Rate: 66.67%") || !strings.Contains(md, "Accuracy Rate: 50.00%") || !strings.Contains(md, "质量统计月:2026-09") || meta["quality_source"] != dashboardMonthlySource {
+ t.Fatal("new weekly prefill still uses historical/week quality instead of the selected calendar month", md)
+ }
+ if data.ReportedWeeks[0].CoveragePercent != 57.23 {
+ t.Fatal("historical reported evidence changed")
+ }
+ if strings.Count(md, "\n## ") != 12 {
+ t.Fatal("changed approved bilingual six-section template")
+ }
+ period, ok := meta["quality_period"].(map[string]any)
+ if !ok || period["month"] != "2026-09" {
+ t.Fatal("monthly prefill provenance missing")
+ }
+}
+
func TestWeeklyTemplateHistoricalRatesKeepSourceWeekKeyAndUseMatchingBoundaries(t *testing.T) {
now := time.Date(2026, 10, 19, 12, 0, 0, 0, time.UTC)
start, end, e := weeklyDraftBounds("2026-W40", now)
diff --git a/web/src/QADashboard.test.tsx b/web/src/QADashboard.test.tsx
index dc7c6d9..a71a4cc 100644
--- a/web/src/QADashboard.test.tsx
+++ b/web/src/QADashboard.test.tsx
@@ -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(个人月明细
- {monthly ?
问题总数与新增是可编辑的系统统计建议;区域采用已保存配置及当前通讯录。未做新的FAQ调整,重点与英文文字请自行填写。草稿不会自动发送。
diff --git a/web/src/qaDashboard.css b/web/src/qaDashboard.css
index 3c56ff3..7285923 100644
--- a/web/src/qaDashboard.css
+++ b/web/src/qaDashboard.css
@@ -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;
diff --git a/web/src/qaDashboardData.ts b/web/src/qaDashboardData.ts
index 94bfe6a..5abfbf4 100644
--- a/web/src/qaDashboardData.ts
+++ b/web/src/qaDashboardData.ts
@@ -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