feat(monitor): aggregate nationwide fleet by province

This commit is contained in:
lingniu
2026-07-16 18:36:31 +08:00
parent ea4d576793
commit 21d1baada5
9 changed files with 598 additions and 32 deletions

View File

@@ -541,6 +541,33 @@ func TestMonitorMapUsesMeaningfulClustersAndReleasesPointsAtDetailZoom(t *testin
}
}
func TestMonitorMapNationwideReturnsScopedProvinceSeedsAndGridFallback(t *testing.T) {
vehicles := Page[VehicleRealtimeRow]{Items: []VehicleRealtimeRow{
{VIN: "GUANGDONG-1", Online: true, LocationAvailable: true, Longitude: 113.260, Latitude: 23.130},
{VIN: "GUANGDONG-2", Online: false, LocationAvailable: true, Longitude: 113.265, Latitude: 23.135, LastSeen: "2026-07-15T08:00:00+08:00"},
{VIN: "OUTSIDE-STATUS", Online: true, LocationAvailable: true, Longitude: 121.47, Latitude: 31.23, SpeedKmh: 20},
{VIN: "NO-LOCATION", Online: true},
}, Total: 4, Limit: 4}
result, err := buildMonitorMapResponse(vehicles, url.Values{
"zoom": {"5"},
"status": {"offline"},
"bounds": {"113,22,114,24"},
})
if err != nil {
t.Fatal(err)
}
if result.Mode != "provinces" || result.Total != 1 || len(result.ProvincePoints) != 1 {
t.Fatalf("nationwide response must expose only filtered, located province seeds: %+v", result)
}
if result.ProvincePoints[0].Status != "offline" || result.ProvincePoints[0].Longitude != 113.265 {
t.Fatalf("unexpected province seed: %+v", result.ProvincePoints[0])
}
if len(result.Points)+len(result.Clusters) == 0 {
t.Fatal("nationwide response must retain a grid fallback when AMap district data is unavailable")
}
}
func BenchmarkMonitorMapTenThousandVehicles(b *testing.B) {
vehicles := syntheticMonitorVehicles(10_000)
query := url.Values{"zoom": {"5"}}