feat: sync deployed v1.0.0-rc.38-custom.42
Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
This commit is contained in:
1 parent
aa6c3f50f4
commit
ceddfd3d6b
828 files changed
+122253
-13702
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/QuantumNous/new-api/model"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type ProbeHistoryPoint struct {
|
||||
At int64 `json:"at"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
func GroupProbeHistory(ids []int, tasks []model.SystemTask) []ProbeHistoryPoint {
|
||||
points := []ProbeHistoryPoint{}
|
||||
for _, task := range tasks {
|
||||
if task.Type != model.SystemTaskTypeChannelAvailability {
|
||||
continue
|
||||
}
|
||||
var state ChannelAvailabilityState
|
||||
if task.DecodeState(&state) != nil {
|
||||
continue
|
||||
}
|
||||
evidence := map[int]ChannelDetectionEvidence{}
|
||||
for _, round := range state.Rounds {
|
||||
evidence[round.ChannelID] = ChannelDetectionEvidence{At: round.At, Success: round.Success}
|
||||
}
|
||||
latest := int64(0)
|
||||
for _, id := range ids {
|
||||
latest = max(latest, evidence[id].At)
|
||||
}
|
||||
if latest == 0 {
|
||||
continue
|
||||
}
|
||||
status, at := DetectionFallbackStatus(ids, evidence, latest)
|
||||
points = append(points, ProbeHistoryPoint{At: at, Status: status})
|
||||
}
|
||||
sort.Slice(points, func(i, j int) bool { return points[i].At < points[j].At })
|
||||
if len(points) > 18 {
|
||||
points = points[len(points)-18:]
|
||||
}
|
||||
return points
|
||||
}
|
||||
Reference in new issue
Block a user