feat: publish sanitized custom.97 source

This commit is contained in:
cneicy committed 2026-10-27 20:43:39 +08:00
1 parent 8e6ed0317b
commit 86c0276156
1022 files changed
+69903 -19207

No files matched your search

+45 -30
View File
@@ -11,13 +11,14 @@ import (
)
type DetectionHistory struct {
Closest string `json:"closest,omitempty"`
Weight float64 `json:"relative_weight,omitempty"`
ID string `json:"id"`
At int64 `json:"at"`
Status string `json:"status"`
Quality string `json:"quality"`
UserInitiated bool `json:"user_initiated"`
FirstTokenMS *float64 `json:"first_token_ms,omitempty"`
Closest string `json:"closest,omitempty"`
Weight float64 `json:"relative_weight,omitempty"`
ID string `json:"id"`
At int64 `json:"at"`
Status string `json:"status"`
Quality string `json:"quality"`
UserInitiated bool `json:"user_initiated"`
}
type BenchmarkSummary struct {
LatestValid *DetectionHistory `json:"-"`
@@ -27,6 +28,7 @@ type BenchmarkSummary struct {
WindowHours int `json:"window_hours"`
Normal int `json:"normal"`
Degraded int `json:"degraded"`
Incomplete int `json:"incomplete"`
Unknown int `json:"unknown"`
Failed int `json:"failed"`
Running int `json:"running"`
@@ -38,7 +40,8 @@ type ChannelDetectionEvidence struct {
}
type GroupDetectionSummary struct {
ProbeHistory []ProbeHistoryPoint
Candy *BenchmarkSummary
Ciallo *BenchmarkSummary
Vision *BenchmarkSummary
Benchmark *BenchmarkSummary
Status int
At int64
@@ -78,7 +81,8 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
groups := map[string][]int{}
byChannel := map[int][]string{}
benchmarks := map[string]*BenchmarkSummary{}
candies := map[string]*BenchmarkSummary{}
visions := map[string]*BenchmarkSummary{}
ciallos := map[string]*BenchmarkSummary{}
evidence := map[int]ChannelDetectionEvidence{}
observe := func(id int, at int64, success bool) {
if at > evidence[id].At {
@@ -97,13 +101,14 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
}
}
}
candyRanges, err := DetectionScheduleRanges(ctx, channels, "candy")
visionRanges, err := DetectionScheduleRanges(ctx, channels, "vision")
if err != nil {
return nil, err
}
for group, summary := range benchmarks {
r := candyRanges[group]
candies[group] = &BenchmarkSummary{Channels: summary.Channels, IntervalMinutes: r[0], IntervalMaxMinutes: r[1], WindowHours: 6, History: []DetectionHistory{}}
ciallos[group] = &BenchmarkSummary{Channels: summary.Channels, IntervalMinutes: 45, IntervalMaxMinutes: 45, WindowHours: 6, History: []DetectionHistory{}}
r := visionRanges[group]
visions[group] = &BenchmarkSummary{Channels: summary.Channels, IntervalMinutes: r[0], IntervalMaxMinutes: r[1], WindowHours: 6, History: []DetectionHistory{}}
}
var tasks []model.SystemTask
ranges, err := DetectionScheduleRanges(ctx, channels, "benchmark")
@@ -153,21 +158,28 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
}
var calls []model.DetectionCall
if len(ids) > 0 {
if err = model.DB.WithContext(ctx).Select("run_id", "finished_at", "available").Where("run_id IN ? AND state = ?", ids, "finished").Find(&calls).Error; err != nil {
if err = model.DB.WithContext(ctx).Select("run_id", "finished_at", "available", "first_token_ms").Where("run_id IN ? AND state = ?", ids, "finished").Find(&calls).Error; err != nil {
return nil, err
}
}
runChannels := map[string]int{}
firstTokenTotals := map[string]float64{}
firstTokenCounts := map[string]int{}
for _, run := range runs {
runChannels[run.ID] = run.ChannelID
}
for _, call := range calls {
if call.FirstTokenMS != nil && *call.FirstTokenMS >= 0 && call.Available != nil && *call.Available {
firstTokenTotals[call.RunID] += float64(*call.FirstTokenMS)
firstTokenCounts[call.RunID]++
}
if call.Available != nil {
observe(runChannels[call.RunID], call.FinishedAt, *call.Available)
}
}
for _, run := range runs {
if run.Kind != "fingerprint" && run.Kind != "benchmark" && run.Kind != "candy" {
run = NormalizeVisionRun(run)
if run.Kind != "fingerprint" && run.Kind != "benchmark" && run.Kind != "vision" && run.Kind != "ciallo" {
continue
}
for _, group := range byChannel[run.ChannelID] {
@@ -208,19 +220,26 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
continue
}
s := benchmarks[group]
if run.Kind == "candy" {
s = candies[group]
if run.Kind == "vision" {
s = visions[group]
}
if run.Kind == "ciallo" {
s = ciallos[group]
}
if s == nil {
continue
}
history := DetectionHistory{ID: run.ID, At: run.CreatedAt, Status: run.Status, Quality: run.Quality, UserInitiated: run.UserID > 0}
if count := firstTokenCounts[run.ID]; count > 0 {
average := firstTokenTotals[run.ID] / float64(count)
history.FirstTokenMS = &average
}
var metadata fingerprint.Result
if common.UnmarshalJsonStr(run.Result, &metadata) == nil {
history.Closest, history.Weight = metadata.Closest, metadata.Weight
}
s.History = append(s.History, history)
if run.Status == "succeeded" && (run.Quality == "normal" || run.Quality == "degraded") && (s.LatestValid == nil || history.At > s.LatestValid.At) {
if run.Status == "succeeded" && (run.Quality == "normal" || run.Quality == "degraded" || run.Quality == "incomplete") && (s.LatestValid == nil || history.At > s.LatestValid.At) {
s.LatestValid = &history
}
switch run.Status {
@@ -234,6 +253,8 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
s.Normal++
case "degraded":
s.Degraded++
case "incomplete":
s.Incomplete++
default:
s.Unknown++
}
@@ -246,9 +267,6 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
s.Rate = &rate
}
sort.SliceStable(s.History, func(i, j int) bool { return s.History[i].At > s.History[j].At })
if len(s.History) > 12 {
s.History = s.History[:12]
}
}
results := map[string]GroupDetectionSummary{}
for group, ids := range groups {
@@ -256,18 +274,15 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
s := benchmarks[group]
if s != nil {
sort.SliceStable(s.History, func(i, j int) bool { return s.History[i].At > s.History[j].At })
if len(s.History) > 12 {
s.History = s.History[:12]
}
}
candy := candies[group]
if candy != nil {
sort.SliceStable(candy.History, func(i, j int) bool { return candy.History[i].At > candy.History[j].At })
if len(candy.History) > 12 {
candy.History = candy.History[:12]
}
vision := visions[group]
if vision != nil {
sort.SliceStable(vision.History, func(i, j int) bool { return vision.History[i].At > vision.History[j].At })
}
results[group] = GroupDetectionSummary{Candy: candy, Benchmark: s, Status: status, At: at, ProbeHistory: GroupProbeHistory(ids, tasks)}
if s := ciallos[group]; s != nil {
sort.SliceStable(s.History, func(i, j int) bool { return s.History[i].At > s.History[j].At })
}
results[group] = GroupDetectionSummary{Ciallo: ciallos[group], Vision: vision, Benchmark: s, Status: status, At: at, ProbeHistory: GroupProbeHistory(ids, tasks)}
}
return results, nil
}