Skip to content

Commit

Permalink
Address early AM bugs (#674)
Browse files Browse the repository at this point in the history
* Address bugs

* Change Kenmore B platforms to use green_b headway group
  • Loading branch information
PaulJKim authored Aug 18, 2023
1 parent e559993 commit 20d3add
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 5 additions & 3 deletions lib/content/message/stopped_train.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ defmodule Content.Message.StoppedTrain do
require Logger

@enforce_keys [:destination, :stops_away]
defstruct @enforce_keys ++ [:certainty]
defstruct @enforce_keys ++ [:certainty, :stop_id]

@type t :: %__MODULE__{
destination: PaEss.destination(),
stops_away: non_neg_integer(),
certainty: non_neg_integer() | nil
certainty: non_neg_integer() | nil,
stop_id: String.t()
}

@spec from_prediction(Predictions.Prediction.t()) :: t() | nil
Expand All @@ -34,7 +35,8 @@ defmodule Content.Message.StoppedTrain do
%__MODULE__{
destination: destination,
stops_away: stops_away,
certainty: prediction.arrival_certainty || prediction.departure_certainty
certainty: prediction.arrival_certainty || prediction.departure_certainty,
stop_id: prediction.stop_id
}

{:error, _} ->
Expand Down
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 @@ -166,6 +166,15 @@ defmodule Signs.Utilities.EarlyAmSuppression do
{%Headways.Top{destination: destination, vehicle_type: :train},
%Headways.Bottom{range: range}}

# If we get one half of a headway message, it means the mz sign was showing headways in the original content generation
# but that one or the other mz lines has an early am status of :none.
# We can piece the original headway message back together in this case and let the proceeding logic handle what to do with it
{%Headways.Top{} = unprocessed_message, %Message.Empty{}} ->
{unprocessed_message, bottom_message}

{%Headways.Bottom{} = unprocessed_message, %Message.Empty{}} ->
{top_message, unprocessed_message}

content ->
content
end
Expand All @@ -189,7 +198,7 @@ defmodule Signs.Utilities.EarlyAmSuppression do
}}

status == :partially_suppressed ->
case filter_early_am_messages(messages, sign.id) do
case filter_early_am_messages(messages) do
[] ->
# If no valid predictions, try fetching headways
case Signs.Utilities.Headways.get_messages(sign, current_time) do
Expand Down Expand Up @@ -226,7 +235,7 @@ defmodule Signs.Utilities.EarlyAmSuppression do
end
end

defp filter_early_am_messages(messages, sign_id) do
defp filter_early_am_messages(messages) do
Enum.reject(Tuple.to_list(messages), fn message ->
case message do
%Headways.Top{} ->
Expand All @@ -246,8 +255,9 @@ defmodule Signs.Utilities.EarlyAmSuppression do
_ -> false
end

# Reject reverse predictions/stopped trains unless the message is for Prudential or Symphony EB
is_prediction_or_stopped? and message.certainty == @reverse_prediction_certainty and
sign_id not in ["symphony_eastbound", "prudential_eastbound"]
message.stop_id not in ["70240", "70242"]
end
end)
end
Expand Down
6 changes: 3 additions & 3 deletions priv/signs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6365,7 +6365,7 @@
],
"type": "realtime",
"source_config": {
"headway_group": "green_trunk",
"headway_group": "green_b",
"headway_direction_name": "Eastbound",
"sources": [
{
Expand Down Expand Up @@ -6394,8 +6394,8 @@
],
"type": "realtime",
"source_config": {
"headway_group": "green_trunk",
"headway_direction_name": "Westbound",
"headway_group": "green_b",
"headway_direction_name": "Boston College",
"sources": [
{
"stop_id": "71151",
Expand Down

0 comments on commit 20d3add

Please sign in to comment.