Skip to content

Filter out VehicleActivities with invalid location - #244

Closed
bnordli wants to merge 2 commits into
entur:masterfrom
bnordli:fix/filter-invalid-zero-vehicle-location
Closed

Filter out VehicleActivities with invalid location#244
bnordli wants to merge 2 commits into
entur:masterfrom
bnordli:fix/filter-invalid-zero-vehicle-location

Conversation

@bnordli

@bnordli bnordli commented Aug 11, 2026

Copy link
Copy Markdown

Actually remove vehicle positions with 0 lat or long from the live feed, instead of just reporting invalid positions.

dev notes:

  • It might be that report-only is the intended behavior, but this has been submitted by an end user:
attachment1786426044611_50pct
  • Vehicles in England or Brazil (say) may have actually valid exact 0 coordinates, but I think in general it is better to remove updates where any coordinate is == 0 (as opposed to both). In these (rare) cases, the next update should be processed as normal.

isLocationValid() already detected null/zero coordinates on VehicleMonitoring updates, but its result was only used to increment a metrics counter — the activity had already been unconditionally added to the changes map beforehand. This meant vehicles reported at 0N/0W (or with a zero-only lat or lon) were logged as invalid but still stored and served to clients.

Move the isLocationValid() check into the storage-gating condition so invalid-location activities are actually dropped.

Added regression tests covering 0/0, lat-only-zero, lon-only-zero, and null VehicleLocation.

bnordli and others added 2 commits August 11, 2026 08:13
isLocationValid() already detected null/zero coordinates on
VehicleMonitoring updates, but its result was only used to increment
a metrics counter — the activity had already been unconditionally
added to the changes map beforehand. This meant vehicles reported at
0N/0W (or with a zero-only lat or lon) were logged as invalid but
still stored and served to clients.

Move the isLocationValid() check into the storage-gating condition so
invalid-location activities are actually dropped. Also renamed the
shadowing local `keep` variable (meaning "is newer than existing") to
`isNewer` to avoid conflating it with location validity again.

Added regression tests covering 0/0, lat-only-zero, lon-only-zero, and
null VehicleLocation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Restore the pre-existing behavior where outdatedCounter and
invalidLocationCounter are each evaluated independently (matching how
notMeaningfulCounter already works), instead of the mutually-exclusive
if/else-if chain introduced in the previous commit. A single rejected
update that is both expired/not-newer and has an invalid location will
again increment both counters.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@bnordli

bnordli commented Aug 11, 2026

Copy link
Copy Markdown
Author

Another (live) example, from another operator:
image

@lassetyr

Copy link
Copy Markdown
Contributor

Keeping these "invalid" updates is intentional.

"Low quality data" is reported back to the data-producers, and removing them at this point will result in this "data-error" no longer being reported.

I have instead added an optional filter in the user/customer-facing api to hide them from regular usage (but still available when explicitly requested): entur/vehicle-positions#40

@lassetyr lassetyr closed this Aug 11, 2026
@bnordli

bnordli commented Aug 11, 2026

Copy link
Copy Markdown
Author

Got it, thanks!

@bnordli

bnordli commented Aug 11, 2026

Copy link
Copy Markdown
Author

Is it possible to verify that this other fix will resolve the issue for the end user?

(Note that the user has explicitly chosen a bus to view the position of.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants