Skip to content

Commit

Permalink
refactor counting of predictions
Browse files Browse the repository at this point in the history
  • Loading branch information
sloanelybutsurely committed May 16, 2024
1 parent 94b2052 commit c525734
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/screens/v2/widget_instance/line_map.ex
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,10 @@ defmodule Screens.V2.WidgetInstance.LineMap do
def serialize_scheduled_departure(departures, direction_id, stops, _is_terminal?) do
# Number of departures with predictions (not just schedules) in this direction
prediction_count =
departures
|> Stream.reject(fn %Departure{prediction: p} -> is_nil(p) end)
|> Stream.reject(fn %Departure{prediction: %Prediction{trip: t}} -> is_nil(t) end)
|> Stream.filter(fn %Departure{prediction: %Prediction{trip: %Trip{direction_id: d}}} ->
d == direction_id
end)
|> Enum.count()
Enum.count(
departures,
&match?(%Departure{prediction: %Prediction{trip: %Trip{direction_id: ^direction_id}}}, &1)
)

if prediction_count < 2 do
%{name: origin_stop_name} = Enum.at(stops, 0)
Expand Down

0 comments on commit c525734

Please sign in to comment.