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

Modify "End of service" text to specify routes and/or directions #759

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion lib/content/message/last_trip/platform_closed.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Content.Message.LastTrip.PlatformClosed do

defimpl Content.Message do
def to_string(%Content.Message.LastTrip.PlatformClosed{}) do
"Platform closed"
"Service ended"
end
end
end
13 changes: 10 additions & 3 deletions lib/content/message/last_trip/service_ended.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ defmodule Content.Message.LastTrip.ServiceEnded do
A message displayed when a station is closed
"""
@enforce_keys []
defstruct @enforce_keys
defstruct @enforce_keys ++ [:destination]

@type t :: %__MODULE__{}
@type t :: %__MODULE__{
destination: PaEss.destination()
}

defimpl Content.Message do
def to_string(%Content.Message.LastTrip.ServiceEnded{}) do
def to_string(%Content.Message.LastTrip.ServiceEnded{destination: nil}) do
"Service ended for night"
end

def to_string(%Content.Message.LastTrip.ServiceEnded{destination: destination}) do
headsign = PaEss.Utilities.destination_to_sign_string(destination)
"No #{headsign} trains"
end
end
end
9 changes: 6 additions & 3 deletions lib/content/message/last_trip/station_closed.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ defmodule Content.Message.LastTrip.StationClosed do
A message displayed when a station is closed
"""
@enforce_keys []
defstruct @enforce_keys
defstruct @enforce_keys ++ [routes: []]

@type t :: %__MODULE__{}

defimpl Content.Message do
def to_string(%Content.Message.LastTrip.StationClosed{}) do
"Station closed"
def to_string(%Content.Message.LastTrip.StationClosed{routes: routes}) do
case PaEss.Utilities.get_line_from_routes_list(routes) do
"train" -> "Station closed"
line -> "No #{line}"
end
end
end
end
35 changes: 24 additions & 11 deletions lib/signs/utilities/last_trip.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ defmodule Signs.Utilities.LastTrip do
case service_status do
{has_top_service_ended?, has_bottom_service_ended?} ->
{unpacked_mz_top, unpacked_mz_bottom} = unpack_mezzanine_content(messages, source)
{top_source, bottom_source} = source
{top_source_config, bottom_source_config} = source

routes =
Enum.flat_map(
top_source_config.sources ++ bottom_source_config.sources,
&List.wrap(&1.routes)
)

cond do
# If combined alert status, only switch to Last Trip messaging once service has fully ended.
Expand All @@ -19,26 +25,27 @@ defmodule Signs.Utilities.LastTrip do
match?(%Message.Alert.NoService{}, unpacked_mz_top) ->
if has_top_service_ended? and has_bottom_service_ended?,
do:
{%Content.Message.LastTrip.StationClosed{},
{%Content.Message.LastTrip.StationClosed{routes: routes},
%Content.Message.LastTrip.ServiceEnded{}},
else: messages

has_top_service_ended? and has_bottom_service_ended? and
not is_prediction?(unpacked_mz_top) and
not is_prediction?(unpacked_mz_bottom) ->
{%Content.Message.LastTrip.StationClosed{}, %Content.Message.LastTrip.ServiceEnded{}}
{%Content.Message.LastTrip.StationClosed{routes: routes},
%Content.Message.LastTrip.ServiceEnded{}}

has_top_service_ended? and not is_prediction?(unpacked_mz_top) and
not is_empty?(unpacked_mz_bottom) ->
if get_message_length(unpacked_mz_bottom) <= 18 do
{unpacked_mz_bottom,
%Content.Message.LastTrip.NoService{
destination: top_source.headway_destination,
destination: top_source_config.headway_destination,
line: :bottom
}}
else
{%Content.Message.LastTrip.NoService{
destination: top_source.headway_destination,
destination: top_source_config.headway_destination,
line: :top
}, unpacked_mz_bottom}
end
Expand All @@ -48,12 +55,12 @@ defmodule Signs.Utilities.LastTrip do
if get_message_length(unpacked_mz_top) <= 18 do
{unpacked_mz_top,
%Content.Message.LastTrip.NoService{
destination: bottom_source.headway_destination,
destination: bottom_source_config.headway_destination,
line: :bottom
}}
else
{%Content.Message.LastTrip.NoService{
destination: bottom_source.headway_destination,
destination: bottom_source_config.headway_destination,
line: :top
}, unpacked_mz_top}
end
Expand All @@ -67,12 +74,12 @@ defmodule Signs.Utilities.LastTrip do
not (is_prediction?(top_message) or is_prediction?(bottom_message)),
do:
{%LastTrip.PlatformClosed{destination: source.headway_destination},
%LastTrip.ServiceEnded{}},
%LastTrip.ServiceEnded{destination: source.headway_destination}},
else: messages
end
end

defp unpack_mezzanine_content(messages, {top_source, bottom_source}) do
defp unpack_mezzanine_content(messages, {top_source_config, bottom_source_config}) do
case messages do
# JFK/UMass case
{%Message.GenericPaging{messages: [prediction, headway_top]},
Expand All @@ -83,8 +90,14 @@ defmodule Signs.Utilities.LastTrip do
}, %{prediction | zone: "m"}}

{%Message.Headways.Top{}, %Message.Headways.Bottom{range: range}} ->
{%Message.Headways.Paging{destination: top_source.headway_destination, range: range},
%Message.Headways.Paging{destination: bottom_source.headway_destination, range: range}}
{%Message.Headways.Paging{
destination: top_source_config.headway_destination,
range: range
},
%Message.Headways.Paging{
destination: bottom_source_config.headway_destination,
range: range
}}

_ ->
messages
Expand Down
33 changes: 31 additions & 2 deletions test/signs/realtime_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ defmodule Signs.RealtimeTest do
current_content_bottom: "Every 11 to 13 min"
}

@mezzanine_sign_with_routes %{
@mezzanine_sign
| source_config: {
%{
sources: [%{@src | routes: ["Orange"]}],
headway_group: "group",
headway_destination: :northbound
},
%{
sources: [%{@src_2 | routes: ["Orange"]}],
headway_group: "group",
headway_destination: :southbound
}
},
current_content_top: "Orange line trains",
current_content_bottom: "Every 11 to 13 min"
}

@jfk_mezzanine_sign %{
@sign
| pa_ess_loc: "RJFK",
Expand Down Expand Up @@ -1390,7 +1408,7 @@ defmodule Signs.RealtimeTest do
| tick_read: 0
}

expect_messages({"Platform closed", "Service ended for night"})
expect_messages({"Service ended", "No Southbound trains"})
expect_audios(canned: {"107", ["884", "21000", "787", "21000", "882"], :audio})
Signs.Realtime.handle_info(:run_loop, sign)
end
Expand All @@ -1406,9 +1424,20 @@ defmodule Signs.RealtimeTest do
Signs.Realtime.handle_info(:run_loop, sign)
end

test "Station with routes is closed" do
sign = %{
@mezzanine_sign_with_routes
| tick_read: 0
}

expect_messages({"No Orange Line", "Service ended for night"})
expect_audios(canned: {"103", ["883"], :audio})
Signs.Realtime.handle_info(:run_loop, sign)
end

test "No service goes on bottom line when top line fits in 18 chars or less" do
sign = %{
@mezzanine_sign
@mezzanine_sign_with_routes
| tick_read: 0,
announced_stalls: [{"a", 8}]
}
Expand Down
Loading