Skip to content

Commit

Permalink
read special boarding button announcement at Bowdoin
Browse files Browse the repository at this point in the history
  • Loading branch information
panentheos committed Sep 14, 2023
1 parent b357649 commit d645163
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
12 changes: 12 additions & 0 deletions lib/content/audio/boarding_button.ex
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion lib/content/audio/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
[
Expand Down
8 changes: 5 additions & 3 deletions lib/content/message/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion lib/signs/utilities/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 8 additions & 8 deletions test/content/messages/predictions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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},
Expand All @@ -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
Expand Down
19 changes: 17 additions & 2 deletions test/signs/realtime_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit d645163

Please sign in to comment.