feat(platform): summarize missing vehicle sources
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user