diff --git a/lib/content/message/last_trip/service_ended.ex b/lib/content/message/last_trip/service_ended.ex index 1076084ce..b3441ed29 100644 --- a/lib/content/message/last_trip/service_ended.ex +++ b/lib/content/message/last_trip/service_ended.ex @@ -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 diff --git a/lib/content/message/last_trip/station_closed.ex b/lib/content/message/last_trip/station_closed.ex index 3b57bba0a..95d105936 100644 --- a/lib/content/message/last_trip/station_closed.ex +++ b/lib/content/message/last_trip/station_closed.ex @@ -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 diff --git a/lib/signs/utilities/last_trip.ex b/lib/signs/utilities/last_trip.ex index 9c7722117..921f7742c 100644 --- a/lib/signs/utilities/last_trip.ex +++ b/lib/signs/utilities/last_trip.ex @@ -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. @@ -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 @@ -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 @@ -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]}, @@ -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 diff --git a/test/signs/realtime_test.exs b/test/signs/realtime_test.exs index 9a4e79210..2e683d9dd 100644 --- a/test/signs/realtime_test.exs +++ b/test/signs/realtime_test.exs @@ -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", @@ -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}] }