feat(platform): summarize missing vehicle sources

This commit is contained in:
lingniu
2026-07-04 06:13:38 +08:00
parent 1c210897bb
commit 8cd90f629b
7 changed files with 53 additions and 7 deletions

View File

@@ -185,6 +185,9 @@ func TestHandlerVehicleCoverageSummary(t *testing.T) {
if body.Data.OnlineVehicles != 1 || body.Data.UnboundVehicles != 0 {
t.Fatalf("coverage summary should expose filtered online and binding totals, got %+v", body.Data)
}
if len(body.Data.MissingSources) == 0 {
t.Fatalf("coverage summary should expose missing source counts, got %+v", body.Data)
}
}
func TestSplitCSVEmptyReturnsEmptySlice(t *testing.T) {

View File

@@ -168,6 +168,15 @@ func (m *MockStore) VehicleCoverageSummary(ctx context.Context, query url.Values
summary.UnboundVehicles++
}
}
for _, protocol := range canonicalVehicleProtocols {
missing := 0
for _, row := range coverage.Items {
if !containsString(row.Protocols, protocol) {
missing++
}
}
summary.MissingSources = append(summary.MissingSources, MissingSourceStat{Protocol: protocol, Count: missing})
}
return summary, nil
}

View File

@@ -65,12 +65,13 @@ type VehicleCoverageRow struct {
}
type VehicleCoverageSummary struct {
TotalVehicles int `json:"totalVehicles"`
OnlineVehicles int `json:"onlineVehicles"`
SingleSourceVehicles int `json:"singleSourceVehicles"`
MultiSourceVehicles int `json:"multiSourceVehicles"`
NoDataVehicles int `json:"noDataVehicles"`
UnboundVehicles int `json:"unboundVehicles"`
TotalVehicles int `json:"totalVehicles"`
OnlineVehicles int `json:"onlineVehicles"`
SingleSourceVehicles int `json:"singleSourceVehicles"`
MultiSourceVehicles int `json:"multiSourceVehicles"`
NoDataVehicles int `json:"noDataVehicles"`
UnboundVehicles int `json:"unboundVehicles"`
MissingSources []MissingSourceStat `json:"missingSources"`
}
type VehicleIdentityResolution struct {

View File

@@ -297,9 +297,30 @@ func (s *ProductionStore) VehicleCoverageSummary(ctx context.Context, query url.
); err != nil {
return VehicleCoverageSummary{}, err
}
missingSources, err := s.coverageMissingSourceStats(ctx, query)
if err != nil {
return VehicleCoverageSummary{}, err
}
summary.MissingSources = missingSources
return summary, nil
}
func (s *ProductionStore) coverageMissingSourceStats(ctx context.Context, query url.Values) ([]MissingSourceStat, error) {
out := make([]MissingSourceStat, 0, len(canonicalVehicleProtocols))
for _, protocol := range canonicalVehicleProtocols {
next := copyValues(query)
next.Set("missingProtocol", protocol)
next.Set("limit", "1")
next.Set("offset", "0")
page, err := s.VehicleCoverage(ctx, next)
if err != nil {
return nil, err
}
out = append(out, MissingSourceStat{Protocol: protocol, Count: page.Total})
}
return out, nil
}
func (s *ProductionStore) VehicleRealtime(ctx context.Context, query url.Values) (Page[VehicleRealtimeRow], error) {
built := buildVehicleRealtimeSQL(query)
total := 0