Files
knowledge-governance/internal/qaopsmirror/dashboard.go
T
姚章浩 a9870beade
build / build (push) Successful in 1m10s
feat(qaops): 补充独立历史覆盖率与正确率趋势
用户提供的历史百分比独立持久化,按ISO自然周和截止范围读取,不伪造分子分母、记录数或冻结时间。现有两张趋势图与PNG共用来源分色/分段及两位小数;缺失周留空,关键词筛选不借用无明细历史,当前指标与原冻结证据不变。

验证:完整make verify退出0;镜像全量隔离PG race退出0,新增来源/精度/关键词/租户/截止/不可变和安全down回归先失败后通过。前端输入/来源及缺失周回归先红后绿。治理库上线前原生备份与真实恢复已完成,71表行数和28张QA表内容哈希一致,独立主密钥同时受限备份。

当前仅完成开发验证,真实数据候选浏览器验收、正式25周导入与应用上线需继续完成。不修改源生产数据库、原问答、已有模型自动开关或隧道;用户原始报表和图像只保存于私有证据目录,不入Git。
2026-10-19 17:55:15 +08:00

93 lines
3.5 KiB
Go

package qaopsmirror
import (
"knowledge-governance/internal/dobotaiops"
"knowledge-governance/internal/qaopsquality"
"time"
)
type DashboardCount struct {
Label string `json:"label"`
Count int `json:"count"`
}
type DashboardDaily struct {
Date string `json:"date"`
Count int `json:"count"`
}
type DashboardReported struct {
Week string `json:"week"`
WeekStart time.Time `json:"week_start"`
WeekEnd time.Time `json:"week_end"`
CoveragePercent float64 `json:"coverage_percent"`
CorrectnessPercent float64 `json:"correctness_percent"`
Source string `json:"source"`
}
type DashboardFrozen struct {
WeekStart time.Time `json:"week_start"`
WeekEnd time.Time `json:"week_end"`
FrozenAt *time.Time `json:"frozen_at"`
PolicyVersion string `json:"policy_version"`
Records int `json:"records"`
Coverage qaopsquality.Rate `json:"coverage"`
Correctness qaopsquality.Rate `json:"correctness"`
}
type DashboardRegion struct {
ID string `json:"id"`
Name string `json:"name"`
Questions int `json:"questions"`
Users *int `json:"users"`
RosterPeople *int `json:"roster_people"`
Frequency *float64 `json:"frequency"`
UsageCoverage qaopsquality.Rate `json:"usage_coverage"`
}
type Dashboard struct {
Start time.Time `json:"start"`
End time.Time `json:"end"`
Keyword string `json:"keyword"`
AsOf time.Time `json:"as_of"`
LocalRevision int64 `json:"local_revision"`
Organization dobotaiops.OrganizationVersion `json:"organization"`
TotalIssues int `json:"total_issues"`
NewThisWeek int `json:"new_this_week"`
WeekStart time.Time `json:"week_start"`
MonthStart time.Time `json:"month_start"`
Quality qaopsquality.Summary `json:"quality"`
IssueTypes []DashboardCount `json:"issue_types"`
Products []DashboardCount `json:"products"`
Daily []DashboardDaily `json:"daily"`
Regions []DashboardRegion `json:"regions"`
FrozenWeeks []DashboardFrozen `json:"frozen_weeks"`
ReportedWeeks []DashboardReported `json:"reported_weeks"`
}
var dashboardLocation = time.FixedZone("Asia/Shanghai", 8*60*60)
func dashboardDay(at time.Time) time.Time {
t := at.In(dashboardLocation)
return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, dashboardLocation)
}
func dashboardWeek(at time.Time) time.Time {
d := dashboardDay(at)
return d.AddDate(0, 0, -((int(d.Weekday()) + 6) % 7))
}
func dashboardPeriods(end time.Time) (time.Time, time.Time) {
cutoff := end.Add(-time.Nanosecond).In(dashboardLocation)
return time.Date(cutoff.Year(), cutoff.Month(), 1, 0, 0, 0, 0, dashboardLocation), dashboardWeek(cutoff)
}
func dashboardFrozenSeries(first, end time.Time, snapshots map[string]DashboardFrozen) []DashboardFrozen {
out := []DashboardFrozen{}
if first.IsZero() || !first.Before(end) {
return out
}
for at := dashboardWeek(first); at.Before(end) && len(out) < 5200; at = at.AddDate(0, 0, 7) {
key := at.Format("2006-01-02")
point, ok := snapshots[key]
if !ok {
point = DashboardFrozen{WeekStart: at, WeekEnd: at.AddDate(0, 0, 7)}
}
out = append(out, point)
}
return out
}