Skip to content

Commit

Permalink
feat: new bidirectional end of service message
Browse files Browse the repository at this point in the history
Changes message from

    Station closed
    Service ended for night

      to

    No <line>
    Service ended for night
  • Loading branch information
sloanelybutsurely committed Jun 4, 2024
1 parent 23f521d commit 2619eb4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/content/message/last_trip/service_ended.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Content.Message.LastTrip.ServiceEnded do

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

def to_string(%Content.Message.LastTrip.ServiceEnded{destination: destination}) do
Expand Down
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
33 changes: 23 additions & 10 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 @@ -72,7 +79,7 @@ defmodule Signs.Utilities.LastTrip do
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
31 changes: 30 additions & 1 deletion 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 @@ -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

0 comments on commit 2619eb4

Please sign in to comment.