cb9f0c389f
build / build (push) Successful in 1m10s
去掉看板个人月明细;十一卡悬停和键盘可读的真实统计范围、公式与排除数。 自然月独立计算;跨月周取周一所在月,保留旧周证据和已存周报正文。 验证:make verify;一次性PG全镜像套件-race;真实恢复数据7个月与周报calc_metrics对拍。 真实浏览器十一卡逐项悬停、Tab/Escape、30秒刷新、跨月周、390px和完整PNG通过。 没有写DobotAI源问答、触发付费模型、外发或应用新迁移。
108 lines
3.3 KiB
Go
108 lines
3.3 KiB
Go
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
|
|
}
|