Skip to content

Commit

Permalink
adjust approaching and arriving visual messages (#833)
Browse files Browse the repository at this point in the history
  • Loading branch information
panentheos authored Oct 25, 2024
1 parent 110bff3 commit dee82d6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 49 deletions.
13 changes: 11 additions & 2 deletions lib/content/audio/approaching.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,17 @@ defmodule Content.Audio.Approaching do
end

def to_tts(%Content.Audio.Approaching{} = audio) do
text = tts_text(audio)
{text, PaEss.Utilities.paginate_text(text)}
train = PaEss.Utilities.train_description(audio.destination, audio.route_id, :visual)
crowding = PaEss.Utilities.crowding_text(audio.crowding_description)

new_cars =
if(audio.new_cars? && audio.route_id == "Red", do: "with all new Red Line cars", else: "")

pages =
[{train, "now approaching", 6}] ++
PaEss.Utilities.paginate_text(new_cars) ++ PaEss.Utilities.paginate_text(crowding)

{tts_text(audio), pages}
end

def to_logs(%Content.Audio.Approaching{}) do
Expand Down
6 changes: 4 additions & 2 deletions lib/content/audio/train_is_arriving.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ defmodule Content.Audio.TrainIsArriving do
end

def to_tts(%Content.Audio.TrainIsArriving{} = audio) do
text = tts_text(audio)
{text, PaEss.Utilities.paginate_text(text)}
train = PaEss.Utilities.train_description(audio.destination, audio.route_id, :visual)
crowding = PaEss.Utilities.crowding_text(audio.crowding_description)
pages = [{train, "now arriving", 6}] ++ PaEss.Utilities.paginate_text(crowding)
{tts_text(audio), pages}
end

def to_logs(%Content.Audio.TrainIsArriving{}) do
Expand Down
18 changes: 15 additions & 3 deletions lib/pa_ess/utilities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,23 @@ defmodule PaEss.Utilities do
def directional_destination?(destination),
do: destination in [:eastbound, :westbound, :southbound, :northbound, :inbound, :outbound]

def train_description(destination, route_id) do
@spec train_description(PaEss.destination(), String.t() | nil, :audio | :visual) :: String.t()
def train_description(destination, route_id, av \\ :audio) do
route_text =
case route_id do
"Green-" <> branch -> branch
_ -> nil
end

{:ok, destination_text} = destination_to_ad_hoc_string(destination)
destination_text =
case av do
:audio ->
{:ok, string} = destination_to_ad_hoc_string(destination)
string

:visual ->
destination_to_sign_string(destination)
end

if route_text do
"#{route_text} train to #{destination_text}"
Expand Down Expand Up @@ -699,7 +708,10 @@ defmodule PaEss.Utilities do
end
end
end,
fn acc -> {:cont, acc, nil} end
fn
nil -> {:cont, nil}
acc -> {:cont, acc, nil}
end
)
|> Stream.chunk_every(2, 2, [""])
|> Enum.map(fn [top, bottom] -> {top, bottom, 3} end)
Expand Down
1 change: 1 addition & 0 deletions test/pa_ess/utilities_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@ defmodule Content.Audio.UtilitiesTest do

assert [{"too-long", "word", 3}] = paginate_text(" too-long word ", 5)
assert [{"fits", "", 3}] = paginate_text("fits", 24)
assert [] = paginate_text("")
end
end
57 changes: 15 additions & 42 deletions test/signs/realtime_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,7 @@ defmodule Signs.RealtimeTest do

expect_audios([{:canned, {"103", ["90007"], :audio_visual}}], [
{"Attention passengers: The next C train to Cleveland Circle is now arriving.",
[
{"Attention passengers:", "The next C train to", 3},
{"Cleveland Circle is now", "arriving.", 3}
]}
[{"C train to Clvlnd Cir", "now arriving", 6}]}
])

Signs.Realtime.handle_info(:run_loop, @sign)
Expand All @@ -581,15 +578,9 @@ defmodule Signs.RealtimeTest do
],
[
{"Attention passengers: The next C train to Cleveland Circle is now arriving.",
[
{"Attention passengers:", "The next C train to", 3},
{"Cleveland Circle is now", "arriving.", 3}
]},
[{"C train to Clvlnd Cir", "now arriving", 6}]},
{"Attention passengers: The next D train to Riverside is now arriving.",
[
{"Attention passengers:", "The next D train to", 3},
{"Riverside is now", "arriving.", 3}
]}
[{"D train to Riverside", "now arriving", 6}]}
]
)

Expand Down Expand Up @@ -739,7 +730,7 @@ defmodule Signs.RealtimeTest do

expect_audios([{:canned, {"103", ["32127"], :audio_visual}}], [
{"Attention passengers: The next Ashmont train is now approaching.",
[{"Attention passengers:", "The next Ashmont train", 3}, {"is now approaching.", "", 3}]}
[{"Ashmont train", "now approaching", 6}]}
])

assert {_, %{announced_approachings: ["1"]}} = Signs.Realtime.handle_info(:run_loop, @sign)
Expand Down Expand Up @@ -798,7 +789,7 @@ defmodule Signs.RealtimeTest do

