Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show destination-based alert message on platform signs #846

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions lib/content/audio/no_service.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ defmodule Content.Audio.NoService do
use_shuttle?: use_shuttle?,
use_routes?: use_routes?
}) do
shuttle = if(use_shuttle?, do: " Use shuttle.", else: "")

cond do
use_routes? ->
suffix =
cond do
use_shuttle? -> " Use shuttle."
# Hardcoded for Union Square
"No Train Service. Use routes 86, 87, or 91"

destination ->
{:ok, destination_text} = PaEss.Utilities.destination_to_ad_hoc_string(destination)
"No #{destination_text} service.#{shuttle}"
use_routes? -> " Use routes 86, 87, or 91"
true -> ""
end

true ->
line = if(route, do: "#{route} Line", else: "train")
"There is no #{line} service at this station.#{shuttle}"
if destination do
{:ok, destination_text} = PaEss.Utilities.destination_to_ad_hoc_string(destination)
"No #{destination_text} service.#{suffix}"
else
line = if(route, do: "#{route} Line", else: "train")
"There is no #{line} service at this station.#{suffix}"
end
end
end
Expand Down
16 changes: 10 additions & 6 deletions lib/signs/utilities/messages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -239,33 +239,37 @@ defmodule Signs.Utilities.Messages do
end
end

defp alert_messages(alert_status, %{pa_ess_loc: "GUNS"}, _) do
defp alert_messages(alert_status, %{pa_ess_loc: "GUNS"}, config) do
route = Signs.Utilities.SourceConfig.single_route(config)
destination = config.headway_destination

if alert_status in [:none, :alert_along_route],
do: nil,
else: {%Alert.NoService{}, %Alert.UseRoutes{}}
else: {%Alert.NoService{route: route, destination: destination}, %Alert.UseRoutes{}}
end

defp alert_messages(alert_status, sign, config) do
route = Signs.Utilities.SourceConfig.single_route(config)
destination = config.headway_destination

case {alert_status, sign.uses_shuttles} do
{:shuttles_transfer_station, _} ->
{%Content.Message.Empty{}, %Content.Message.Empty{}}

{:shuttles_closed_station, true} ->
{%Alert.NoService{route: route}, %Alert.UseShuttleBus{}}
{%Alert.NoService{route: route, destination: destination}, %Alert.UseShuttleBus{}}

{:shuttles_closed_station, false} ->
{%Alert.NoService{route: route}, %Content.Message.Empty{}}
{%Alert.NoService{route: route, destination: destination}, %Content.Message.Empty{}}

{:suspension_transfer_station, _} ->
{%Content.Message.Empty{}, %Content.Message.Empty{}}

{:suspension_closed_station, _} ->
{%Alert.NoService{route: route}, %Content.Message.Empty{}}
{%Alert.NoService{route: route, destination: destination}, %Content.Message.Empty{}}

{:station_closure, _} ->
{%Alert.NoService{route: route}, %Content.Message.Empty{}}
{%Alert.NoService{route: route, destination: destination}, %Content.Message.Empty{}}

_ ->
nil
Expand Down
56 changes: 40 additions & 16 deletions test/signs/realtime_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -275,34 +275,54 @@ defmodule Signs.RealtimeTest do

test "when sign is at a station closed by shuttles and there are no predictions, it says so" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :shuttles_closed_station end)
expect_messages({"No Red Line", "Use shuttle bus"})
expect_messages({"No Southbound svc", "Use shuttle bus"})

expect_audios([{:canned, {"199", ["3005"], :audio}}], [
{"There is no Red Line service at this station. Use shuttle.", nil}
expect_audios([{:ad_hoc, {"No Southbound service. Use shuttle.", :audio}}], [
{"No Southbound service. Use shuttle.", nil}
])

Signs.Realtime.handle_info(:run_loop, @sign)
end

test "when sign is at a station closed and there are no predictions, but shuttles do not run at this station" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :shuttles_closed_station end)
expect_messages({"No Red Line", ""})
expect_audios([@no_service_audio], [{"There is no Red Line service at this station.", nil}])
expect_messages({"No Southbound svc", ""})

expect_audios([{:ad_hoc, {"No Southbound service.", :audio}}], [
{"No Southbound service.", nil}
])

Signs.Realtime.handle_info(:run_loop, %{@sign | uses_shuttles: false})
end

test "when sign is at a station closed due to suspension and there are no predictions, it says so" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :suspension_closed_station end)
expect_messages({"No Red Line", ""})
expect_audios([@no_service_audio], [{"There is no Red Line service at this station.", nil}])
expect_messages({"No Southbound svc", ""})

expect_audios([{:ad_hoc, {"No Southbound service.", :audio}}], [
{"No Southbound service.", nil}
])

Signs.Realtime.handle_info(:run_loop, @sign)
end

test "when sign is at a closed station and there are no predictions, it says so" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :station_closure end)
expect_messages({"No Southbound svc", ""})

expect_audios([{:ad_hoc, {"No Southbound service.", :audio}}], [
{"No Southbound service.", nil}
])

assert {_, %{announced_alert: true}} = Signs.Realtime.handle_info(:run_loop, @sign)
end

test "mezzanine sign with alert" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :station_closure end)
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :station_closure end)
expect_messages({"No Red Line", ""})
expect_audios([@no_service_audio], [{"There is no Red Line service at this station.", nil}])
assert {_, %{announced_alert: true}} = Signs.Realtime.handle_info(:run_loop, @sign)
Signs.Realtime.handle_info(:run_loop, @mezzanine_sign)
end

test "multi-route mezzanine sign with alert" do
Expand Down Expand Up @@ -384,8 +404,12 @@ defmodule Signs.RealtimeTest do
end)

expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :station_closure end)
expect_messages({"No Red Line", ""})
expect_audios([@no_service_audio], [{"There is no Red Line service at this station.", nil}])
expect_messages({"No Southbound svc", ""})

expect_audios([{:ad_hoc, {"No Southbound service.", :audio}}], [
{"No Southbound service.", nil}
])

Signs.Realtime.handle_info(:run_loop, @sign)
end

Expand Down Expand Up @@ -925,10 +949,10 @@ defmodule Signs.RealtimeTest do

test "reads alerts" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :shuttles_closed_station end)
expect_messages({"No Red Line", "Use shuttle bus"})
expect_messages({"No Southbound svc", "Use shuttle bus"})

expect_audios([{:canned, {"199", ["3005"], :audio}}], [
{"There is no Red Line service at this station. Use shuttle.", nil}
expect_audios([{:ad_hoc, {"No Southbound service. Use shuttle.", :audio}}], [
{"No Southbound service. Use shuttle.", nil}
])

Signs.Realtime.handle_info(:run_loop, %{@sign | tick_read: 0, announced_alert: true})
Expand Down Expand Up @@ -1598,10 +1622,10 @@ defmodule Signs.RealtimeTest do
text_zone: "x"
}

expect_messages({"No train service", "Use Routes 86, 87, or 91"})
expect_messages({"No Southbound svc", "Use Routes 86, 87, or 91"})

expect_audios([{:ad_hoc, {"No Train Service. Use routes 86, 87, or 91", :audio}}], [
{"No Train Service. Use routes 86, 87, or 91", nil}
expect_audios([{:ad_hoc, {"No Southbound service. Use routes 86, 87, or 91", :audio}}], [
{"No Southbound service. Use routes 86, 87, or 91", nil}
])

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