feat(platform): surface incomplete vehicle archives
This commit is contained in:
@@ -463,6 +463,9 @@ func TestHandlerVehicleServiceSummaryEndpoint(t *testing.T) {
|
||||
if body.Data.MultiSourceVehicles < 1 || body.Data.SingleSourceVehicles < 1 {
|
||||
t.Fatalf("summary should expose source coverage distribution, got %+v", body.Data)
|
||||
}
|
||||
if body.Data.ArchiveIncompleteVehicles < 1 {
|
||||
t.Fatalf("summary should expose incomplete archive vehicles, got %+v", body.Data)
|
||||
}
|
||||
if len(body.Data.ServiceStatuses) == 0 || len(body.Data.Protocols) == 0 {
|
||||
t.Fatalf("summary should expose service status and protocol distributions, got %+v", body.Data)
|
||||
}
|
||||
|
||||
@@ -175,6 +175,9 @@ func (m *MockStore) VehicleCoverageSummary(ctx context.Context, query url.Values
|
||||
if row.BindingStatus != "bound" {
|
||||
summary.UnboundVehicles++
|
||||
}
|
||||
if vehicleArchiveIncomplete(row) {
|
||||
summary.ArchiveIncompleteVehicles++
|
||||
}
|
||||
}
|
||||
for _, protocol := range canonicalVehicleProtocols {
|
||||
missing := 0
|
||||
@@ -211,6 +214,9 @@ func (m *MockStore) VehicleServiceSummary(ctx context.Context) (VehicleServiceSu
|
||||
if row.BindingStatus == "bound" {
|
||||
summary.BoundVehicles++
|
||||
}
|
||||
if vehicleArchiveIncomplete(row) {
|
||||
summary.ArchiveIncompleteVehicles++
|
||||
}
|
||||
if row.Online {
|
||||
summary.OnlineVehicles++
|
||||
}
|
||||
@@ -275,6 +281,13 @@ func (m *MockStore) VehicleServiceSummary(ctx context.Context) (VehicleServiceSu
|
||||
return summary, nil
|
||||
}
|
||||
|
||||
func vehicleArchiveIncomplete(row VehicleCoverageRow) bool {
|
||||
return strings.TrimSpace(row.VIN) == "" ||
|
||||
strings.TrimSpace(row.Plate) == "" ||
|
||||
strings.TrimSpace(row.Phone) == "" ||
|
||||
strings.TrimSpace(row.OEM) == ""
|
||||
}
|
||||
|
||||
func (m *MockStore) VehicleRealtime(_ context.Context, query url.Values) (Page[VehicleRealtimeRow], error) {
|
||||
rows := m.locations
|
||||
if vin := strings.TrimSpace(query.Get("vin")); vin != "" {
|
||||
|
||||
@@ -67,13 +67,14 @@ 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"`
|
||||
MissingSources []MissingSourceStat `json:"missingSources"`
|
||||
TotalVehicles int `json:"totalVehicles"`
|
||||
OnlineVehicles int `json:"onlineVehicles"`
|
||||
SingleSourceVehicles int `json:"singleSourceVehicles"`
|
||||
MultiSourceVehicles int `json:"multiSourceVehicles"`
|
||||
NoDataVehicles int `json:"noDataVehicles"`
|
||||
UnboundVehicles int `json:"unboundVehicles"`
|
||||
ArchiveIncompleteVehicles int `json:"archiveIncompleteVehicles"`
|
||||
MissingSources []MissingSourceStat `json:"missingSources"`
|
||||
}
|
||||
|
||||
type VehicleIdentityResolution struct {
|
||||
@@ -143,16 +144,17 @@ type VehicleServiceOverview struct {
|
||||
}
|
||||
|
||||
type VehicleServiceSummary struct {
|
||||
TotalVehicles int `json:"totalVehicles"`
|
||||
BoundVehicles int `json:"boundVehicles"`
|
||||
OnlineVehicles int `json:"onlineVehicles"`
|
||||
SingleSourceVehicles int `json:"singleSourceVehicles"`
|
||||
MultiSourceVehicles int `json:"multiSourceVehicles"`
|
||||
NoDataVehicles int `json:"noDataVehicles"`
|
||||
IdentityRequiredVehicles int `json:"identityRequiredVehicles"`
|
||||
ServiceStatuses []ServiceStatusStat `json:"serviceStatuses"`
|
||||
Protocols []ProtocolStat `json:"protocols"`
|
||||
MissingSources []MissingSourceStat `json:"missingSources"`
|
||||
TotalVehicles int `json:"totalVehicles"`
|
||||
BoundVehicles int `json:"boundVehicles"`
|
||||
OnlineVehicles int `json:"onlineVehicles"`
|
||||
SingleSourceVehicles int `json:"singleSourceVehicles"`
|
||||
MultiSourceVehicles int `json:"multiSourceVehicles"`
|
||||
NoDataVehicles int `json:"noDataVehicles"`
|
||||
IdentityRequiredVehicles int `json:"identityRequiredVehicles"`
|
||||
ArchiveIncompleteVehicles int `json:"archiveIncompleteVehicles"`
|
||||
ServiceStatuses []ServiceStatusStat `json:"serviceStatuses"`
|
||||
Protocols []ProtocolStat `json:"protocols"`
|
||||
MissingSources []MissingSourceStat `json:"missingSources"`
|
||||
}
|
||||
|
||||
type VehicleServiceStatus struct {
|
||||
|
||||
@@ -238,7 +238,12 @@ func buildVehicleCoverageSummarySQL(query url.Values) SQLQuery {
|
||||
groupSQL := `SELECT v.vin, ` +
|
||||
`COUNT(DISTINCT s.protocol) AS source_count, ` +
|
||||
`COUNT(DISTINCT CASE WHEN s.updated_at >= DATE_SUB(NOW(), INTERVAL 1 MINUTE) THEN s.protocol END) AS online_source_count, ` +
|
||||
`MAX(CASE WHEN b.vin IS NOT NULL AND b.vin <> '' THEN 1 ELSE 0 END) AS bound ` +
|
||||
`MAX(CASE WHEN b.vin IS NOT NULL AND b.vin <> '' THEN 1 ELSE 0 END) AS bound, ` +
|
||||
`CASE WHEN v.vin IS NOT NULL AND v.vin <> '' ` +
|
||||
`AND COALESCE(NULLIF(MAX(NULLIF(s.plate, '')), ''), NULLIF(MAX(NULLIF(b.plate, '')), '')) IS NOT NULL ` +
|
||||
`AND NULLIF(MAX(NULLIF(b.phone, '')), '') IS NOT NULL ` +
|
||||
`AND NULLIF(MAX(NULLIF(b.oem, '')), '') IS NOT NULL ` +
|
||||
`THEN 1 ELSE 0 END AS archive_complete ` +
|
||||
`FROM (` + vehicleSetSQL + `) v ` +
|
||||
`LEFT JOIN vehicle_identity_binding b ON b.vin = v.vin ` +
|
||||
`LEFT JOIN vehicle_realtime_snapshot s ON s.vin = v.vin ` +
|
||||
@@ -250,7 +255,8 @@ func buildVehicleCoverageSummarySQL(query url.Values) SQLQuery {
|
||||
`COALESCE(SUM(CASE WHEN source_count = 1 THEN 1 ELSE 0 END), 0) AS single_source_vehicles, ` +
|
||||
`COALESCE(SUM(CASE WHEN source_count > 1 THEN 1 ELSE 0 END), 0) AS multi_source_vehicles, ` +
|
||||
`COALESCE(SUM(CASE WHEN source_count = 0 THEN 1 ELSE 0 END), 0) AS no_data_vehicles, ` +
|
||||
`COALESCE(SUM(CASE WHEN bound = 0 THEN 1 ELSE 0 END), 0) AS unbound_vehicles ` +
|
||||
`COALESCE(SUM(CASE WHEN bound = 0 THEN 1 ELSE 0 END), 0) AS unbound_vehicles, ` +
|
||||
`COALESCE(SUM(CASE WHEN archive_complete = 0 THEN 1 ELSE 0 END), 0) AS archive_incomplete_vehicles ` +
|
||||
`FROM (` + groupSQL + `) vehicle_coverage_summary`,
|
||||
Args: args,
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ COALESCE(SUM(CASE WHEN source_count = 1 THEN 1 ELSE 0 END), 0) AS single_source_
|
||||
COALESCE(SUM(CASE WHEN source_count > 1 THEN 1 ELSE 0 END), 0) AS multi_source_vehicles,
|
||||
COALESCE(SUM(CASE WHEN source_count = 0 THEN 1 ELSE 0 END), 0) AS no_data_vehicles,
|
||||
COALESCE(SUM(CASE WHEN bound = 0 THEN 1 ELSE 0 END), 0) AS identity_required_vehicles,
|
||||
COALESCE(SUM(CASE WHEN archive_complete = 0 THEN 1 ELSE 0 END), 0) AS archive_incomplete_vehicles,
|
||||
COALESCE(SUM(CASE WHEN bound = 1 AND source_count = `+canonicalSourceCount+` AND online_source_count = source_count THEN 1 ELSE 0 END), 0) AS healthy_vehicles,
|
||||
COALESCE(SUM(CASE WHEN bound = 1 AND source_count > 0 AND online_source_count > 0 AND (online_source_count < source_count OR source_count < `+canonicalSourceCount+`) THEN 1 ELSE 0 END), 0) AS degraded_vehicles,
|
||||
COALESCE(SUM(CASE WHEN bound = 1 AND source_count > 0 AND online_source_count = 0 THEN 1 ELSE 0 END), 0) AS offline_vehicles
|
||||
@@ -132,7 +133,12 @@ FROM (
|
||||
SELECT v.vin,
|
||||
MAX(CASE WHEN b.vin IS NOT NULL AND b.vin <> '' THEN 1 ELSE 0 END) AS bound,
|
||||
COUNT(DISTINCT s.protocol) AS source_count,
|
||||
COUNT(DISTINCT CASE WHEN s.updated_at >= DATE_SUB(NOW(), INTERVAL 1 MINUTE) THEN s.protocol END) AS online_source_count
|
||||
COUNT(DISTINCT CASE WHEN s.updated_at >= DATE_SUB(NOW(), INTERVAL 1 MINUTE) THEN s.protocol END) AS online_source_count,
|
||||
CASE WHEN v.vin IS NOT NULL AND v.vin <> ''
|
||||
AND COALESCE(NULLIF(MAX(NULLIF(s.plate, '')), ''), NULLIF(MAX(NULLIF(b.plate, '')), '')) IS NOT NULL
|
||||
AND NULLIF(MAX(NULLIF(b.phone, '')), '') IS NOT NULL
|
||||
AND NULLIF(MAX(NULLIF(b.oem, '')), '') IS NOT NULL
|
||||
THEN 1 ELSE 0 END AS archive_complete
|
||||
FROM (
|
||||
SELECT vin FROM vehicle_identity_binding WHERE vin IS NOT NULL AND vin <> ''
|
||||
UNION
|
||||
@@ -157,6 +163,7 @@ GROUP BY v.vin
|
||||
&summary.MultiSourceVehicles,
|
||||
&summary.NoDataVehicles,
|
||||
&summary.IdentityRequiredVehicles,
|
||||
&summary.ArchiveIncompleteVehicles,
|
||||
&healthy,
|
||||
°raded,
|
||||
&offline,
|
||||
@@ -317,6 +324,7 @@ func (s *ProductionStore) VehicleCoverageSummary(ctx context.Context, query url.
|
||||
&summary.MultiSourceVehicles,
|
||||
&summary.NoDataVehicles,
|
||||
&summary.UnboundVehicles,
|
||||
&summary.ArchiveIncompleteVehicles,
|
||||
); err != nil {
|
||||
return VehicleCoverageSummary{}, err
|
||||
}
|
||||
|
||||
@@ -143,6 +143,7 @@ func TestBuildVehicleCoverageSummarySQL(t *testing.T) {
|
||||
"SUM(CASE WHEN online_source_count > 0 THEN 1 ELSE 0 END)",
|
||||
"SUM(CASE WHEN source_count > 1 THEN 1 ELSE 0 END)",
|
||||
"SUM(CASE WHEN source_count = 0 THEN 1 ELSE 0 END)",
|
||||
"SUM(CASE WHEN archive_complete = 0 THEN 1 ELSE 0 END)",
|
||||
"HAVING",
|
||||
"COUNT(DISTINCT s.protocol) > 1",
|
||||
} {
|
||||
|
||||
Reference in New Issue
Block a user