Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude mezzanine zones from crowding announcements #697

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/content/message/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ defmodule Content.Message.Predictions do
Predictions.Prediction.t(),
String.t(),
String.t(),
Signs.Realtime.t(),
Content.platform() | nil,
integer()
) :: t() | nil
def non_terminal(prediction, station_code, zone, platform \\ nil, width \\ 18)
def non_terminal(prediction, station_code, zone, sign, platform \\ nil, width \\ 18)

def non_terminal(prediction, station_code, zone, platform, width) do
def non_terminal(prediction, station_code, zone, sign, platform, width) do
# e.g., North Station which is non-terminal but has trips that begin there
predicted_time = prediction.seconds_until_arrival || prediction.seconds_until_departure

Expand All @@ -82,7 +83,10 @@ defmodule Content.Message.Predictions do
true -> compute_minutes(predicted_time, certainty)
end

{crowding_data_confidence, crowding_description} = do_crowding(prediction)
{crowding_data_confidence, crowding_description} =
if Signs.Utilities.SourceConfig.multi_source?(sign.source_config),
do: {nil, nil},
else: do_crowding(prediction)

case Content.Utilities.destination_for_prediction(
prediction.route_id,
Expand Down
1 change: 1 addition & 0 deletions lib/signs/utilities/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ defmodule Signs.Utilities.Predictions do
prediction,
station_code,
zone,
sign,
platform(prediction, sources)
)
end
Expand Down
40 changes: 21 additions & 19 deletions test/content/messages/predictions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule Content.Message.PredictionsTest do
import ExUnit.CaptureLog

describe "non_terminal/3" do
@sign %{source_config: nil}

test "logs a warning when we cant find a headsign" do
prediction = %Predictions.Prediction{
seconds_until_arrival: 0,
Expand All @@ -15,7 +17,7 @@ defmodule Content.Message.PredictionsTest do

log =
capture_log([level: :warn], fn ->
assert is_nil(Content.Message.Predictions.non_terminal(prediction, "test", "m"))
assert is_nil(Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign))
end)

assert log =~ "no_destination_for_prediction"
Expand All @@ -31,7 +33,7 @@ defmodule Content.Message.PredictionsTest do
destination_stop_id: "70261"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert Content.Message.to_string(msg) == "Ashmont ARR"
end
Expand All @@ -46,7 +48,7 @@ defmodule Content.Message.PredictionsTest do
boarding_status: "Boarding"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert Content.Message.to_string(msg) == "Ashmont BRD"
end
Expand All @@ -61,7 +63,7 @@ defmodule Content.Message.PredictionsTest do
destination_stop_id: "70275"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert Content.Message.to_string(msg) == "Mattapan ARR"
end
Expand All @@ -76,7 +78,7 @@ defmodule Content.Message.PredictionsTest do
destination_stop_id: "70275"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert Content.Message.to_string(msg) == "Mattapan 1 min"
end
Expand All @@ -91,7 +93,7 @@ defmodule Content.Message.PredictionsTest do
destination_stop_id: "70275"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert Content.Message.to_string(msg) == "Mattapan 1 min"
end
Expand All @@ -107,7 +109,7 @@ defmodule Content.Message.PredictionsTest do
destination_stop_id: "70275"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert Content.Message.to_string(msg) == "Mattapan 20+ min"
end
Expand All @@ -122,7 +124,7 @@ defmodule Content.Message.PredictionsTest do
destination_stop_id: "70275"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", nil, 15)
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign, nil, 15)
assert Content.Message.to_string(msg) == "Mattapan 9 min"
end

Expand All @@ -136,7 +138,7 @@ defmodule Content.Message.PredictionsTest do
destination_stop_id: "70261"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert Content.Message.to_string(msg) == "Ashmont 1 min"
end
Expand All @@ -151,7 +153,7 @@ defmodule Content.Message.PredictionsTest do
destination_stop_id: "70261"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert Content.Message.to_string(msg) == "Ashmont 2 min"
end
Expand All @@ -166,7 +168,7 @@ defmodule Content.Message.PredictionsTest do
destination_stop_id: "70261"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert Content.Message.to_string(msg) == "Ashmont ARR"
end
Expand All @@ -181,7 +183,7 @@ defmodule Content.Message.PredictionsTest do
boarding_status: "Boarding"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert Content.Message.to_string(msg) == "Ashmont BRD"
end
Expand All @@ -196,7 +198,7 @@ defmodule Content.Message.PredictionsTest do
destination_stop_id: "70261"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert Content.Message.to_string(msg) == "Ashmont 2 min"
end
Expand All @@ -212,7 +214,7 @@ defmodule Content.Message.PredictionsTest do
trip_id: "trip1"
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert msg.trip_id == "trip1"
end
Expand All @@ -228,7 +230,7 @@ defmodule Content.Message.PredictionsTest do
new_cars?: true
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert msg.new_cars?
end
Expand All @@ -243,7 +245,7 @@ defmodule Content.Message.PredictionsTest do
stops_away: 2
}

msg = Content.Message.Predictions.non_terminal(prediction, "RJFK", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "RJFK", "m", @sign)

assert Content.Message.to_string(msg) == [
{"Alewife (A) 5 min", 6},
Expand All @@ -261,7 +263,7 @@ defmodule Content.Message.PredictionsTest do
stops_away: 2
}

msg = Content.Message.Predictions.non_terminal(prediction, "RJFK", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "RJFK", "m", @sign)

assert Content.Message.to_string(msg) == [
{"Alewife (B) 5 min", 6},
Expand All @@ -279,7 +281,7 @@ defmodule Content.Message.PredictionsTest do
stops_away: 2
}

msg = Content.Message.Predictions.non_terminal(prediction, "RJFK", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "RJFK", "m", @sign)

assert Content.Message.to_string(msg) == [
{"Alewife 6 min", 6},
Expand Down Expand Up @@ -434,7 +436,7 @@ defmodule Content.Message.PredictionsTest do
new_cars?: true
}

msg = Content.Message.Predictions.non_terminal(prediction, "test", "m")
msg = Content.Message.Predictions.non_terminal(prediction, "test", "m", @sign)

assert msg.new_cars?
end
Expand Down
Loading