From d39ced6244e01a9780e27500604cb9587f655b16 Mon Sep 17 00:00:00 2001 From: Brett Heath-Wlaz Date: Tue, 7 Jan 2025 10:32:45 -0500 Subject: [PATCH] extract helper --- lib/signs/realtime.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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