Files
knowledge-governance/internal/qaopsmirror/dashboard.go
T
姚章浩 cb9f0c389f
build / build (push) Successful in 1m10s
feat(qaops): 看板改用自然月质量指标并增加统计口径
去掉看板个人月明细;十一卡悬停和键盘可读的真实统计范围、公式与排除数。
自然月独立计算;跨月周取周一所在月,保留旧周证据和已存周报正文。

验证:make verify;一次性PG全镜像套件-race;真实恢复数据7个月与周报calc_metrics对拍。
真实浏览器十一卡逐项悬停、Tab/Escape、30秒刷新、跨月周、390px和完整PNG通过。
没有写DobotAI源问答、触发付费模型、外发或应用新迁移。
2026-10-21 08:48:55 +08:00

97 lines
3.9 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"`
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)
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
}