diff --git a/lib/signs/realtime.ex b/lib/signs/realtime.ex index 0a526414..bb59c80d 100644 --- a/lib/signs/realtime.ex +++ b/lib/signs/realtime.ex @@ -213,8 +213,7 @@ defmodule Signs.Realtime do SourceConfig.sign_stop_ids(source) |> Stream.flat_map(&sign.last_trip_engine.get_recent_departures(&1)) |> Enum.count(fn {trip_id, departure_time} -> - # Use a 3 second buffer to make sure trips have fully departed - DateTime.to_unix(current_time) - DateTime.to_unix(departure_time) > 3 and + trip_departed?(departure_time, current_time) and sign.last_trip_engine.is_last_trip?(trip_id) end) @@ -223,6 +222,11 @@ defmodule Signs.Realtime do num_last_trips >= threshold end + defp trip_departed?(departure_time, current_time) do + # Use a 3 second buffer to make sure trips have fully departed + DateTime.to_unix(current_time) - DateTime.to_unix(departure_time) > 3 + end + defp prediction_key(prediction) do Map.take(prediction, [:stop_id, :route_id, :vehicle_id, :direction_id, :trip_id]) end