Skip to content

Commit

Permalink
Modify "End of service" text to specify routes and/or directions (#759)
Browse files Browse the repository at this point in the history
* feat: new single direction end of service message

Changes message from

    Platform closed
    Service ended for night

      to

    Service ended
    No <headsign> trains

* feat: new bidirectional end of service message

Changes message from

    Station closed
    Service ended for night

      to

    No <line>
    Service ended for night

* refactor: use sign_routes/1

Co-authored-by: Paul Kim <[email protected]>

* fix: include ended route in audio readout

---------

Co-authored-by: Paul Kim <[email protected]>
  • Loading branch information
sloanelybutsurely and PaulJKim authored Jun 5, 2024
1 parent 6974e00 commit 601a679
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 27 deletions.
18 changes: 12 additions & 6 deletions lib/content/audio/service_ended.ex
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
defmodule Content.Audio.ServiceEnded do
alias PaEss.Utilities
@enforce_keys [:location]
defstruct @enforce_keys ++ [:destination]
defstruct @enforce_keys ++ [:destination, :routes]

@type location :: :platform | :station | :direction
@type t :: %__MODULE__{
destination: PaEss.destination(),
routes: [String.t()] | nil,
location: location()
}

def from_message(%Content.Message.LastTrip.StationClosed{}) do
[%__MODULE__{location: :station}]
def from_message(%Content.Message.LastTrip.StationClosed{routes: routes}) do
[%__MODULE__{location: :station, routes: routes}]
end

def from_message(%Content.Message.LastTrip.PlatformClosed{destination: destination}) do
Expand All @@ -23,11 +24,16 @@ defmodule Content.Audio.ServiceEnded do

defimpl Content.Audio do
@service_ended "882"
@station_closed "883"
# @station_closed "883"
@platform_closed "884"

def to_params(%Content.Audio.ServiceEnded{location: :station}) do
Utilities.take_message([@station_closed], :audio)
def to_params(%Content.Audio.ServiceEnded{location: :station, routes: routes}) do
line_var =
routes
|> Utilities.get_line_from_routes_list()
|> Utilities.line_to_var()

Utilities.take_message([line_var, @service_ended], :audio)
end

def to_params(
Expand Down
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
31 changes: 20 additions & 11 deletions lib/signs/utilities/last_trip.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ 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 = Signs.Utilities.SourceConfig.sign_routes(source)

cond do
# If combined alert status, only switch to Last Trip messaging once service has fully ended.
Expand All @@ -19,26 +21,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 +51,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 +70,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 +86,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
35 changes: 32 additions & 3 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 @@ -1402,13 +1420,24 @@ defmodule Signs.RealtimeTest do
}

expect_messages({"Station closed", "Service ended for night"})
expect_audios(canned: {"103", ["883"], :audio})
expect_audios(canned: {"105", ["864", "21000", "882"], :audio})
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: {"105", ["3006", "21000", "882"], :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

0 comments on commit 601a679

Please sign in to comment.