fix(open-platform): align realtime online status across protocols
This commit is contained in:
@@ -162,13 +162,20 @@ ORDER BY l.vin,
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
onlineThreshold := now.Add(-time.Minute)
|
||||
for rows.Next() {
|
||||
var point RealtimeVehiclePoint
|
||||
if err := rows.Scan(&point.VIN, &point.Protocol, &point.Longitude, &point.Latitude, &point.SpeedKmh, &point.TotalMileageKm, &point.ObservedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, exists := out[point.VIN]; !exists {
|
||||
point.Online = !point.ObservedAt.Before(onlineThreshold)
|
||||
if selected, exists := out[point.VIN]; !exists {
|
||||
out[point.VIN] = point
|
||||
} else if point.Online && !selected.Online {
|
||||
// The selected source still follows the documented protocol priority, but
|
||||
// online means that any source for this VIN reported in the last minute.
|
||||
selected.Online = true
|
||||
out[point.VIN] = selected
|
||||
}
|
||||
}
|
||||
return out, rows.Err()
|
||||
|
||||
Reference in New Issue
Block a user