feat(platform): keep canonical source summary slots
This commit is contained in:
@@ -58,6 +58,37 @@ type Service struct {
|
||||
|
||||
var canonicalVehicleProtocols = []string{"GB32960", "JT808", "YUTONG_MQTT"}
|
||||
|
||||
func completeProtocolStats(stats []ProtocolStat) []ProtocolStat {
|
||||
byProtocol := make(map[string]ProtocolStat, len(stats)+len(canonicalVehicleProtocols))
|
||||
for _, stat := range stats {
|
||||
protocol := strings.TrimSpace(stat.Protocol)
|
||||
if protocol == "" {
|
||||
continue
|
||||
}
|
||||
stat.Protocol = protocol
|
||||
byProtocol[protocol] = stat
|
||||
}
|
||||
out := make([]ProtocolStat, 0, len(byProtocol)+len(canonicalVehicleProtocols))
|
||||
seen := map[string]struct{}{}
|
||||
for _, protocol := range canonicalVehicleProtocols {
|
||||
stat := byProtocol[protocol]
|
||||
stat.Protocol = protocol
|
||||
out = append(out, stat)
|
||||
seen[protocol] = struct{}{}
|
||||
}
|
||||
extra := make([]string, 0)
|
||||
for protocol := range byProtocol {
|
||||
if _, ok := seen[protocol]; !ok {
|
||||
extra = append(extra, protocol)
|
||||
}
|
||||
}
|
||||
sort.Strings(extra)
|
||||
for _, protocol := range extra {
|
||||
out = append(out, byProtocol[protocol])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func missingCanonicalProtocols(protocols []string) []string {
|
||||
missing := make([]string, 0, len(canonicalVehicleProtocols))
|
||||
for _, protocol := range canonicalVehicleProtocols {
|
||||
|
||||
Reference in New Issue
Block a user