From d645163fd4cdecbc914a51d23d3021b223368f59 Mon Sep 17 00:00:00 2001 From: Brett Heath-Wlaz Date: Thu, 14 Sep 2023 11:20:26 -0400 Subject: [PATCH] read special boarding button announcement at Bowdoin --- lib/content/audio/boarding_button.ex | 12 ++++++++++++ lib/content/audio/predictions.ex | 8 +++++++- lib/content/message/predictions.ex | 8 +++++--- lib/signs/utilities/predictions.ex | 2 +- test/content/messages/predictions_test.exs | 16 ++++++++-------- test/signs/realtime_test.exs | 19 +++++++++++++++++-- 6 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 lib/content/audio/boarding_button.ex diff --git a/lib/content/audio/boarding_button.ex b/lib/content/audio/boarding_button.ex new file mode 100644 index 000000000..03221d162 --- /dev/null +++ b/lib/content/audio/boarding_button.ex @@ -0,0 +1,12 @@ +defmodule Content.Audio.BoardingButton do + alias PaEss.Utilities + defstruct [] + + defimpl Content.Audio do + @boarding_button_message "869" + + def to_params(_audio) do + Utilities.take_message([@boarding_button_message], :audio_visual) + end + end +end diff --git a/lib/content/audio/predictions.ex b/lib/content/audio/predictions.ex index 4d6865ff7..44e3c3262 100644 --- a/lib/content/audio/predictions.ex +++ b/lib/content/audio/predictions.ex @@ -7,6 +7,7 @@ defmodule Content.Audio.Predictions do require Logger require Content.Utilities + alias Content.Audio.BoardingButton alias Content.Audio.TrackChange alias Content.Audio.TrainIsBoarding alias Content.Audio.TrainIsArriving @@ -43,7 +44,12 @@ defmodule Content.Audio.Predictions do route_id: predictions.route_id, track_number: Content.Utilities.stop_track_number(predictions.stop_id) } - ] + ] ++ + if predictions.station_code == "BBOW" && predictions.zone == "e" do + [%BoardingButton{}] + else + [] + end predictions.minutes == :arriving -> [ diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index a142b1ae6..ccd9e3741 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -112,10 +112,10 @@ defmodule Content.Message.Predictions do end end - @spec terminal(Predictions.Prediction.t(), integer()) :: t() | nil - def terminal(prediction, width \\ 18) + @spec terminal(Predictions.Prediction.t(), String.t(), String.t(), integer()) :: t() | nil + def terminal(prediction, station_code, zone, width \\ 18) - def terminal(prediction, width) do + def terminal(prediction, station_code, zone, width) do stopped_at? = prediction.stops_away == 0 minutes = @@ -141,6 +141,8 @@ defmodule Content.Message.Predictions do direction_id: prediction.direction_id, width: width, new_cars?: prediction.new_cars?, + station_code: station_code, + zone: zone, terminal?: true, certainty: prediction.departure_certainty } diff --git a/lib/signs/utilities/predictions.ex b/lib/signs/utilities/predictions.ex index d88675947..08188aaa8 100644 --- a/lib/signs/utilities/predictions.ex +++ b/lib/signs/utilities/predictions.ex @@ -52,7 +52,7 @@ defmodule Signs.Utilities.Predictions do Content.Message.StoppedTrain.from_prediction(prediction) terminal_prediction?(prediction, sources) -> - Content.Message.Predictions.terminal(prediction) + Content.Message.Predictions.terminal(prediction, station_code, zone) true -> Content.Message.Predictions.non_terminal( diff --git a/test/content/messages/predictions_test.exs b/test/content/messages/predictions_test.exs index 0d23e6888..133df8368 100644 --- a/test/content/messages/predictions_test.exs +++ b/test/content/messages/predictions_test.exs @@ -301,7 +301,7 @@ defmodule Content.Message.PredictionsTest do log = capture_log([level: :warn], fn -> - assert is_nil(Content.Message.Predictions.terminal(prediction)) + assert is_nil(Content.Message.Predictions.terminal(prediction, "test", "m")) end) assert log =~ "no_destination_for_prediction" @@ -319,7 +319,7 @@ defmodule Content.Message.PredictionsTest do log = capture_log([level: :warn], fn -> - assert is_nil(Content.Message.Predictions.terminal(prediction)) + assert is_nil(Content.Message.Predictions.terminal(prediction, "test", "m")) end) assert log =~ "no_destination_for_prediction" @@ -336,7 +336,7 @@ defmodule Content.Message.PredictionsTest do boarding_status: "Stopped at station" } - msg = Content.Message.Predictions.terminal(prediction) + msg = Content.Message.Predictions.terminal(prediction, "test", "m") assert Content.Message.to_string(msg) == "Ashmont BRD" end @@ -352,7 +352,7 @@ defmodule Content.Message.PredictionsTest do boarding_status: "Stopped at station" } - msg = Content.Message.Predictions.terminal(prediction) + msg = Content.Message.Predictions.terminal(prediction, "test", "m") assert Content.Message.to_string(msg) == "Ashmont 1 min" end @@ -368,7 +368,7 @@ defmodule Content.Message.PredictionsTest do boarding_status: "Stopped at station" } - msg = Content.Message.Predictions.terminal(prediction) + msg = Content.Message.Predictions.terminal(prediction, "test", "m") assert Content.Message.to_string(msg) == "Ashmont 2 min" end @@ -383,7 +383,7 @@ defmodule Content.Message.PredictionsTest do destination_stop_id: "70261" } - msg = Content.Message.Predictions.terminal(prediction) + msg = Content.Message.Predictions.terminal(prediction, "test", "m") assert Content.Message.to_string(msg) == "Ashmont 1 min" end @@ -398,7 +398,7 @@ defmodule Content.Message.PredictionsTest do stops_away: 0 } - msg = Content.Message.Predictions.terminal(prediction) + msg = Content.Message.Predictions.terminal(prediction, "test", "m") assert Content.Message.to_string(msg) == [ {"Oak Grove 2 min", 6}, @@ -417,7 +417,7 @@ defmodule Content.Message.PredictionsTest do trip_id: "trip1" } - msg = Content.Message.Predictions.terminal(prediction) + msg = Content.Message.Predictions.terminal(prediction, "test", "m") assert msg.trip_id == "trip1" end diff --git a/test/signs/realtime_test.exs b/test/signs/realtime_test.exs index 8eee82b0d..bac3e908b 100644 --- a/test/signs/realtime_test.exs +++ b/test/signs/realtime_test.exs @@ -531,6 +531,20 @@ defmodule Signs.RealtimeTest do assert log =~ "no_passthrough_audio_for_prediction" end + + test "reads special boarding button announcement at Bowdoin" do + expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> + [prediction(arrival: 0, destination: :wonderland, stops_away: 0)] + end) + + expect_audios([ + {:canned, {"109", ["501", "21000", "507", "21000", "4044", "21000", "544"], :audio}}, + {:canned, {"103", ["869"], :audio_visual}} + ]) + + expect_messages({"Wonderland BRD", ""}) + Signs.Realtime.handle_info(:run_loop, %{@sign | text_id: {"BBOW", "e"}}) + end end describe "decrement_ticks/1" do @@ -547,14 +561,14 @@ defmodule Signs.RealtimeTest do end defp expect_messages(messages) do - expect(PaEss.Updater.Mock, :update_sign, fn {"TEST", "x"}, top, bottom, 145, :now, _sign_id -> + expect(PaEss.Updater.Mock, :update_sign, fn {_, _}, top, bottom, 145, :now, _sign_id -> assert {Content.Message.to_string(top), Content.Message.to_string(bottom)} == messages :ok end) end defp expect_audios(audios) do - expect(PaEss.Updater.Mock, :send_audio, fn {"TEST", ["x"]}, list, 5, 60, _sign_id -> + expect(PaEss.Updater.Mock, :send_audio, fn {_, _}, list, 5, 60, _sign_id -> assert Enum.map(list, &Content.Audio.to_params(&1)) == audios :ok end) @@ -572,6 +586,7 @@ defmodule Signs.RealtimeTest do :boston_college -> [route_id: "Green-B", direction_id: 0] :cleveland_circle -> [route_id: "Green-C", direction_id: 0] :riverside -> [route_id: "Green-D", direction_id: 0] + :wonderland -> [route_id: "Blue", direction_id: 1] nil -> [] end