Skip to content

Commit

Permalink
Add logic to compare to scheduled first arrival
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJKim committed Aug 14, 2023
1 parent 68fc4b4 commit d0c2099
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
16 changes: 13 additions & 3 deletions lib/signs/utilities/early_am_suppression.ex
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,19 @@ defmodule Signs.Utilities.EarlyAmSuppression do
scheduled_time: scheduled
}}

{headway_top, headway_bottom} ->
# Make sure routes is nil so that destination is used as headsign
{%{headway_top | destination: destination, routes: nil}, headway_bottom}
{headway_top, %Headways.Bottom{range: {_, high}} = headway_bottom} ->
# Check against schedule to account for mezzanine sources having different first scheduled arrivals
if DateTime.add(current_time, high, :minute) |> DateTime.compare(scheduled) == :gt do
# Make sure routes is nil so that destination is used as headsign
{%{headway_top | destination: destination, routes: nil}, headway_bottom}
else
{%EarlyAm.DestinationTrain{
destination: destination
},
%EarlyAm.ScheduledTime{
scheduled_time: scheduled
}}
end
end

[message] ->
Expand Down
22 changes: 17 additions & 5 deletions test/signs/utilities/early_am_suppression_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,14 @@ defmodule Signs.Utilities.EarlyAmSuppresionTest do
{%Content.Message.Predictions{destination: :alewife, minutes: 3},
%Content.Message.Predictions{destination: :braintree, minutes: 4, certainty: 360}}

northbound_headways_inactive = {~U[2023-07-14 09:00:00Z], :alewife}
southbound_headways_active = {~U[2023-07-14 08:05:00Z], :southbound}

assert Signs.Utilities.EarlyAmSuppression.do_early_am_suppression(
current_content,
@current_time,
{:fully_suppressed, :partially_suppressed},
@schedule,
{northbound_headways_inactive, southbound_headways_active},
@mezzanine_sign
) ==
{
Expand All @@ -241,7 +244,7 @@ defmodule Signs.Utilities.EarlyAmSuppresionTest do
%Content.Message.GenericPaging{
messages: [
%Content.Message.EarlyAm.ScheduledTime{
scheduled_time: ~U[2023-07-14 08:00:00Z]
scheduled_time: ~U[2023-07-14 09:00:00Z]
},
%Content.Message.Headways.Bottom{prev_departure_mins: nil, range: {8, 10}}
]
Expand All @@ -254,11 +257,14 @@ defmodule Signs.Utilities.EarlyAmSuppresionTest do
{%Content.Message.Predictions{destination: :alewife, minutes: 3, certainty: 360},
%Content.Message.Predictions{destination: :braintree, minutes: 4, certainty: 360}}

southbound_headways_active = {~U[2023-07-14 08:05:00Z], :southbound}
northbound_headways_active = {~U[2023-07-14 08:05:00Z], :alewife}

assert Signs.Utilities.EarlyAmSuppression.do_early_am_suppression(
current_content,
@current_time,
{:partially_suppressed, :partially_suppressed},
@schedule,
{northbound_headways_active, southbound_headways_active},
@mezzanine_sign
) ==
{%Content.Message.Headways.Top{
Expand Down Expand Up @@ -391,11 +397,14 @@ defmodule Signs.Utilities.EarlyAmSuppresionTest do
zone: "m"
}}

southbound_headways_active = {~U[2023-07-14 08:05:00Z], :southbound}
northbound_headways_active = {~U[2023-07-14 08:05:00Z], :alewife}

assert Signs.Utilities.EarlyAmSuppression.do_early_am_suppression(
current_content,
@current_time,
{:partially_suppressed, :partially_suppressed},
@schedule,
{southbound_headways_active, northbound_headways_active},
@mezzanine_sign
) ==
{
Expand Down Expand Up @@ -444,11 +453,14 @@ defmodule Signs.Utilities.EarlyAmSuppresionTest do
]
}}

southbound_headways_active = {~U[2023-07-14 08:05:00Z], :southbound}
northbound_headways_active = {~U[2023-07-14 08:05:00Z], :alewife}

assert Signs.Utilities.EarlyAmSuppression.do_early_am_suppression(
current_content,
@current_time,
{:partially_suppressed, :partially_suppressed},
@schedule,
{southbound_headways_active, northbound_headways_active},
@mezzanine_sign
) ==
{%Content.Message.Headways.Top{
Expand Down

0 comments on commit d0c2099

Please sign in to comment.