expect_audios([{:canned, {"103", ["32127"], :audio_visual}}], [
{"Attention passengers: The next Ashmont train is now approaching.",
[{"Attention passengers:", "The next Ashmont train", 3}, {"is now approaching.", "", 3}]}
[{"Ashmont train", "now approaching", 6}]}
])

assert {_, %{tick_read: 119}} =
Expand All @@ -818,10 +809,7 @@ defmodule Signs.RealtimeTest do

expect_audios([{:canned, {"103", ["32123"], :audio_visual}}], [
{"Attention passengers: The next Forest Hills train is now approaching.",
[
{"Attention passengers:", "The next Forest Hills", 3},
{"train is now", "approaching.", 3}
]}
[{"Frst Hills train", "now approaching", 6}]}
])

assert {_, %{announced_approachings_with_crowding: ["1"]}} =
Expand All @@ -841,10 +829,7 @@ defmodule Signs.RealtimeTest do

expect_audios([{:canned, {"103", ["32123"], :audio_visual}}], [
{"Attention passengers: The next Forest Hills train is now approaching.",
[
{"Attention passengers:", "The next Forest Hills", 3},
{"train is now", "approaching.", 3}
]}
[{"Frst Hills train", "now approaching", 6}]}
])

assert {_, %{announced_approachings_with_crowding: []}} =
Expand All @@ -864,10 +849,7 @@ defmodule Signs.RealtimeTest do

expect_audios([{:canned, {"103", ["32103"], :audio_visual}}], [
{"Attention passengers: The next Forest Hills train is now arriving.",
[
{"Attention passengers:", "The next Forest Hills", 3},
{"train is now arriving.", "", 3}
]}
[{"Frst Hills train", "now arriving", 6}]}
])

Signs.Realtime.handle_info(:run_loop, @sign)
Expand All @@ -886,10 +868,7 @@ defmodule Signs.RealtimeTest do

expect_audios([{:canned, {"103", ["32103"], :audio_visual}}], [
{"Attention passengers: The next Forest Hills train is now arriving.",
[
{"Attention passengers:", "The next Forest Hills", 3},
{"train is now arriving.", "", 3}
]}
[{"Frst Hills train", "now arriving", 6}]}
])

Signs.Realtime.handle_info(:run_loop, @sign)
Expand All @@ -908,10 +887,7 @@ defmodule Signs.RealtimeTest do

expect_audios([{:canned, {"103", ["32103"], :audio_visual}}], [
{"Attention passengers: The next Forest Hills train is now arriving.",
[
{"Attention passengers:", "The next Forest Hills", 3},
{"train is now arriving.", "", 3}
]}
[{"Frst Hills train", "now arriving", 6}]}
])

Signs.Realtime.handle_info(:run_loop, %{@sign | announced_approachings_with_crowding: ["1"]})
Expand Down Expand Up @@ -1038,7 +1014,7 @@ defmodule Signs.RealtimeTest do

expect_audios([{:canned, {"103", ["32107"], :audio_visual}}], [
{"Attention passengers: The next Ashmont train is now arriving.",
[{"Attention passengers:", "The next Ashmont train", 3}, {"is now arriving.", "", 3}]}
[{"Ashmont train", "now arriving", 6}]}
])

Signs.Realtime.handle_info(:run_loop, %{
Expand Down Expand Up @@ -1097,7 +1073,7 @@ defmodule Signs.RealtimeTest do
],
[
{"Attention passengers: The next Ashmont train is now arriving.",
[{"Attention passengers:", "The next Ashmont train", 3}, {"is now arriving.", "", 3}]},
[{"Ashmont train", "now arriving", 6}]},
{"The following Ashmont train arrives in 2 minutes", nil}
]
)
Expand All @@ -1124,7 +1100,7 @@ defmodule Signs.RealtimeTest do
[
{"The next Ashmont train arrives in 2 minutes.", nil},
{"Attention passengers: The next Alewife train is now arriving.",
[{"Attention passengers:", "The next Alewife train", 3}, {"is now arriving.", "", 3}]}
[{"Alewife train", "now arriving", 6}]}
]
)

Expand Down Expand Up @@ -1548,10 +1524,7 @@ defmodule Signs.RealtimeTest do

expect_audios([{:canned, {"106", ["783", "4016", "21000", "786"], :audio_visual}}], [
{"Attention passengers: The next Ashmont train is now approaching, with all new Red Line cars.",
[
{"Attention passengers:", "The next Ashmont train", 3},
{"is now approaching, with", "all new Red Line cars.", 3}
]}
[{"Ashmont train", "now approaching", 6}, {"with all new Red Line", "cars", 3}]}
])

Signs.Realtime.handle_info(:run_loop, @sign)
Expand Down Expand Up @@ -1580,7 +1553,7 @@ defmodule Signs.RealtimeTest do

expect_audios([{:canned, {"103", ["32127"], :audio_visual}}], [
{"Attention passengers: The next Ashmont train is now approaching.",
[{"Attention passengers:", "The next Ashmont train", 3}, {"is now approaching.", "", 3}]}
[{"Ashmont train", "now approaching", 6}]}
])

Signs.Realtime.handle_info(:run_loop, @sign)
Expand Down

0 comments on commit dee82d6

Please sign in to comment.