From c525734d1e80d61507eec3d6b43038f00f8ada36 Mon Sep 17 00:00:00 2001 From: sloane <1699281+sloanelybutsurely@users.noreply.github.com> Date: Thu, 16 May 2024 13:47:42 -0400 Subject: [PATCH] refactor counting of predictions --- lib/screens/v2/widget_instance/line_map.ex | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/screens/v2/widget_instance/line_map.ex b/lib/screens/v2/widget_instance/line_map.ex index 6d9a70ebe..60c0500de 100644 --- a/lib/screens/v2/widget_instance/line_map.ex +++ b/lib/screens/v2/widget_instance/line_map.ex @@ -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)