feat: sync deployed v1.0.0-rc.38-custom.67

This commit is contained in:
cneicy committed 2026-10-06 00:07:10 +08:00
1 parent d2e03ab7e8
commit ffc8cf56db
154 files changed
+39540 -20509

No files matched your search

+56 -32
View File
@@ -11,15 +11,16 @@ import (
)
type DetectionHistory struct {
SourceURL string `json:"source_url,omitempty"`
ID string `json:"id"`
At int64 `json:"at"`
Status string `json:"status"`
Quality string `json:"quality"`
UserInitiated bool `json:"user_initiated"`
HasHTML bool `json:"has_html"`
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 PelicanSummary struct {
type BenchmarkSummary struct {
LatestValid *DetectionHistory `json:"-"`
Channels int `json:"channels"`
IntervalMinutes int `json:"interval_minutes"`
IntervalMaxMinutes int `json:"interval_max_minutes"`
@@ -37,7 +38,8 @@ type ChannelDetectionEvidence struct {
}
type GroupDetectionSummary struct {
ProbeHistory []ProbeHistoryPoint
Pelican *PelicanSummary
Candy *BenchmarkSummary
Benchmark *BenchmarkSummary
Status int
At int64
}
@@ -75,7 +77,8 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
}
groups := map[string][]int{}
byChannel := map[int][]string{}
pelicans := map[string]*PelicanSummary{}
benchmarks := map[string]*BenchmarkSummary{}
candies := map[string]*BenchmarkSummary{}
evidence := map[int]ChannelDetectionEvidence{}
observe := func(id int, at int64, success bool) {
if at > evidence[id].At {
@@ -87,19 +90,27 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
for _, group := range channel.GetGroups() {
groups[group] = append(groups[group], channel.Id)
if ChannelSupportsAstra(&channel) {
if pelicans[group] == nil {
pelicans[group] = &PelicanSummary{IntervalMinutes: 30, WindowHours: 6, History: []DetectionHistory{}}
if benchmarks[group] == nil {
benchmarks[group] = &BenchmarkSummary{IntervalMinutes: 30, WindowHours: 6, History: []DetectionHistory{}}
}
pelicans[group].Channels++
benchmarks[group].Channels++
}
}
}
var tasks []model.SystemTask
ranges, err := DetectionScheduleRanges(ctx, channels, "pelican")
candyRanges, err := DetectionScheduleRanges(ctx, channels, "candy")
if err != nil {
return nil, err
}
for group, summary := range pelicans {
for group, summary := range benchmarks {
r := candyRanges[group]
candies[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")
if err != nil {
return nil, err
}
for group, summary := range benchmarks {
r := ranges[group]
summary.IntervalMinutes, summary.IntervalMaxMinutes = r[0], r[1]
}
@@ -136,14 +147,6 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
if err = model.DB.WithContext(ctx).Omit("html", "price", "remote_id").Where("created_at >= ?", now.Add(-6*time.Hour).Unix()).Find(&runs).Error; err != nil {
return nil, err
}
var artworkIDs []string
if err = model.DB.WithContext(ctx).Model(&model.DetectionRun{}).Where("created_at >= ? AND html <> ?", now.Add(-6*time.Hour).Unix(), "").Pluck("id", &artworkIDs).Error; err != nil {
return nil, err
}
artwork := map[string]bool{}
for _, id := range artworkIDs {
artwork[id] = true
}
ids := []string{}
for _, run := range runs {
ids = append(ids, run.ID)
@@ -164,6 +167,9 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
}
}
for _, run := range runs {
if run.Kind != "fingerprint" && run.Kind != "benchmark" && run.Kind != "candy" {
continue
}
for _, group := range byChannel[run.ChannelID] {
if cutoff := settings[group].ResetBefore; cutoff > 0 && run.CreatedAt <= cutoff {
continue
@@ -180,6 +186,9 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
if result.Status == "" {
result.Status = "error"
}
if result.Engine != fingerprint.Version {
continue
}
result.Status = AstraSamplingResultStatus(result)
switch result.Status {
case "match":
@@ -192,20 +201,28 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
summary.Errors++
}
summary.History = append(summary.History, AstraSamplingHistory{ID: run.ID, At: run.CreatedAt, Status: result.Status, ValidSamples: result.ValidSamples, Closest: result.Closest, Gap: result.Gap, UserInitiated: true})
if result.ValidSamples > 0 && result.Closest != "" && (result.Status == "match" || result.Status == "mismatch") && (summary.LatestValid == nil || run.CreatedAt > summary.LatestValid.At) {
round := summary.History[len(summary.History)-1]
summary.LatestValid = &round
}
continue
}
s := pelicans[group]
s := benchmarks[group]
if run.Kind == "candy" {
s = candies[group]
}
if s == nil {
continue
}
history := DetectionHistory{ID: run.ID, At: run.CreatedAt, Status: run.Status, Quality: run.Quality, UserInitiated: run.UserID > 0, HasHTML: artwork[run.ID]}
var metadata struct {
SourceURL string `json:"source_url"`
}
history := DetectionHistory{ID: run.ID, At: run.CreatedAt, Status: run.Status, Quality: run.Quality, UserInitiated: run.UserID > 0}
var metadata fingerprint.Result
if common.UnmarshalJsonStr(run.Result, &metadata) == nil {
history.SourceURL = metadata.SourceURL
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) {
s.LatestValid = &history
}
switch run.Status {
case "pending", "running":
s.Running++
@@ -236,14 +253,21 @@ func GroupDetectionSummaries(ctx context.Context, now time.Time, fingerprints ma
results := map[string]GroupDetectionSummary{}
for group, ids := range groups {
status, at := DetectionFallbackStatus(ids, evidence, now.Unix())
s := pelicans[group]
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]
}
}
results[group] = GroupDetectionSummary{Pelican: s, Status: status, At: at, ProbeHistory: GroupProbeHistory(ids, tasks)}
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]
}
}
results[group] = GroupDetectionSummary{Candy: candy, Benchmark: s, Status: status, At: at, ProbeHistory: GroupProbeHistory(ids, tasks)}
}
return results, nil
}