feat(monitor): aggregate nationwide fleet by province
This commit is contained in:
@@ -373,6 +373,7 @@ const (
|
||||
monitorVehicleLimit = 10000
|
||||
monitorPointLimit = 2000
|
||||
monitorPointZoom = 11
|
||||
monitorProvinceMaxZoom = 5
|
||||
monitorClusterGridPixels = 64
|
||||
vehicleSearchKeywordLimit = 100
|
||||
)
|
||||
@@ -606,17 +607,19 @@ func buildMonitorMapResponse(vehicles Page[VehicleRealtimeRow], query url.Values
|
||||
if zoom > 20 {
|
||||
zoom = 20
|
||||
}
|
||||
provinceMode := zoom <= monitorProvinceMaxZoom
|
||||
bounds, hasBounds, err := parseMonitorBounds(query.Get("bounds"))
|
||||
if err != nil {
|
||||
return MonitorMapResponse{}, err
|
||||
}
|
||||
result := MonitorMapResponse{
|
||||
Mode: "clusters",
|
||||
Zoom: zoom,
|
||||
Truncated: vehicles.Total > len(vehicles.Items),
|
||||
Points: []MonitorMapPoint{},
|
||||
Clusters: []MonitorMapCluster{},
|
||||
AsOf: time.Now().UTC().Format(time.RFC3339),
|
||||
Mode: "clusters",
|
||||
Zoom: zoom,
|
||||
Truncated: vehicles.Total > len(vehicles.Items),
|
||||
Points: []MonitorMapPoint{},
|
||||
Clusters: []MonitorMapCluster{},
|
||||
ProvincePoints: []MonitorMapProvincePoint{},
|
||||
AsOf: time.Now().UTC().Format(time.RFC3339),
|
||||
}
|
||||
points := make([]MonitorMapPoint, 0, len(vehicles.Items))
|
||||
for _, vehicle := range vehicles.Items {
|
||||
@@ -627,7 +630,17 @@ func buildMonitorMapResponse(vehicles Page[VehicleRealtimeRow], query url.Values
|
||||
continue
|
||||
}
|
||||
result.Total++
|
||||
if hasBounds && !bounds.contains(vehicle.Longitude, vehicle.Latitude) {
|
||||
status := monitorVehicleStatus(vehicle)
|
||||
if provinceMode {
|
||||
result.ProvincePoints = append(result.ProvincePoints, MonitorMapProvincePoint{
|
||||
Longitude: vehicle.Longitude,
|
||||
Latitude: vehicle.Latitude,
|
||||
Status: status,
|
||||
})
|
||||
}
|
||||
// Nationwide province counts describe the complete filtered fleet, not
|
||||
// only the current slippy-map rectangle. Bounds resume after drill-down.
|
||||
if hasBounds && !provinceMode && !bounds.contains(vehicle.Longitude, vehicle.Latitude) {
|
||||
continue
|
||||
}
|
||||
points = append(points, MonitorMapPoint{
|
||||
@@ -637,7 +650,7 @@ func buildMonitorMapResponse(vehicles Page[VehicleRealtimeRow], query url.Values
|
||||
ReportIntervalMs: vehicle.ReportIntervalMs,
|
||||
LocationSource: vehicle.LocationSource,
|
||||
LocationConflict: vehicle.LocationConflict,
|
||||
Status: monitorVehicleStatus(vehicle),
|
||||
Status: status,
|
||||
})
|
||||
}
|
||||
if zoom >= monitorPointZoom && len(points) <= monitorPointLimit {
|
||||
@@ -708,6 +721,9 @@ func buildMonitorMapResponse(vehicles Page[VehicleRealtimeRow], query url.Values
|
||||
result.Mode = "points"
|
||||
}
|
||||
}
|
||||
if provinceMode {
|
||||
result.Mode = "provinces"
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user