Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vehicles): add logging if a non-shuttle vehicle has a null direction_id #854

Merged
merged 8 commits into from
Jan 22, 2025
14 changes: 14 additions & 0 deletions apps/state/lib/state/vehicle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,23 @@ defmodule State.Vehicle do

@impl State.Server
def pre_insert_hook(vehicle) do
if has_invalid_dir(vehicle) do
Logger.error("Found vehicle with invalid direction: #{inspect(vehicle)}")
rudiejd marked this conversation as resolved.
Show resolved Hide resolved
end

update_effective_route_id(vehicle)
end

@spec has_invalid_dir(Vehicle.t()) :: boolean()
defp has_invalid_dir(vehicle) do
not_shuttle = vehicle.route_id != nil and not String.contains?(vehicle.route_id, "Shuttle")
rudiejd marked this conversation as resolved.
Show resolved Hide resolved

invalid_dir =
vehicle.direction_id == nil or vehicle.direction_id > 1 or vehicle.direction_id < 0
rudiejd marked this conversation as resolved.
Show resolved Hide resolved

not_shuttle and invalid_dir
end

defp update_effective_route_id(%Vehicle{trip_id: trip_id} = vehicle) do
case Trip.by_id(trip_id) do
[] ->
Expand Down
Loading