Skip to content

Commit

Permalink
Omit GL from multi destination logic (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJKim authored Sep 18, 2023
1 parent 51de9d0 commit 7382fb7
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions lib/signs/utilities/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ defmodule Signs.Utilities.Predictions do
SourceConfig.config(),
Signs.Realtime.t()
) :: Signs.Realtime.sign_messages()
defp prediction_messages(predictions, %{sources: sources}, %{text_id: {station_code, zone}}) do
defp prediction_messages(
predictions,
%{sources: sources},
%{text_id: {station_code, zone}} = sign
) do
predictions
|> Enum.filter(fn p ->
p.seconds_until_departure
Expand Down Expand Up @@ -71,16 +75,10 @@ defmodule Signs.Utilities.Predictions do
# Take next two predictions, but if the list has multiple destinations, prefer showing
# distinct ones. This helps e.g. the red line trunk where people may need to know about
# a particular branch.
|> case do
[msg1, msg2 | rest] ->
case Enum.find([msg2 | rest], fn x -> x.destination != msg1.destination end) do
nil -> [msg1, msg2]
preferred -> [msg1, preferred]
end

messages ->
messages
end
|> get_unique_destination_predictions(
SourceConfig.sign_routes(sign.source_config)
|> PaEss.Utilities.get_unique_routes()
)
|> case do
[] ->
{Content.Message.Empty.new(), Content.Message.Empty.new()}
Expand All @@ -103,6 +101,24 @@ defmodule Signs.Utilities.Predictions do
end
end

defp get_unique_destination_predictions(predictions, sign_routes)
when sign_routes == ["Green"] do
Enum.take(predictions, 2)
end

defp get_unique_destination_predictions(predictions, _) do
case predictions do
[msg1, msg2 | rest] ->
case Enum.find([msg2 | rest], fn x -> x.destination != msg1.destination end) do
nil -> [msg1, msg2]
preferred -> [msg1, preferred]
end

messages ->
messages
end
end

@spec get_passthrough_train_audio(Signs.Realtime.predictions()) :: [Content.Audio.t()]
def get_passthrough_train_audio({top_predictions, bottom_predictions}) do
prediction_passthrough_audios(top_predictions) ++
Expand Down

0 comments on commit 7382fb7

Please sign in to comment.