Skip to content

Commit

Permalink
extract helper
Browse files Browse the repository at this point in the history
  • Loading branch information
panentheos committed Jan 7, 2025
1 parent eb6a5b6 commit d39ced6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/signs/realtime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit d39ced6

Please sign in to comment.