From 428c9daa7e732efbe4ccf8ae173b2d596a3088f7 Mon Sep 17 00:00:00 2001 From: "robbie.sundstrom" Date: Thu, 19 Dec 2024 13:42:12 -0500 Subject: [PATCH 1/5] Update time to BRD to 60, fix and add tests --- lib/content/message/predictions.ex | 2 +- test/content/messages/predictions_test.exs | 33 +++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index 9a2e2284..a632ed2c 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -39,7 +39,7 @@ defmodule Content.Message.Predictions do {minutes, approximate?} = cond do - prediction.stopped_at_predicted_stop? and (!terminal? or sec <= 30) -> {:boarding, false} + prediction.stopped_at_predicted_stop? and (!terminal? or sec <= 60) -> {:boarding, false} !terminal? and sec <= 30 -> {:arriving, false} !terminal? and sec <= 60 -> {:approaching, false} min > 60 -> {60, true} diff --git a/test/content/messages/predictions_test.exs b/test/content/messages/predictions_test.exs index a2d22ac4..7f331d97 100644 --- a/test/content/messages/predictions_test.exs +++ b/test/content/messages/predictions_test.exs @@ -215,9 +215,25 @@ defmodule Content.Message.PredictionsTest do assert Content.Message.to_string(msg) == "Ashmont BRD" end + + test "put boarding on the sign when train is stopped at terminal and departing in less than 60 seconds" do + prediction = %Predictions.Prediction{ + seconds_until_departure: 59, + direction_id: 1, + route_id: "Mattapan", + destination_stop_id: "70261", + stopped_at_predicted_stop?: true, + boarding_status: "Stopped at station" + } + + msg = Content.Message.Predictions.new(prediction, true, nil) + + assert Content.Message.to_string(msg) == "Ashmont BRD" + end + test "does not put boarding on the sign too early when train is stopped at terminal" do prediction = %Predictions.Prediction{ - seconds_until_departure: 35, + seconds_until_departure: 61, direction_id: 1, route_id: "Mattapan", destination_stop_id: "70261", @@ -230,6 +246,21 @@ defmodule Content.Message.PredictionsTest do assert Content.Message.to_string(msg) == "Ashmont 1 min" end + test "puts minutes on sign when train is stopped at terminal but departure is >=1.5 minutes" do + prediction = %Predictions.Prediction{ + seconds_until_departure: 92, + direction_id: 1, + route_id: "Mattapan", + destination_stop_id: "70261", + stopped_at_predicted_stop?: true, + boarding_status: "Stopped at station" + } + + msg = Content.Message.Predictions.new(prediction, true, nil) + + assert Content.Message.to_string(msg) == "Ashmont 2 min" + end + test "puts 1 min on the sign when train is not boarding, but is predicted to depart in less than a minute when offset" do prediction = %Predictions.Prediction{ seconds_until_departure: 70, From a5326ac739b334247f536d1dd52c4202a71416f6 Mon Sep 17 00:00:00 2001 From: "robbie.sundstrom" Date: Thu, 19 Dec 2024 13:59:27 -0500 Subject: [PATCH 2/5] Rename test for clarity --- test/content/messages/predictions_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/content/messages/predictions_test.exs b/test/content/messages/predictions_test.exs index 7f331d97..633c17e1 100644 --- a/test/content/messages/predictions_test.exs +++ b/test/content/messages/predictions_test.exs @@ -231,7 +231,7 @@ defmodule Content.Message.PredictionsTest do assert Content.Message.to_string(msg) == "Ashmont BRD" end - test "does not put boarding on the sign too early when train is stopped at terminal" do + test "puts 1 min on sign when train is stopped at terminal but departure is between 60-90 seconds" do prediction = %Predictions.Prediction{ seconds_until_departure: 61, direction_id: 1, From 9ee7762d159b7ea41ffaa7023c03feb370aa6952 Mon Sep 17 00:00:00 2001 From: "robbie.sundstrom" Date: Fri, 20 Dec 2024 14:13:46 -0500 Subject: [PATCH 3/5] mix format --- test/content/messages/predictions_test.exs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/content/messages/predictions_test.exs b/test/content/messages/predictions_test.exs index 633c17e1..f4daee5a 100644 --- a/test/content/messages/predictions_test.exs +++ b/test/content/messages/predictions_test.exs @@ -215,7 +215,6 @@ defmodule Content.Message.PredictionsTest do assert Content.Message.to_string(msg) == "Ashmont BRD" end - test "put boarding on the sign when train is stopped at terminal and departing in less than 60 seconds" do prediction = %Predictions.Prediction{ seconds_until_departure: 59, From 1ad59c0e298c322738e803bb412f525bff81946a Mon Sep 17 00:00:00 2001 From: "robbie.sundstrom" Date: Fri, 20 Dec 2024 18:06:19 -0500 Subject: [PATCH 4/5] Add test cases to realtime_test --- test/signs/realtime_test.exs | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/signs/realtime_test.exs b/test/signs/realtime_test.exs index 508ee768..a1dde98c 100644 --- a/test/signs/realtime_test.exs +++ b/test/signs/realtime_test.exs @@ -513,6 +513,48 @@ defmodule Signs.RealtimeTest do Signs.Realtime.handle_info(:run_loop, @terminal_sign) end + test "When the train is stopped at the terminal and departing in <= 60 seconds, shows BRD" do + expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> + [ + prediction( + destination: :mattapan, + stopped: 0, + seconds_until_arrival: -1, + seconds_until_departure: 60, + trip_id: "3" + ) + ] + end) + + expect_messages({"Mattapan BRD", ""}) + + expect_audios( + [ + {:canned, {"109", ["501", "21000", "507", "21000", "4100", "21000", "544"], :audio}} + ], + [{"The next Mattapan train is now boarding.", nil}] + ) + + Signs.Realtime.handle_info(:run_loop, @terminal_sign) + end + + test "When the train is stopped at the terminal and departing in more than 60 seconds, shows mins to departure" do + expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> + [ + prediction( + destination: :mattapan, + stopped: 0, + seconds_until_arrival: nil, + seconds_until_departure: 91, + trip_id: "3" + ) + ] + end) + + expect_messages({"Mattapan 2 min", ""}) + Signs.Realtime.handle_info(:run_loop, @terminal_sign) + end + test "When the train is stopped a long time away, shows max time instead of stopped" do expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [prediction(destination: :mattapan, arrival: 3700, stopped: 8)] From 4dca8e57afd335ba73c842b342736391dc70fdce Mon Sep 17 00:00:00 2001 From: "robbie.sundstrom" Date: Mon, 23 Dec 2024 10:13:00 -0500 Subject: [PATCH 5/5] Fix test with merge from main --- test/signs/realtime_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/signs/realtime_test.exs b/test/signs/realtime_test.exs index 5ca9670e..294edbd3 100644 --- a/test/signs/realtime_test.exs +++ b/test/signs/realtime_test.exs @@ -514,7 +514,7 @@ defmodule Signs.RealtimeTest do expect_audios( [ - {:canned, {"109", ["501", "21000", "507", "21000", "4100", "21000", "544"], :audio}} + {:canned, {"109", ["501", "21000", "4100", "21000", "864", "21000", "544"], :audio}} ], [{"The next Mattapan train is now boarding.", nil}] )