From d9c11dcbd01e0cd358464658cdb797d043ab4a55 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 25 Mar 2024 14:20:50 -0400 Subject: [PATCH 01/26] Migrate to GTFS-rt predictions and locations feeds --- lib/content/message/predictions.ex | 17 +- lib/fake/httpoison.ex | 21 +-- lib/predictions/prediction.ex | 4 +- lib/predictions/predictions.ex | 32 ++-- lib/signs/utilities/predictions.ex | 7 +- test/content/messages/predictions_test.exs | 44 ++--- test/engine/predictions_test.exs | 2 + test/predictions/predictions_test.exs | 196 ++++----------------- test/signs/realtime_test.exs | 98 ++++++++--- 9 files changed, 164 insertions(+), 257 deletions(-) diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index a34e1e349..7784f1ace 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -77,10 +77,17 @@ defmodule Content.Message.Predictions do {minutes, approximate?} = cond do - prediction.stops_away == 0 -> {:boarding, false} - predicted_time <= 30 -> {:arriving, false} - predicted_time <= 60 -> {:approaching, false} - true -> compute_minutes(predicted_time, certainty) + prediction.stopped? and prediction.vehicle_at_predicted_stop? -> + {:boarding, false} + + predicted_time <= 30 -> + {:arriving, false} + + predicted_time <= 60 -> + {:approaching, false} + + true -> + compute_minutes(predicted_time, certainty) end {crowding_data_confidence, crowding_description} = @@ -128,7 +135,7 @@ defmodule Content.Message.Predictions do def terminal(prediction, station_code, zone, sign, width \\ 18) def terminal(prediction, station_code, zone, sign, width) do - stopped_at? = prediction.stops_away == 0 + stopped_at? = prediction.vehicle_at_predicted_stop? and prediction.stopped? {minutes, approximate?} = case prediction.seconds_until_departure + @terminal_prediction_offset_seconds do diff --git a/lib/fake/httpoison.ex b/lib/fake/httpoison.ex index 2d9a0a9bf..24329373e 100644 --- a/lib/fake/httpoison.ex +++ b/lib/fake/httpoison.ex @@ -65,15 +65,11 @@ defmodule Fake.HTTPoison do %{ "entity" => [ %{ - "alert" => nil, "id" => "1490783458_32568935", - "is_deleted" => false, "trip_update" => %{ - "delay" => nil, "stop_time_update" => [ %{ "arrival" => %{ - "delay" => nil, "time" => 1_491_570_120, "uncertainty" => nil }, @@ -84,7 +80,6 @@ defmodule Fake.HTTPoison do }, %{ "arrival" => %{ - "delay" => nil, "time" => 1_491_570_180, "uncertainty" => nil }, @@ -133,23 +128,17 @@ defmodule Fake.HTTPoison do %{ "entity" => [ %{ - "alert" => nil, "id" => "1490783458_32568935", - "is_deleted" => false, "trip_update" => %{ - "delay" => nil, "stop_time_update" => [ %{ "arrival" => %{ - "delay" => nil, "time" => 1_491_570_180, - "uncertainty" => nil + "uncertainty" => 60 }, "departure" => nil, - "schedule_relationship" => "SCHEDULED", "stop_id" => "stop_to_update", - "stop_sequence" => 1, - "stops_away" => 0 + "stop_sequence" => 1 } ], "timestamp" => nil, @@ -159,15 +148,15 @@ defmodule Fake.HTTPoison do "schedule_relationship" => "SCHEDULED", "start_date" => "20170329", "start_time" => nil, - "trip_id" => "32568935" + "trip_id" => "32568935", + "revenue" => true }, "vehicle" => %{ "id" => "G-10040", "label" => "3260", "license_plate" => nil } - }, - "vehicle" => nil + } } ], "header" => %{ diff --git a/lib/predictions/prediction.ex b/lib/predictions/prediction.ex index 70b5b693a..92a533de7 100644 --- a/lib/predictions/prediction.ex +++ b/lib/predictions/prediction.ex @@ -11,7 +11,7 @@ defmodule Predictions.Prediction do trip_id: nil, destination_stop_id: nil, stopped?: false, - stops_away: 0, + vehicle_at_predicted_stop?: false, boarding_status: nil, revenue_trip?: true, vehicle_id: nil @@ -31,7 +31,7 @@ defmodule Predictions.Prediction do trip_id: trip_id() | nil, destination_stop_id: String.t(), stopped?: boolean(), - stops_away: integer(), + vehicle_at_predicted_stop?: boolean(), boarding_status: String.t() | nil, revenue_trip?: boolean(), vehicle_id: String.t() | nil diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index db856514a..646a13907 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -10,11 +10,23 @@ defmodule Predictions.Predictions do predictions = feed_message["entity"] |> Enum.map(& &1["trip_update"]) + |> Enum.filter( + &(&1["trip"]["route_id"] in [ + "Red", + "Blue", + "Orange", + "Green-B", + "Green-C", + "Green-D", + "Green-E", + "Mattapan" + ]) + ) |> Enum.reject(&(&1["trip"]["schedule_relationship"] == "CANCELED")) |> Enum.flat_map(&transform_stop_time_updates/1) |> Enum.filter(fn {update, _, _, _, _, _, _} -> - ((update["arrival"] || update["departure"]) && - not is_nil(update["stops_away"])) || update["passthrough_time"] + (update["arrival"] && update["arrival"]["uncertainty"]) || + (update["departure"] && update["departure"]["uncertainty"]) end) |> Enum.map(&prediction_from_update(&1, current_time)) |> Enum.reject( @@ -43,15 +55,12 @@ defmodule Predictions.Predictions do end) |> Map.get("stop_id") - revenue_trip? = - Enum.any?(trip_update["stop_time_update"], &(&1["schedule_relationship"] != "SKIPPED")) - vehicle_id = get_in(trip_update, ["vehicle", "id"]) Enum.map( trip_update["stop_time_update"], &{&1, last_stop_id, trip_update["trip"]["route_id"], trip_update["trip"]["direction_id"], - trip_update["trip"]["trip_id"], revenue_trip?, vehicle_id} + trip_update["trip"]["trip_id"], trip_update["trip"]["revenue"], vehicle_id} ) end @@ -80,10 +89,12 @@ defmodule Predictions.Predictions do else: nil seconds_until_passthrough = - if stop_time_update["passthrough_time"], - do: stop_time_update["passthrough_time"] - current_time_seconds, + if not revenue_trip?, + do: seconds_until_arrival || seconds_until_departure, else: nil + vehicle_location = Engine.Locations.for_vehicle(vehicle_id) + %Prediction{ stop_id: stop_time_update["stop_id"], direction_id: direction_id, @@ -97,8 +108,9 @@ defmodule Predictions.Predictions do route_id: route_id, trip_id: trip_id, destination_stop_id: last_stop_id, - stopped?: stop_time_update["stopped?"], - stops_away: stop_time_update["stops_away"], + stopped?: not is_nil(vehicle_location) and vehicle_location.status == :stopped_at, + vehicle_at_predicted_stop?: + not is_nil(vehicle_location) and stop_time_update["stop_id"] == vehicle_location.stop_id, boarding_status: stop_time_update["boarding_status"], revenue_trip?: revenue_trip?, vehicle_id: vehicle_id diff --git a/lib/signs/utilities/predictions.ex b/lib/signs/utilities/predictions.ex index f8a04ca61..398d51593 100644 --- a/lib/signs/utilities/predictions.ex +++ b/lib/signs/utilities/predictions.ex @@ -47,10 +47,9 @@ defmodule Signs.Utilities.Predictions do {if terminal_prediction?(prediction, sources) do 0 else - case prediction.stops_away do - 0 -> 0 - _ -> 1 - end + if prediction.stopped? and prediction.vehicle_at_predicted_stop?, + do: 0, + else: 1 end, prediction.seconds_until_departure, prediction.seconds_until_arrival} end) |> filter_large_red_line_gaps() diff --git a/test/content/messages/predictions_test.exs b/test/content/messages/predictions_test.exs index 8876a707c..353dc4137 100644 --- a/test/content/messages/predictions_test.exs +++ b/test/content/messages/predictions_test.exs @@ -18,7 +18,6 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "NON-ROUTE", stopped?: false, - stops_away: 1, destination_stop_id: "70261" } @@ -36,7 +35,6 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "Mattapan", stopped?: false, - stops_away: 1, destination_stop_id: "70261" } @@ -50,8 +48,8 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "Mattapan", destination_stop_id: "70261", - stopped?: false, - stops_away: 0, + stopped?: true, + vehicle_at_predicted_stop?: true, boarding_status: "Boarding" } @@ -66,7 +64,6 @@ defmodule Content.Message.PredictionsTest do direction_id: 0, route_id: "Mattapan", stopped?: false, - stops_away: 1, destination_stop_id: "70275" } @@ -81,7 +78,6 @@ defmodule Content.Message.PredictionsTest do direction_id: 0, route_id: "Mattapan", stopped?: false, - stops_away: 1, destination_stop_id: "70275" } @@ -96,7 +92,6 @@ defmodule Content.Message.PredictionsTest do direction_id: 0, route_id: "Mattapan", stopped?: false, - stops_away: 1, destination_stop_id: "70275" } @@ -112,7 +107,6 @@ defmodule Content.Message.PredictionsTest do direction_id: 0, route_id: "Mattapan", stopped?: false, - stops_away: 10, destination_stop_id: "70275" } @@ -127,7 +121,6 @@ defmodule Content.Message.PredictionsTest do route_id: "Mattapan", direction_id: 0, stopped?: false, - stops_away: 3, destination_stop_id: "70275" } @@ -141,7 +134,6 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "Mattapan", stopped?: false, - stops_away: 1, destination_stop_id: "70261" } @@ -156,7 +148,6 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "Mattapan", stopped?: false, - stops_away: 2, destination_stop_id: "70261" } @@ -171,7 +162,6 @@ defmodule Content.Message.PredictionsTest do route_id: "Mattapan", direction_id: 1, stopped?: false, - stops_away: 1, destination_stop_id: "70261" } @@ -185,8 +175,8 @@ defmodule Content.Message.PredictionsTest do route_id: "Mattapan", direction_id: 1, destination_stop_id: "70261", - stopped?: false, - stops_away: 0, + stopped?: true, + vehicle_at_predicted_stop?: true, boarding_status: "Boarding" } @@ -201,7 +191,6 @@ defmodule Content.Message.PredictionsTest do route_id: "Mattapan", direction_id: 1, stopped?: false, - stops_away: 2, destination_stop_id: "70261" } @@ -216,7 +205,6 @@ defmodule Content.Message.PredictionsTest do route_id: "Mattapan", direction_id: 1, stopped?: false, - stops_away: 2, destination_stop_id: "70261", trip_id: "trip1" } @@ -232,8 +220,7 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 300, direction_id: 1, route_id: "Red", - stopped?: false, - stops_away: 2 + stopped?: false } msg = Content.Message.Predictions.non_terminal(prediction, "RJFK", "m", @sign) @@ -250,8 +237,7 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 300, direction_id: 1, route_id: "Red", - stopped?: false, - stops_away: 2 + stopped?: false } msg = Content.Message.Predictions.non_terminal(prediction, "RJFK", "m", @sign) @@ -268,8 +254,7 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 360, direction_id: 1, route_id: "Red", - stopped?: false, - stops_away: 2 + stopped?: false } msg = Content.Message.Predictions.non_terminal(prediction, "RJFK", "m", @sign) @@ -295,7 +280,7 @@ defmodule Content.Message.PredictionsTest do route_id: "NON-ROUTE", destination_stop_id: "70261", stopped?: false, - stops_away: 0, + vehicle_at_predicted_stop?: true, boarding_status: "Boarding" } @@ -313,7 +298,6 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "NON-ROUTE", stopped?: false, - stops_away: 1, destination_stop_id: "70261" } @@ -331,8 +315,8 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "Mattapan", destination_stop_id: "70261", - stopped?: false, - stops_away: 0, + stopped?: true, + vehicle_at_predicted_stop?: true, boarding_status: "Stopped at station" } @@ -348,7 +332,7 @@ defmodule Content.Message.PredictionsTest do route_id: "Mattapan", destination_stop_id: "70261", stopped?: false, - stops_away: 0, + vehicle_at_predicted_stop?: true, boarding_status: "Stopped at station" } @@ -364,7 +348,7 @@ defmodule Content.Message.PredictionsTest do route_id: "Mattapan", destination_stop_id: "70261", stopped?: false, - stops_away: 0, + vehicle_at_predicted_stop?: true, boarding_status: "Stopped at station" } @@ -379,7 +363,6 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "Mattapan", stopped?: false, - stops_away: 1, destination_stop_id: "70261" } @@ -395,7 +378,7 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "Orange", stopped?: false, - stops_away: 0 + vehicle_at_predicted_stop?: true } msg = Content.Message.Predictions.terminal(prediction, "test", "m", @sign) @@ -412,7 +395,6 @@ defmodule Content.Message.PredictionsTest do route_id: "Mattapan", direction_id: 1, stopped?: false, - stops_away: 2, destination_stop_id: "70261", trip_id: "trip1" } diff --git a/test/engine/predictions_test.exs b/test/engine/predictions_test.exs index b3e268ef2..63381685c 100644 --- a/test/engine/predictions_test.exs +++ b/test/engine/predictions_test.exs @@ -65,6 +65,8 @@ defmodule Engine.PredictionsTest do assert :ets.info(predictions_table)[:size] == 2 [{{"stop_to_remove", 0}, []}] = :ets.lookup(predictions_table, {"stop_to_remove", 0}) + :ets.lookup(predictions_table, {"stop_to_update", 0}) + [{{"stop_to_update", 0}, [%Predictions.Prediction{}]}] = :ets.lookup(predictions_table, {"stop_to_update", 0}) end diff --git a/test/predictions/predictions_test.exs b/test/predictions/predictions_test.exs index 71d94aac8..f73adc38d 100644 --- a/test/predictions/predictions_test.exs +++ b/test/predictions/predictions_test.exs @@ -7,47 +7,32 @@ defmodule Predictions.PredictionsTest do @feed_message %{ "entity" => [ %{ - "alert" => nil, "id" => "1490783458_32568935", - "is_deleted" => false, "trip_update" => %{ - "delay" => nil, "stop_time_update" => [ %{ "arrival" => nil, "departure" => nil, - "schedule_relationship" => "SKIPPED", "stop_id" => "70265", - "stop_sequence" => 1, - "stops_away" => nil, - "stopped?" => false, - "passthrough_time" => 1_491_570_110 + "stop_sequence" => 1 }, %{ "arrival" => nil, "departure" => %{ - "delay" => nil, "time" => 1_491_570_120, - "uncertainty" => nil + "uncertainty" => 60 }, - "schedule_relationship" => "SCHEDULED", "stop_id" => "70263", "stop_sequence" => 1, - "stops_away" => 1, - "stopped?" => true, "boarding_status" => "Stopped 1 stop away" }, %{ "arrival" => %{ - "delay" => nil, "time" => 1_491_570_180, - "uncertainty" => nil + "uncertainty" => 60 }, "departure" => nil, - "schedule_relationship" => "SCHEDULED", "stop_id" => "70261", - "stops_away" => 1, - "stopped?" => false, "stop_sequence" => 1 } ], @@ -58,7 +43,8 @@ defmodule Predictions.PredictionsTest do "schedule_relationship" => "SCHEDULED", "start_date" => "20170329", "start_time" => nil, - "trip_id" => "32568935" + "trip_id" => "32568935", + "revenue" => true }, "vehicle" => %{ "id" => "G-10040", @@ -83,11 +69,10 @@ defmodule Predictions.PredictionsTest do %Predictions.Prediction{ stop_id: "70261", seconds_until_arrival: 180, + arrival_certainty: 60, direction_id: 0, schedule_relationship: :scheduled, route_id: "Mattapan", - stops_away: 1, - stopped?: false, destination_stop_id: "70261", trip_id: "32568935", revenue_trip?: true, @@ -98,32 +83,16 @@ defmodule Predictions.PredictionsTest do %Predictions.Prediction{ stop_id: "70263", seconds_until_departure: 120, + departure_certainty: 60, direction_id: 0, schedule_relationship: :scheduled, route_id: "Mattapan", destination_stop_id: "70261", - stops_away: 1, - stopped?: true, boarding_status: "Stopped 1 stop away", trip_id: "32568935", revenue_trip?: true, vehicle_id: "G-10040" } - ], - {"70265", 0} => [ - %Predictions.Prediction{ - stop_id: "70265", - seconds_until_passthrough: 110, - direction_id: 0, - schedule_relationship: :skipped, - route_id: "Mattapan", - destination_stop_id: "70261", - stops_away: nil, - stopped?: false, - trip_id: "32568935", - revenue_trip?: true, - vehicle_id: "G-10040" - } ] } @@ -144,10 +113,9 @@ defmodule Predictions.PredictionsTest do "arrival" => %{ "delay" => nil, "time" => 1_491_570_120, - "uncertainty" => nil + "uncertainty" => 60 }, "departure" => nil, - "schedule_relationship" => "SCHEDULED", "stop_id" => "70263", "stopped?" => false, "stops_away" => 1, @@ -157,10 +125,9 @@ defmodule Predictions.PredictionsTest do "arrival" => %{ "delay" => nil, "time" => 1_491_570_180, - "uncertainty" => nil + "uncertainty" => 60 }, "departure" => nil, - "schedule_relationship" => "SCHEDULED", "stop_id" => "70261", "stopped?" => false, "stops_away" => 1, @@ -169,7 +136,6 @@ defmodule Predictions.PredictionsTest do %{ "arrival" => nil, "departure" => nil, - "schedule_relationship" => "SCHEDULED", "stop_id" => "70261", "stopped?" => false, "stops_away" => 1, @@ -183,7 +149,8 @@ defmodule Predictions.PredictionsTest do "schedule_relationship" => "SCHEDULED", "start_date" => "20170329", "start_time" => nil, - "trip_id" => "32568935" + "trip_id" => "32568935", + "revenue" => true }, "vehicle" => %{ "id" => "G-10040", @@ -204,10 +171,9 @@ defmodule Predictions.PredictionsTest do "arrival" => %{ "delay" => nil, "time" => 1_491_570_200, - "uncertainty" => nil + "uncertainty" => 60 }, "departure" => nil, - "schedule_relationship" => "SCHEDULED", "stop_id" => "70038", "stopped?" => false, "stops_away" => 1, @@ -217,10 +183,9 @@ defmodule Predictions.PredictionsTest do "arrival" => %{ "delay" => nil, "time" => 1_491_570_400, - "uncertainty" => nil + "uncertainty" => 60 }, "departure" => nil, - "schedule_relationship" => "SCHEDULED", "stop_id" => "70060", "stopped?" => false, "stops_away" => 1, @@ -234,7 +199,8 @@ defmodule Predictions.PredictionsTest do "schedule_relationship" => "SCHEDULED", "start_date" => "20170329", "start_time" => nil, - "trip_id" => "trip_2" + "trip_id" => "trip_2", + "revenue" => true }, "vehicle" => %{ "id" => "vehicle_2", @@ -258,7 +224,8 @@ defmodule Predictions.PredictionsTest do "schedule_relationship" => "CANCELED", "start_date" => "20190821", "start_time" => nil, - "trip_id" => "40826503" + "trip_id" => "40826503", + "revenue" => true }, "vehicle" => %{ "id" => nil, @@ -281,11 +248,11 @@ defmodule Predictions.PredictionsTest do %Predictions.Prediction{ stop_id: "70261", seconds_until_arrival: 180, + arrival_certainty: 60, schedule_relationship: :scheduled, direction_id: 0, route_id: "Mattapan", stopped?: false, - stops_away: 1, destination_stop_id: "70261", trip_id: "32568935", revenue_trip?: true, @@ -296,11 +263,11 @@ defmodule Predictions.PredictionsTest do %Predictions.Prediction{ stop_id: "70263", seconds_until_arrival: 120, + arrival_certainty: 60, direction_id: 0, schedule_relationship: :scheduled, route_id: "Mattapan", stopped?: false, - stops_away: 1, destination_stop_id: "70261", trip_id: "32568935", revenue_trip?: true, @@ -311,11 +278,11 @@ defmodule Predictions.PredictionsTest do %Predictions.Prediction{ stop_id: "70038", seconds_until_arrival: 200, + arrival_certainty: 60, direction_id: 1, schedule_relationship: :scheduled, route_id: "Blue", stopped?: false, - stops_away: 1, destination_stop_id: "70060", trip_id: "trip_2", revenue_trip?: true, @@ -326,11 +293,11 @@ defmodule Predictions.PredictionsTest do %Predictions.Prediction{ stop_id: "70060", seconds_until_arrival: 400, + arrival_certainty: 60, direction_id: 1, schedule_relationship: :scheduled, route_id: "Blue", stopped?: false, - stops_away: 1, destination_stop_id: "70060", trip_id: "trip_2", revenue_trip?: true, @@ -356,7 +323,7 @@ defmodule Predictions.PredictionsTest do "arrival" => %{ "delay" => nil, "time" => Timex.to_unix(@current_time) - 100, - "uncertainty" => nil + "uncertainty" => 60 }, "departure" => nil, "schedule_relationship" => "SCHEDULED", @@ -373,7 +340,8 @@ defmodule Predictions.PredictionsTest do "schedule_relationship" => "SCHEDULED", "start_date" => "20170329", "start_time" => nil, - "trip_id" => "32568935" + "trip_id" => "32568935", + "revenue" => true }, "vehicle" => %{ "id" => "G-10040", @@ -400,7 +368,6 @@ defmodule Predictions.PredictionsTest do schedule_relationship: :scheduled, route_id: "Mattapan", stopped?: false, - stops_away: 1, destination_stop_id: "70263", trip_id: "32568935", revenue_trip?: true, @@ -410,109 +377,6 @@ defmodule Predictions.PredictionsTest do }, _} = get_all(feed_message, @current_time) end - test "filters stop_time_updates where stops_away == nil" do - feed_message = %{ - "entity" => [ - %{ - "alert" => nil, - "id" => "1490783458_32568935", - "is_deleted" => false, - "trip_update" => %{ - "delay" => nil, - "stop_time_update" => [ - %{ - "arrival" => %{ - "delay" => nil, - "time" => Timex.to_unix(@current_time) - 100, - "uncertainty" => nil - }, - "departure" => %{ - "delay" => nil, - "time" => Timex.to_unix(@current_time) - 100, - "uncertainty" => nil - }, - "schedule_relationship" => "SCHEDULED", - "stop_id" => "70262", - "stopped?" => false, - "stops_away" => nil, - "stop_sequence" => 1 - }, - %{ - "arrival" => nil, - "departure" => %{ - "delay" => nil, - "time" => Timex.to_unix(@current_time) - 100, - "uncertainty" => nil - }, - "schedule_relationship" => "SCHEDULED", - "stop_id" => "70263", - "stopped?" => false, - "stops_away" => nil, - "stop_sequence" => 1 - }, - %{ - "arrival" => nil, - "departure" => %{ - "delay" => nil, - "time" => Timex.to_unix(@current_time) + 100, - "uncertainty" => nil - }, - "schedule_relationship" => "SCHEDULED", - "stop_id" => "70264", - "stopped?" => false, - "stops_away" => 1, - "stop_sequence" => 2 - } - ], - "timestamp" => nil, - "trip" => %{ - "direction_id" => 0, - "route_id" => "Mattapan", - "schedule_relationship" => "SCHEDULED", - "start_date" => "20170329", - "start_time" => nil, - "trip_id" => "32568935" - }, - "vehicle" => %{ - "id" => "G-10040", - "label" => "3260", - "license_plate" => nil - } - }, - "vehicle" => nil - } - ], - "header" => %{ - "gtfs_realtime_version" => "1.0", - "incrementality" => "FULL_DATASET", - "timestamp" => 1_490_783_458 - } - } - - {predictions_map, _} = get_all(feed_message, @current_time) - - assert predictions_map == %{ - {"70264", 0} => [ - %Predictions.Prediction{ - boarding_status: nil, - destination_stop_id: "70262", - direction_id: 0, - revenue_trip?: true, - route_id: "Mattapan", - schedule_relationship: :scheduled, - seconds_until_arrival: nil, - seconds_until_departure: 100, - seconds_until_passthrough: nil, - stop_id: "70264", - stopped?: false, - stops_away: 1, - trip_id: "32568935", - vehicle_id: "G-10040" - } - ] - } - end - test "include predictions with low uncertainty" do reassign_env(:filter_uncertain_predictions?, true) @@ -547,7 +411,8 @@ defmodule Predictions.PredictionsTest do "schedule_relationship" => "SCHEDULED", "start_date" => "20170329", "start_time" => nil, - "trip_id" => "32568935" + "trip_id" => "32568935", + "revenue" => true }, "vehicle" => %{ "id" => "R-54639F6C", @@ -612,7 +477,8 @@ defmodule Predictions.PredictionsTest do "schedule_relationship" => "SCHEDULED", "start_date" => "20170329", "start_time" => nil, - "trip_id" => "32568935" + "trip_id" => "32568935", + "revenue" => true }, "vehicle" => %{ "id" => "R-54639F6C", @@ -673,7 +539,8 @@ defmodule Predictions.PredictionsTest do "schedule_relationship" => "SCHEDULED", "start_date" => "20170329", "start_time" => nil, - "trip_id" => "32568935" + "trip_id" => "32568935", + "revenue" => true }, "vehicle" => %{ "id" => "R-54639F6C", @@ -739,7 +606,8 @@ defmodule Predictions.PredictionsTest do "schedule_relationship" => "SCHEDULED", "start_date" => "20170329", "start_time" => nil, - "trip_id" => "32568935" + "trip_id" => "32568935", + "revenue" => true }, "vehicle" => %{ "id" => "G-10040", diff --git a/test/signs/realtime_test.exs b/test/signs/realtime_test.exs index 64dffcd52..8bf3572c6 100644 --- a/test/signs/realtime_test.exs +++ b/test/signs/realtime_test.exs @@ -330,7 +330,14 @@ defmodule Signs.RealtimeTest do test "When the train is stopped a long time away, but not quite max time, shows stopped" do expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> - [prediction(destination: :mattapan, arrival: 1100, stopped: 8, trip_id: "1")] + [ + prediction( + destination: :mattapan, + arrival: 1100, + boarding_status: "Stopped 8 stops away", + trip_id: "1" + ) + ] end) expect_messages( @@ -378,7 +385,7 @@ defmodule Signs.RealtimeTest do 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)] + [prediction(destination: :mattapan, arrival: 3700, stopped: true)] end) expect_messages({"Mattapan 60+ min", ""}) @@ -388,8 +395,14 @@ defmodule Signs.RealtimeTest do test "only the first prediction in a source list can be BRD" do expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [ - prediction(destination: :mattapan, arrival: 0, stops_away: 0, trip_id: "1"), - prediction(destination: :mattapan, arrival: 100, stops_away: 1) + prediction( + destination: :mattapan, + arrival: 0, + stopped: true, + vehicle_at_predicted_stop: true, + trip_id: "1" + ), + prediction(destination: :mattapan, arrival: 100) ] end) @@ -406,7 +419,12 @@ defmodule Signs.RealtimeTest do expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [ prediction(destination: :boston_college, arrival: 200), - prediction(destination: :cleveland_circle, arrival: 250, stops_away: 0) + prediction( + destination: :cleveland_circle, + arrival: 250, + stopped: true, + vehicle_at_predicted_stop: true + ) ] end) @@ -486,21 +504,24 @@ defmodule Signs.RealtimeTest do [ prediction( destination: :riverside, - stops_away: 0, + stopped: true, + vehicle_at_predicted_stop: true, seconds_until_arrival: -30, seconds_until_departure: 60, trip_id: "1" ), prediction( destination: :riverside, - stops_away: 0, + stopped: true, + vehicle_at_predicted_stop: true, seconds_until_arrival: -15, seconds_until_departure: 75, trip_id: "2" ), prediction( destination: :boston_college, - stops_away: 0, + stopped: true, + vehicle_at_predicted_stop: true, seconds_until_arrival: nil, seconds_until_departure: 60, trip_id: "3" @@ -548,7 +569,14 @@ defmodule Signs.RealtimeTest do test "reads special boarding button announcement at Bowdoin" do expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> - [prediction(arrival: 0, destination: :wonderland, stops_away: 0)] + [ + prediction( + arrival: 0, + destination: :wonderland, + vehicle_at_predicted_stop: true, + stopped: true + ) + ] end) expect_audios([ @@ -844,7 +872,13 @@ defmodule Signs.RealtimeTest do # special case. expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [ - prediction(destination: :ashmont, arrival: 0, stops_away: 0, trip_id: "1"), + prediction( + destination: :ashmont, + arrival: 0, + stopped: true, + vehicle_at_predicted_stop: true, + trip_id: "1" + ), prediction(destination: :braintree, arrival: 45, trip_id: "2") ] end) @@ -910,8 +944,18 @@ defmodule Signs.RealtimeTest do # time, but we should fix this so it works the same as other readouts. expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [ - prediction(destination: :ashmont, arrival: 120, stopped: 3, trip_id: "1"), - prediction(destination: :ashmont, arrival: 130, stopped: 4, trip_id: "2") + prediction( + destination: :ashmont, + arrival: 120, + boarding_status: "Stopped 3 stops away", + trip_id: "1" + ), + prediction( + destination: :ashmont, + arrival: 130, + boarding_status: "Stopped 4 stops away", + trip_id: "2" + ) ] end) @@ -947,7 +991,12 @@ defmodule Signs.RealtimeTest do # Note: This should be changed to read both messages, so it's consistent with other cases. expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [ - prediction(destination: :ashmont, arrival: 120, stopped: 3, trip_id: "1"), + prediction( + destination: :ashmont, + arrival: 120, + boarding_status: "Stopped 3 stops away", + trip_id: "1" + ), prediction(destination: :ashmont, arrival: 130) ] end) @@ -1067,13 +1116,19 @@ defmodule Signs.RealtimeTest do test "When sign in partial am suppression, filters stopped predictions based on certainty" do expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [ - prediction(destination: :ashmont, arrival: 120, stopped: 2, arrival_certainty: 360), + prediction( + destination: :ashmont, + arrival: 120, + stopped?: true, + arrival_certainty: 360 + ), prediction( destination: :ashmont, arrival: 240, - stopped: 3, + stopped?: true, arrival_certainty: 120, - trip_id: "1" + trip_id: "1", + boarding_status: "Stopped 3 stops away" ) ] end) @@ -1394,13 +1449,6 @@ defmodule Signs.RealtimeTest do sec -> [seconds_until_arrival: sec, seconds_until_departure: sec + 30] end - opts = - opts ++ - case Keyword.get(opts, :stopped) do - nil -> [] - stops -> [stops_away: stops, boarding_status: "Stopped #{stops} stop away"] - end - %Predictions.Prediction{ stop_id: Keyword.get(opts, :stop_id, "1"), seconds_until_arrival: Keyword.get(opts, :seconds_until_arrival), @@ -1413,8 +1461,8 @@ defmodule Signs.RealtimeTest do route_id: Keyword.get(opts, :route_id), trip_id: Keyword.get(opts, :trip_id, "123"), destination_stop_id: Keyword.get(opts, :destination_stop_id), - stopped?: false, - stops_away: Keyword.get(opts, :stops_away, 1), + stopped?: Keyword.get(opts, :stopped, false), + vehicle_at_predicted_stop?: Keyword.get(opts, :vehicle_at_predicted_stop, false), boarding_status: Keyword.get(opts, :boarding_status), revenue_trip?: true, vehicle_id: "v1" From 541999541c1f007ed77665111adf0c2fbe635740 Mon Sep 17 00:00:00 2001 From: Kim Date: Wed, 27 Mar 2024 14:22:57 -0400 Subject: [PATCH 02/26] PR feedback --- .envrc.template | 4 +- config/runtime.exs | 4 +- lib/content/message/predictions.ex | 15 +-- lib/predictions/prediction.ex | 6 +- lib/predictions/predictions.ex | 23 +++-- lib/signs/utilities/predictions.ex | 2 +- test/content/messages/predictions_test.exs | 45 ++------- test/engine/predictions_test.exs | 2 - test/predictions/predictions_test.exs | 5 - test/signs/realtime_test.exs | 101 ++++++--------------- 10 files changed, 66 insertions(+), 141 deletions(-) diff --git a/.envrc.template b/.envrc.template index 4cb6df709..2fa108278 100644 --- a/.envrc.template +++ b/.envrc.template @@ -19,5 +19,5 @@ export API_V3_URL=https://api-dev-green.mbtace.com # URLs of the enhanced trip-update and vehicle-position feeds. Default to the real feed URLs if # not set here. -#export TRIP_UPDATE_URL= -#export VEHICLE_POSITIONS_URL= +#export TRIP_UPDATE_URL="https://cdn.mbta.com/realtime/TripUpdates_enhanced.json" +#export VEHICLE_POSITIONS_URL="https://cdn.mbta.com/realtime/VehiclePositions_enhanced.json" diff --git a/config/runtime.exs b/config/runtime.exs index 77211f051..3b27129aa 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -9,8 +9,8 @@ if config_env() != :test do config :realtime_signs, sign_ui_url: System.get_env("SIGN_UI_URL"), sign_ui_api_key: System.get_env("SIGN_UI_API_KEY"), - trip_update_url: System.get_env("TRIP_UPDATE_URL", "https://s3.amazonaws.com/mbta-gtfs-s3/rtr/TripUpdates_enhanced.json"), - vehicle_positions_url: System.get_env("VEHICLE_POSITIONS_URL", "https://s3.amazonaws.com/mbta-gtfs-s3/rtr/VehiclePositions_enhanced.json"), + trip_update_url: System.get_env("TRIP_UPDATE_URL"), + vehicle_positions_url: System.get_env("VEHICLE_POSITIONS_URL"), s3_bucket: System.get_env("SIGNS_S3_BUCKET"), s3_path: System.get_env("SIGNS_S3_PATH"), api_v3_url: System.get_env("API_V3_URL"), diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index 7784f1ace..3f7d2dc4b 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -77,7 +77,7 @@ defmodule Content.Message.Predictions do {minutes, approximate?} = cond do - prediction.stopped? and prediction.vehicle_at_predicted_stop? -> + prediction.stopped_at_predicted_stop? -> {:boarding, false} predicted_time <= 30 -> @@ -135,13 +135,16 @@ defmodule Content.Message.Predictions do def terminal(prediction, station_code, zone, sign, width \\ 18) def terminal(prediction, station_code, zone, sign, width) do - stopped_at? = prediction.vehicle_at_predicted_stop? and prediction.stopped? - {minutes, approximate?} = case prediction.seconds_until_departure + @terminal_prediction_offset_seconds do - x when x <= @terminal_brd_seconds and stopped_at? -> {:boarding, false} - x when x <= @terminal_brd_seconds -> {1, false} - x -> compute_minutes(x, prediction.departure_certainty) + x when x <= @terminal_brd_seconds and prediction.stopped_at_predicted_stop? -> + {:boarding, false} + + x when x <= @terminal_brd_seconds -> + {1, false} + + x -> + compute_minutes(x, prediction.departure_certainty) end case Content.Utilities.destination_for_prediction( diff --git a/lib/predictions/prediction.ex b/lib/predictions/prediction.ex index 92a533de7..ee9fe08f3 100644 --- a/lib/predictions/prediction.ex +++ b/lib/predictions/prediction.ex @@ -10,8 +10,7 @@ defmodule Predictions.Prediction do route_id: nil, trip_id: nil, destination_stop_id: nil, - stopped?: false, - vehicle_at_predicted_stop?: false, + stopped_at_predicted_stop?: false, boarding_status: nil, revenue_trip?: true, vehicle_id: nil @@ -30,8 +29,7 @@ defmodule Predictions.Prediction do route_id: String.t(), trip_id: trip_id() | nil, destination_stop_id: String.t(), - stopped?: boolean(), - vehicle_at_predicted_stop?: boolean(), + stopped_at_predicted_stop?: boolean(), boarding_status: String.t() | nil, revenue_trip?: boolean(), vehicle_id: String.t() | nil diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index 646a13907..26ba58570 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -9,8 +9,8 @@ defmodule Predictions.Predictions do def get_all(feed_message, current_time) do predictions = feed_message["entity"] - |> Enum.map(& &1["trip_update"]) - |> Enum.filter( + |> Stream.map(& &1["trip_update"]) + |> Stream.filter( &(&1["trip"]["route_id"] in [ "Red", "Blue", @@ -20,15 +20,14 @@ defmodule Predictions.Predictions do "Green-D", "Green-E", "Mattapan" - ]) + ] and &1["trip"]["schedule_relationship"] != "CANCELED") ) - |> Enum.reject(&(&1["trip"]["schedule_relationship"] == "CANCELED")) - |> Enum.flat_map(&transform_stop_time_updates/1) - |> Enum.filter(fn {update, _, _, _, _, _, _} -> + |> Stream.flat_map(&transform_stop_time_updates/1) + |> Stream.filter(fn {update, _, _, _, _, _, _} -> (update["arrival"] && update["arrival"]["uncertainty"]) || (update["departure"] && update["departure"]["uncertainty"]) end) - |> Enum.map(&prediction_from_update(&1, current_time)) + |> Stream.map(&prediction_from_update(&1, current_time)) |> Enum.reject( &(is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure) and is_nil(&1.seconds_until_passthrough)) @@ -36,8 +35,8 @@ defmodule Predictions.Predictions do vehicles_running_revenue_trips = predictions - |> Enum.filter(& &1.revenue_trip?) - |> Enum.map(& &1.vehicle_id) + |> Stream.filter(& &1.revenue_trip?) + |> Stream.map(& &1.vehicle_id) |> MapSet.new() {Enum.group_by(predictions, fn prediction -> @@ -108,9 +107,9 @@ defmodule Predictions.Predictions do route_id: route_id, trip_id: trip_id, destination_stop_id: last_stop_id, - stopped?: not is_nil(vehicle_location) and vehicle_location.status == :stopped_at, - vehicle_at_predicted_stop?: - not is_nil(vehicle_location) and stop_time_update["stop_id"] == vehicle_location.stop_id, + stopped_at_predicted_stop?: + not is_nil(vehicle_location) and vehicle_location.status == :stopped_at and + stop_time_update["stop_id"] == vehicle_location.stop_id, boarding_status: stop_time_update["boarding_status"], revenue_trip?: revenue_trip?, vehicle_id: vehicle_id diff --git a/lib/signs/utilities/predictions.ex b/lib/signs/utilities/predictions.ex index 398d51593..08bbb217e 100644 --- a/lib/signs/utilities/predictions.ex +++ b/lib/signs/utilities/predictions.ex @@ -47,7 +47,7 @@ defmodule Signs.Utilities.Predictions do {if terminal_prediction?(prediction, sources) do 0 else - if prediction.stopped? and prediction.vehicle_at_predicted_stop?, + if prediction.stopped_at_predicted_stop?, do: 0, else: 1 end, prediction.seconds_until_departure, prediction.seconds_until_arrival} diff --git a/test/content/messages/predictions_test.exs b/test/content/messages/predictions_test.exs index 353dc4137..59c197f25 100644 --- a/test/content/messages/predictions_test.exs +++ b/test/content/messages/predictions_test.exs @@ -17,7 +17,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 0, direction_id: 1, route_id: "NON-ROUTE", - stopped?: false, destination_stop_id: "70261" } @@ -34,7 +33,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 0, direction_id: 1, route_id: "Mattapan", - stopped?: false, destination_stop_id: "70261" } @@ -48,8 +46,7 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "Mattapan", destination_stop_id: "70261", - stopped?: true, - vehicle_at_predicted_stop?: true, + stopped_at_predicted_stop?: true, boarding_status: "Boarding" } @@ -63,7 +60,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 30, direction_id: 0, route_id: "Mattapan", - stopped?: false, destination_stop_id: "70275" } @@ -77,7 +73,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 31, direction_id: 0, route_id: "Mattapan", - stopped?: false, destination_stop_id: "70275" } @@ -91,7 +86,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 61, direction_id: 0, route_id: "Mattapan", - stopped?: false, destination_stop_id: "70275" } @@ -106,7 +100,6 @@ defmodule Content.Message.PredictionsTest do arrival_certainty: 360, direction_id: 0, route_id: "Mattapan", - stopped?: false, destination_stop_id: "70275" } @@ -120,7 +113,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 550, route_id: "Mattapan", direction_id: 0, - stopped?: false, destination_stop_id: "70275" } @@ -133,7 +125,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 65, direction_id: 1, route_id: "Mattapan", - stopped?: false, destination_stop_id: "70261" } @@ -147,7 +138,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 125, direction_id: 1, route_id: "Mattapan", - stopped?: false, destination_stop_id: "70261" } @@ -161,7 +151,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: -5, route_id: "Mattapan", direction_id: 1, - stopped?: false, destination_stop_id: "70261" } @@ -175,8 +164,7 @@ defmodule Content.Message.PredictionsTest do route_id: "Mattapan", direction_id: 1, destination_stop_id: "70261", - stopped?: true, - vehicle_at_predicted_stop?: true, + stopped_at_predicted_stop?: true, boarding_status: "Boarding" } @@ -190,7 +178,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 91, route_id: "Mattapan", direction_id: 1, - stopped?: false, destination_stop_id: "70261" } @@ -204,7 +191,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_arrival: 91, route_id: "Mattapan", direction_id: 1, - stopped?: false, destination_stop_id: "70261", trip_id: "trip1" } @@ -219,8 +205,7 @@ defmodule Content.Message.PredictionsTest do stop_id: "70086", seconds_until_arrival: 300, direction_id: 1, - route_id: "Red", - stopped?: false + route_id: "Red" } msg = Content.Message.Predictions.non_terminal(prediction, "RJFK", "m", @sign) @@ -236,8 +221,7 @@ defmodule Content.Message.PredictionsTest do stop_id: "70096", seconds_until_arrival: 300, direction_id: 1, - route_id: "Red", - stopped?: false + route_id: "Red" } msg = Content.Message.Predictions.non_terminal(prediction, "RJFK", "m", @sign) @@ -253,8 +237,7 @@ defmodule Content.Message.PredictionsTest do stop_id: "70096", seconds_until_arrival: 360, direction_id: 1, - route_id: "Red", - stopped?: false + route_id: "Red" } msg = Content.Message.Predictions.non_terminal(prediction, "RJFK", "m", @sign) @@ -279,8 +262,7 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "NON-ROUTE", destination_stop_id: "70261", - stopped?: false, - vehicle_at_predicted_stop?: true, + stopped_at_predicted_stop?: true, boarding_status: "Boarding" } @@ -297,7 +279,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_departure: 0, direction_id: 1, route_id: "NON-ROUTE", - stopped?: false, destination_stop_id: "70261" } @@ -315,8 +296,7 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "Mattapan", destination_stop_id: "70261", - stopped?: true, - vehicle_at_predicted_stop?: true, + stopped_at_predicted_stop?: true, boarding_status: "Stopped at station" } @@ -331,8 +311,7 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "Mattapan", destination_stop_id: "70261", - stopped?: false, - vehicle_at_predicted_stop?: true, + stopped_at_predicted_stop?: true, boarding_status: "Stopped at station" } @@ -347,8 +326,7 @@ defmodule Content.Message.PredictionsTest do direction_id: 1, route_id: "Mattapan", destination_stop_id: "70261", - stopped?: false, - vehicle_at_predicted_stop?: true, + stopped_at_predicted_stop?: true, boarding_status: "Stopped at station" } @@ -362,7 +340,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_departure: 70, direction_id: 1, route_id: "Mattapan", - stopped?: false, destination_stop_id: "70261" } @@ -377,8 +354,7 @@ defmodule Content.Message.PredictionsTest do seconds_until_departure: 180, direction_id: 1, route_id: "Orange", - stopped?: false, - vehicle_at_predicted_stop?: true + stopped_at_predicted_stop?: true } msg = Content.Message.Predictions.terminal(prediction, "test", "m", @sign) @@ -394,7 +370,6 @@ defmodule Content.Message.PredictionsTest do seconds_until_departure: 91, route_id: "Mattapan", direction_id: 1, - stopped?: false, destination_stop_id: "70261", trip_id: "trip1" } diff --git a/test/engine/predictions_test.exs b/test/engine/predictions_test.exs index 63381685c..b3e268ef2 100644 --- a/test/engine/predictions_test.exs +++ b/test/engine/predictions_test.exs @@ -65,8 +65,6 @@ defmodule Engine.PredictionsTest do assert :ets.info(predictions_table)[:size] == 2 [{{"stop_to_remove", 0}, []}] = :ets.lookup(predictions_table, {"stop_to_remove", 0}) - :ets.lookup(predictions_table, {"stop_to_update", 0}) - [{{"stop_to_update", 0}, [%Predictions.Prediction{}]}] = :ets.lookup(predictions_table, {"stop_to_update", 0}) end diff --git a/test/predictions/predictions_test.exs b/test/predictions/predictions_test.exs index f73adc38d..63eb514ee 100644 --- a/test/predictions/predictions_test.exs +++ b/test/predictions/predictions_test.exs @@ -252,7 +252,6 @@ defmodule Predictions.PredictionsTest do schedule_relationship: :scheduled, direction_id: 0, route_id: "Mattapan", - stopped?: false, destination_stop_id: "70261", trip_id: "32568935", revenue_trip?: true, @@ -267,7 +266,6 @@ defmodule Predictions.PredictionsTest do direction_id: 0, schedule_relationship: :scheduled, route_id: "Mattapan", - stopped?: false, destination_stop_id: "70261", trip_id: "32568935", revenue_trip?: true, @@ -282,7 +280,6 @@ defmodule Predictions.PredictionsTest do direction_id: 1, schedule_relationship: :scheduled, route_id: "Blue", - stopped?: false, destination_stop_id: "70060", trip_id: "trip_2", revenue_trip?: true, @@ -297,7 +294,6 @@ defmodule Predictions.PredictionsTest do direction_id: 1, schedule_relationship: :scheduled, route_id: "Blue", - stopped?: false, destination_stop_id: "70060", trip_id: "trip_2", revenue_trip?: true, @@ -367,7 +363,6 @@ defmodule Predictions.PredictionsTest do direction_id: 0, schedule_relationship: :scheduled, route_id: "Mattapan", - stopped?: false, destination_stop_id: "70263", trip_id: "32568935", revenue_trip?: true, diff --git a/test/signs/realtime_test.exs b/test/signs/realtime_test.exs index 8bf3572c6..01b4efa7d 100644 --- a/test/signs/realtime_test.exs +++ b/test/signs/realtime_test.exs @@ -330,14 +330,7 @@ defmodule Signs.RealtimeTest do test "When the train is stopped a long time away, but not quite max time, shows stopped" do expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> - [ - prediction( - destination: :mattapan, - arrival: 1100, - boarding_status: "Stopped 8 stops away", - trip_id: "1" - ) - ] + [prediction(destination: :mattapan, arrival: 1100, stopped: 8, trip_id: "1")] end) expect_messages( @@ -385,7 +378,7 @@ defmodule Signs.RealtimeTest do 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: true)] + [prediction(destination: :mattapan, arrival: 3700, stopped: 8)] end) expect_messages({"Mattapan 60+ min", ""}) @@ -395,13 +388,7 @@ defmodule Signs.RealtimeTest do test "only the first prediction in a source list can be BRD" do expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [ - prediction( - destination: :mattapan, - arrival: 0, - stopped: true, - vehicle_at_predicted_stop: true, - trip_id: "1" - ), + prediction(destination: :mattapan, arrival: 0, stopped: 0, trip_id: "1"), prediction(destination: :mattapan, arrival: 100) ] end) @@ -419,12 +406,7 @@ defmodule Signs.RealtimeTest do expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [ prediction(destination: :boston_college, arrival: 200), - prediction( - destination: :cleveland_circle, - arrival: 250, - stopped: true, - vehicle_at_predicted_stop: true - ) + prediction(destination: :cleveland_circle, arrival: 250, stopped: 0) ] end) @@ -504,24 +486,21 @@ defmodule Signs.RealtimeTest do [ prediction( destination: :riverside, - stopped: true, - vehicle_at_predicted_stop: true, + stopped: 0, seconds_until_arrival: -30, seconds_until_departure: 60, trip_id: "1" ), prediction( destination: :riverside, - stopped: true, - vehicle_at_predicted_stop: true, + stopped: 0, seconds_until_arrival: -15, seconds_until_departure: 75, trip_id: "2" ), prediction( destination: :boston_college, - stopped: true, - vehicle_at_predicted_stop: true, + stopped: 0, seconds_until_arrival: nil, seconds_until_departure: 60, trip_id: "3" @@ -569,14 +548,7 @@ defmodule Signs.RealtimeTest do test "reads special boarding button announcement at Bowdoin" do expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> - [ - prediction( - arrival: 0, - destination: :wonderland, - vehicle_at_predicted_stop: true, - stopped: true - ) - ] + [prediction(arrival: 0, destination: :wonderland, stopped: 0)] end) expect_audios([ @@ -872,13 +844,7 @@ defmodule Signs.RealtimeTest do # special case. expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [ - prediction( - destination: :ashmont, - arrival: 0, - stopped: true, - vehicle_at_predicted_stop: true, - trip_id: "1" - ), + prediction(destination: :ashmont, arrival: 0, stopped: 0, trip_id: "1"), prediction(destination: :braintree, arrival: 45, trip_id: "2") ] end) @@ -944,18 +910,8 @@ defmodule Signs.RealtimeTest do # time, but we should fix this so it works the same as other readouts. expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [ - prediction( - destination: :ashmont, - arrival: 120, - boarding_status: "Stopped 3 stops away", - trip_id: "1" - ), - prediction( - destination: :ashmont, - arrival: 130, - boarding_status: "Stopped 4 stops away", - trip_id: "2" - ) + prediction(destination: :ashmont, arrival: 120, stopped: 3, trip_id: "1"), + prediction(destination: :ashmont, arrival: 130, stopped: 4, trip_id: "2") ] end) @@ -991,12 +947,7 @@ defmodule Signs.RealtimeTest do # Note: This should be changed to read both messages, so it's consistent with other cases. expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [ - prediction( - destination: :ashmont, - arrival: 120, - boarding_status: "Stopped 3 stops away", - trip_id: "1" - ), + prediction(destination: :ashmont, arrival: 120, stopped: 3, trip_id: "1"), prediction(destination: :ashmont, arrival: 130) ] end) @@ -1116,19 +1067,13 @@ defmodule Signs.RealtimeTest do test "When sign in partial am suppression, filters stopped predictions based on certainty" do expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [ - prediction( - destination: :ashmont, - arrival: 120, - stopped?: true, - arrival_certainty: 360 - ), + prediction(destination: :ashmont, arrival: 120, stopped: 2, arrival_certainty: 360), prediction( destination: :ashmont, arrival: 240, - stopped?: true, + stopped: 3, arrival_certainty: 120, - trip_id: "1", - boarding_status: "Stopped 3 stops away" + trip_id: "1" ) ] end) @@ -1449,6 +1394,19 @@ defmodule Signs.RealtimeTest do sec -> [seconds_until_arrival: sec, seconds_until_departure: sec + 30] end + opts = + opts ++ + case Keyword.get(opts, :stopped) do + nil -> + [] + + stops when stops > 0 -> + [stopped_at_predicted_stop: false, boarding_status: "Stopped #{stops} stop away"] + + 0 -> + [stopped_at_predicted_stop: true] + end + %Predictions.Prediction{ stop_id: Keyword.get(opts, :stop_id, "1"), seconds_until_arrival: Keyword.get(opts, :seconds_until_arrival), @@ -1461,8 +1419,7 @@ defmodule Signs.RealtimeTest do route_id: Keyword.get(opts, :route_id), trip_id: Keyword.get(opts, :trip_id, "123"), destination_stop_id: Keyword.get(opts, :destination_stop_id), - stopped?: Keyword.get(opts, :stopped, false), - vehicle_at_predicted_stop?: Keyword.get(opts, :vehicle_at_predicted_stop, false), + stopped_at_predicted_stop?: Keyword.get(opts, :stopped_at_predicted_stop, false), boarding_status: Keyword.get(opts, :boarding_status), revenue_trip?: true, vehicle_id: "v1" From f03d8a739dee1c1de61f6f400ef33478d075731f Mon Sep 17 00:00:00 2001 From: Kim Date: Wed, 27 Mar 2024 15:53:18 -0400 Subject: [PATCH 03/26] simplify abstraction --- test/signs/realtime_test.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/signs/realtime_test.exs b/test/signs/realtime_test.exs index 01b4efa7d..306c7706f 100644 --- a/test/signs/realtime_test.exs +++ b/test/signs/realtime_test.exs @@ -1400,11 +1400,11 @@ defmodule Signs.RealtimeTest do nil -> [] - stops when stops > 0 -> - [stopped_at_predicted_stop: false, boarding_status: "Stopped #{stops} stop away"] - 0 -> [stopped_at_predicted_stop: true] + + stops -> + [stopped_at_predicted_stop: false, boarding_status: "Stopped #{stops} stop away"] end %Predictions.Prediction{ From 948020e3df74c185fc35ab101d64efa03b7081c8 Mon Sep 17 00:00:00 2001 From: Paul Kim Date: Thu, 28 Mar 2024 15:59:11 -0400 Subject: [PATCH 04/26] Update .envrc.template Co-authored-by: Brett Heath-Wlaz --- .envrc.template | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.envrc.template b/.envrc.template index 2fa108278..75cd42bc7 100644 --- a/.envrc.template +++ b/.envrc.template @@ -17,7 +17,6 @@ export API_V3_URL=https://api-dev-green.mbtace.com #export CHELSEA_BRIDGE_URL= #export CHELSEA_BRIDGE_AUTH= -# URLs of the enhanced trip-update and vehicle-position feeds. Default to the real feed URLs if -# not set here. +# URLs of the enhanced trip-update and vehicle-position feeds. Required. #export TRIP_UPDATE_URL="https://cdn.mbta.com/realtime/TripUpdates_enhanced.json" #export VEHICLE_POSITIONS_URL="https://cdn.mbta.com/realtime/VehiclePositions_enhanced.json" From 8251ca961e48d75d62de2879b1f66aff66f44d6b Mon Sep 17 00:00:00 2001 From: Kim Date: Wed, 12 Jun 2024 13:33:38 -0400 Subject: [PATCH 05/26] Filter out past departures and adjust last trip filtering --- lib/predictions/last_trip.ex | 13 ++++++++++++- lib/predictions/predictions.ex | 7 ++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/predictions/last_trip.ex b/lib/predictions/last_trip.ex index 23d5d1987..dcc005b07 100644 --- a/lib/predictions/last_trip.ex +++ b/lib/predictions/last_trip.ex @@ -2,7 +2,18 @@ defmodule Predictions.LastTrip do defp get_running_trips(predictions_feed) do predictions_feed["entity"] |> Stream.map(& &1["trip_update"]) - |> Enum.reject(&(&1["trip"]["schedule_relationship"] == "CANCELED")) + |> Stream.filter( + &(&1["trip"]["route_id"] in [ + "Red", + "Blue", + "Orange", + "Green-B", + "Green-C", + "Green-D", + "Green-E", + "Mattapan" + ] and &1["trip"]["schedule_relationship"] != "CANCELED") + ) end def get_last_trips(predictions_feed) do diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index 26ba58570..38d98c95f 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -29,8 +29,9 @@ defmodule Predictions.Predictions do end) |> Stream.map(&prediction_from_update(&1, current_time)) |> Enum.reject( - &(is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure) and - is_nil(&1.seconds_until_passthrough)) + &((is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure) and + is_nil(&1.seconds_until_passthrough)) or + (&1.seconds_until_departure && &1.seconds_until_departure < 0)) ) vehicles_running_revenue_trips = @@ -99,7 +100,7 @@ defmodule Predictions.Predictions do direction_id: direction_id, seconds_until_arrival: max(0, seconds_until_arrival), arrival_certainty: stop_time_update["arrival"]["uncertainty"], - seconds_until_departure: max(0, seconds_until_departure), + seconds_until_departure: seconds_until_departure, departure_certainty: stop_time_update["departure"]["uncertainty"], seconds_until_passthrough: max(0, seconds_until_passthrough), schedule_relationship: From 099efbe1755fa5821f3f3cfc108219f3bbd7a846 Mon Sep 17 00:00:00 2001 From: Kim Date: Wed, 12 Jun 2024 13:41:26 -0400 Subject: [PATCH 06/26] Remove some references to RTR --- .envrc.template | 4 ++-- config/runtime.exs | 4 ++-- test/content/messages/predictions_test.exs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.envrc.template b/.envrc.template index 75cd42bc7..bb29bf3fe 100644 --- a/.envrc.template +++ b/.envrc.template @@ -18,5 +18,5 @@ export API_V3_URL=https://api-dev-green.mbtace.com #export CHELSEA_BRIDGE_AUTH= # URLs of the enhanced trip-update and vehicle-position feeds. Required. -#export TRIP_UPDATE_URL="https://cdn.mbta.com/realtime/TripUpdates_enhanced.json" -#export VEHICLE_POSITIONS_URL="https://cdn.mbta.com/realtime/VehiclePositions_enhanced.json" +#export TRIP_UPDATE_URL="https://s3.amazonaws.com/mbta-gtfs-s3/concentrate/TripUpdates_enhanced.json" +#export VEHICLE_POSITIONS_URL="https://s3.amazonaws.com/mbta-gtfs-s3/concentrate/VehiclePositions_enhanced.json" diff --git a/config/runtime.exs b/config/runtime.exs index 47c3e5f91..280575dad 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -12,12 +12,12 @@ if config_env() != :test do trip_update_url: System.get_env( "TRIP_UPDATE_URL", - "https://s3.amazonaws.com/mbta-gtfs-s3/rtr/TripUpdates_enhanced.json" + "https://s3.amazonaws.com/mbta-gtfs-s3/concentrate/TripUpdates_enhanced.json" ), vehicle_positions_url: System.get_env( "VEHICLE_POSITIONS_URL", - "https://s3.amazonaws.com/mbta-gtfs-s3/rtr/VehiclePositions_enhanced.json" + "https://s3.amazonaws.com/mbta-gtfs-s3/concentrate/VehiclePositions_enhanced.json" ), s3_bucket: System.get_env("SIGNS_S3_BUCKET"), s3_path: System.get_env("SIGNS_S3_PATH"), diff --git a/test/content/messages/predictions_test.exs b/test/content/messages/predictions_test.exs index 59c197f25..4c0a69cbe 100644 --- a/test/content/messages/predictions_test.exs +++ b/test/content/messages/predictions_test.exs @@ -290,7 +290,7 @@ defmodule Content.Message.PredictionsTest do assert log =~ "no_destination_for_prediction" end - test "puts boarding on the sign when train is supposed to be boarding according to rtr" do + test "puts boarding on the sign when train is supposed to be boarding according to concentrate" do prediction = %Predictions.Prediction{ seconds_until_departure: 75, direction_id: 1, From a22e752320102c71d161678f35644e11f47a7f93 Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 13 Jun 2024 15:24:16 -0400 Subject: [PATCH 07/26] Move route_id check to a shared helper --- lib/predictions/last_trip.ex | 14 ++++---------- lib/predictions/predictions.ex | 25 +++++++++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/predictions/last_trip.ex b/lib/predictions/last_trip.ex index dcc005b07..d9adf529f 100644 --- a/lib/predictions/last_trip.ex +++ b/lib/predictions/last_trip.ex @@ -1,18 +1,12 @@ defmodule Predictions.LastTrip do + alias Predictions.Predictions + defp get_running_trips(predictions_feed) do predictions_feed["entity"] |> Stream.map(& &1["trip_update"]) |> Stream.filter( - &(&1["trip"]["route_id"] in [ - "Red", - "Blue", - "Orange", - "Green-B", - "Green-C", - "Green-D", - "Green-E", - "Mattapan" - ] and &1["trip"]["schedule_relationship"] != "CANCELED") + &(Predictions.relevant_rail_route?(&1["trip"]["route_id"]) and + &1["trip"]["schedule_relationship"] != "CANCELED") ) end diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index 38d98c95f..e5fc3d11b 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -11,16 +11,8 @@ defmodule Predictions.Predictions do feed_message["entity"] |> Stream.map(& &1["trip_update"]) |> Stream.filter( - &(&1["trip"]["route_id"] in [ - "Red", - "Blue", - "Orange", - "Green-B", - "Green-C", - "Green-D", - "Green-E", - "Mattapan" - ] and &1["trip"]["schedule_relationship"] != "CANCELED") + &(relevant_rail_route?(&1["trip"]["route_id"]) and + &1["trip"]["schedule_relationship"] != "CANCELED") ) |> Stream.flat_map(&transform_stop_time_updates/1) |> Stream.filter(fn {update, _, _, _, _, _, _} -> @@ -125,6 +117,19 @@ defmodule Predictions.Predictions do Jason.decode!(body) end + def relevant_rail_route?(route_id) do + route_id in [ + "Red", + "Blue", + "Orange", + "Green-B", + "Green-C", + "Green-D", + "Green-E", + "Mattapan" + ] + end + @spec translate_schedule_relationship(String.t()) :: :skipped | :scheduled defp translate_schedule_relationship("SKIPPED") do :skipped From 88527439d9d5adb3a6e24b30f19658b5bd9169f3 Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 8 Aug 2024 14:56:10 -0400 Subject: [PATCH 08/26] Log prediction details for terminal predictions --- lib/content/message/predictions.ex | 26 ++++++++++++++++++++++++++ lib/predictions/prediction.ex | 10 ++++++++-- lib/predictions/predictions.ex | 5 ++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index 3f7d2dc4b..e50505d82 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -135,6 +135,32 @@ defmodule Content.Message.Predictions do def terminal(prediction, station_code, zone, sign, width \\ 18) def terminal(prediction, station_code, zone, sign, width) do + Logger.info([ + "prediction_info: ", + "station_code=", + station_code, + " zone=", + zone, + " trip_id=", + prediction.trip_id, + " stop_id=", + prediction.stop_id, + " vehicle_id=", + prediction.vehicle_id, + " direction_id=", + prediction.direction_id, + " seconds_until_departure=", + prediction.seconds_until_departure, + " boarding_status=", + prediction.boarding_status, + " vehicle_status=", + inspect(prediction.vehicle_status), + " vehicle_location_stop_id=", + prediction.vehicle_location_stop_id, + " vehicle_location_trip_id=", + prediction.vehicle_location_trip_id + ]) + {minutes, approximate?} = case prediction.seconds_until_departure + @terminal_prediction_offset_seconds do x when x <= @terminal_brd_seconds and prediction.stopped_at_predicted_stop? -> diff --git a/lib/predictions/prediction.ex b/lib/predictions/prediction.ex index ee9fe08f3..eea617f6b 100644 --- a/lib/predictions/prediction.ex +++ b/lib/predictions/prediction.ex @@ -13,7 +13,10 @@ defmodule Predictions.Prediction do stopped_at_predicted_stop?: false, boarding_status: nil, revenue_trip?: true, - vehicle_id: nil + vehicle_id: nil, + vehicle_status: nil, + vehicle_location_stop_id: nil, + vehicle_location_trip_id: nil @type trip_id :: String.t() @@ -32,6 +35,9 @@ defmodule Predictions.Prediction do stopped_at_predicted_stop?: boolean(), boarding_status: String.t() | nil, revenue_trip?: boolean(), - vehicle_id: String.t() | nil + vehicle_id: String.t() | nil, + vehicle_status: :incoming_at | :stopped_at | :in_transit_to, + vehicle_location_stop_id: String.t(), + vehicle_location_trip_id: String.t() } end diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index e5fc3d11b..47ab4b5ff 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -105,7 +105,10 @@ defmodule Predictions.Predictions do stop_time_update["stop_id"] == vehicle_location.stop_id, boarding_status: stop_time_update["boarding_status"], revenue_trip?: revenue_trip?, - vehicle_id: vehicle_id + vehicle_id: vehicle_id, + vehicle_status: vehicle_location.status, + vehicle_location_stop_id: vehicle_location.stop_id, + vehicle_location_trip_id: vehicle_location.trip_id } end From 5903d3fe5cc6394fb41266b605b87ef6cd66ce66 Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 8 Aug 2024 15:19:23 -0400 Subject: [PATCH 09/26] add inspects --- lib/content/message/predictions.ex | 10 +++++----- lib/predictions/predictions.ex | 13 ++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index e50505d82..3c96b2381 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -148,17 +148,17 @@ defmodule Content.Message.Predictions do " vehicle_id=", prediction.vehicle_id, " direction_id=", - prediction.direction_id, + inspect(prediction.direction_id), " seconds_until_departure=", - prediction.seconds_until_departure, + inspect(prediction.seconds_until_departure), " boarding_status=", - prediction.boarding_status, + inspect(prediction.boarding_status), " vehicle_status=", inspect(prediction.vehicle_status), " vehicle_location_stop_id=", - prediction.vehicle_location_stop_id, + inspect(prediction.vehicle_location_stop_id), " vehicle_location_trip_id=", - prediction.vehicle_location_trip_id + inspect(prediction.vehicle_location_trip_id) ]) {minutes, approximate?} = diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index 47ab4b5ff..160d55189 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -86,6 +86,13 @@ defmodule Predictions.Predictions do else: nil vehicle_location = Engine.Locations.for_vehicle(vehicle_id) + vehicle_status = if not is_nil(vehicle_location), do: vehicle_location.status, else: "none" + + vehicle_locaton_stop_id = + if not is_nil(vehicle_location), do: vehicle_location.stop_id, else: "none" + + vehicle_location_trip_id = + if not is_nil(vehicle_location), do: vehicle_location.trip_id, else: "none" %Prediction{ stop_id: stop_time_update["stop_id"], @@ -106,9 +113,9 @@ defmodule Predictions.Predictions do boarding_status: stop_time_update["boarding_status"], revenue_trip?: revenue_trip?, vehicle_id: vehicle_id, - vehicle_status: vehicle_location.status, - vehicle_location_stop_id: vehicle_location.stop_id, - vehicle_location_trip_id: vehicle_location.trip_id + vehicle_status: vehicle_status, + vehicle_location_stop_id: vehicle_locaton_stop_id, + vehicle_location_trip_id: vehicle_location_trip_id } end From 17265974e115119a316b7126d41b7df2ce46d0c1 Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 8 Aug 2024 15:35:32 -0400 Subject: [PATCH 10/26] add inspect --- lib/content/message/predictions.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index 3c96b2381..9443a6fe1 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -146,7 +146,7 @@ defmodule Content.Message.Predictions do " stop_id=", prediction.stop_id, " vehicle_id=", - prediction.vehicle_id, + insepct(prediction.vehicle_id), " direction_id=", inspect(prediction.direction_id), " seconds_until_departure=", From 41f3b106bfd309430a26a888b48eb6156e76142f Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 8 Aug 2024 15:40:35 -0400 Subject: [PATCH 11/26] fix typo --- lib/content/message/predictions.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index 9443a6fe1..c78e5ed02 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -146,7 +146,7 @@ defmodule Content.Message.Predictions do " stop_id=", prediction.stop_id, " vehicle_id=", - insepct(prediction.vehicle_id), + inspect(prediction.vehicle_id), " direction_id=", inspect(prediction.direction_id), " seconds_until_departure=", From 28a000b537cfd747a271560e61ec6773cc31fc41 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 12 Aug 2024 15:29:46 -0400 Subject: [PATCH 12/26] only log when seconds til boarding is under terminal brd seconds --- lib/content/message/predictions.ex | 53 ++++++++++++++++-------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index c78e5ed02..98fd25dad 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -135,31 +135,34 @@ defmodule Content.Message.Predictions do def terminal(prediction, station_code, zone, sign, width \\ 18) def terminal(prediction, station_code, zone, sign, width) do - Logger.info([ - "prediction_info: ", - "station_code=", - station_code, - " zone=", - zone, - " trip_id=", - prediction.trip_id, - " stop_id=", - prediction.stop_id, - " vehicle_id=", - inspect(prediction.vehicle_id), - " direction_id=", - inspect(prediction.direction_id), - " seconds_until_departure=", - inspect(prediction.seconds_until_departure), - " boarding_status=", - inspect(prediction.boarding_status), - " vehicle_status=", - inspect(prediction.vehicle_status), - " vehicle_location_stop_id=", - inspect(prediction.vehicle_location_stop_id), - " vehicle_location_trip_id=", - inspect(prediction.vehicle_location_trip_id) - ]) + if prediction.seconds_until_departure + @terminal_prediction_offset_seconds <= + @terminal_brd_seconds do + Logger.info([ + "prediction_info: ", + "station_code=", + station_code, + " zone=", + zone, + " trip_id=", + prediction.trip_id, + " stop_id=", + prediction.stop_id, + " vehicle_id=", + inspect(prediction.vehicle_id), + " direction_id=", + inspect(prediction.direction_id), + " seconds_until_departure=", + inspect(prediction.seconds_until_departure), + " boarding_status=", + inspect(prediction.boarding_status), + " vehicle_status=", + inspect(prediction.vehicle_status), + " vehicle_location_stop_id=", + inspect(prediction.vehicle_location_stop_id), + " vehicle_location_trip_id=", + inspect(prediction.vehicle_location_trip_id) + ]) + end {minutes, approximate?} = case prediction.seconds_until_departure + @terminal_prediction_offset_seconds do From d76733e51099958aec79b81235fb9866ce4cae54 Mon Sep 17 00:00:00 2001 From: Kim Date: Wed, 14 Aug 2024 18:17:19 -0400 Subject: [PATCH 13/26] Add some logging to stops after terminals --- lib/content/message/predictions.ex | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index 98fd25dad..64dbcd265 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -70,6 +70,41 @@ defmodule Content.Message.Predictions 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 + if sign.id in [ + "malden_center_platform", + "green_street_northbound", + "revere_beach_westbound", + "davis_southbound", + "quincy_adams_northbound", + "shawmut_northbound" + ] do + Logger.info([ + "prediction_info: ", + "station_code=", + station_code, + " zone=", + zone, + " trip_id=", + prediction.trip_id, + " stop_id=", + prediction.stop_id, + " vehicle_id=", + inspect(prediction.vehicle_id), + " direction_id=", + inspect(prediction.direction_id), + " seconds_until_departure=", + inspect(prediction.seconds_until_departure), + " boarding_status=", + inspect(prediction.boarding_status), + " vehicle_status=", + inspect(prediction.vehicle_status), + " vehicle_location_stop_id=", + inspect(prediction.vehicle_location_stop_id), + " vehicle_location_trip_id=", + inspect(prediction.vehicle_location_trip_id) + ]) + end + certainty = if prediction.seconds_until_arrival, do: prediction.arrival_certainty, From f7e550f6630e261b8d3f22cc08788eb57070d601 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 19 Aug 2024 16:00:35 -0400 Subject: [PATCH 14/26] Try adding a buffer to account for potential latency between RTR and concentrate --- lib/predictions/predictions.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index 160d55189..8dc4addfd 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -23,7 +23,7 @@ defmodule Predictions.Predictions do |> Enum.reject( &((is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure) and is_nil(&1.seconds_until_passthrough)) or - (&1.seconds_until_departure && &1.seconds_until_departure < 0)) + (&1.seconds_until_departure && &1.seconds_until_departure < -5)) ) vehicles_running_revenue_trips = From 25f59bdd71e680876fe6620586b9a9e70a8ca8f5 Mon Sep 17 00:00:00 2001 From: Kim Date: Tue, 20 Aug 2024 15:39:26 -0400 Subject: [PATCH 15/26] Log more details --- lib/content/message/predictions.ex | 87 ++++++++++++++++-------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index 64dbcd265..9af455a01 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -170,6 +170,46 @@ defmodule Content.Message.Predictions do def terminal(prediction, station_code, zone, sign, width \\ 18) def terminal(prediction, station_code, zone, sign, width) do + {minutes, approximate?} = + case prediction.seconds_until_departure + @terminal_prediction_offset_seconds do + x when x <= @terminal_brd_seconds and prediction.stopped_at_predicted_stop? -> + {:boarding, false} + + x when x <= @terminal_brd_seconds -> + {1, false} + + x -> + compute_minutes(x, prediction.departure_certainty) + end + + terminal_prediction = + case Content.Utilities.destination_for_prediction( + prediction.route_id, + prediction.direction_id, + prediction.destination_stop_id + ) do + {:ok, destination} -> + %__MODULE__{ + destination: destination, + minutes: minutes, + approximate?: approximate?, + route_id: prediction.route_id, + stop_id: prediction.stop_id, + trip_id: prediction.trip_id, + direction_id: prediction.direction_id, + width: width, + new_cars?: sign.location_engine.for_vehicle(prediction.vehicle_id) |> new_cars?(), + station_code: station_code, + zone: zone, + terminal?: true, + certainty: prediction.departure_certainty + } + + {:error, _} -> + Logger.warn("no_destination_for_prediction #{inspect(prediction)}") + nil + end + if prediction.seconds_until_departure + @terminal_prediction_offset_seconds <= @terminal_brd_seconds do Logger.info([ @@ -195,48 +235,17 @@ defmodule Content.Message.Predictions do " vehicle_location_stop_id=", inspect(prediction.vehicle_location_stop_id), " vehicle_location_trip_id=", - inspect(prediction.vehicle_location_trip_id) + inspect(prediction.vehicle_location_trip_id), + " computed_minute=", + inspect(minutes), + " prediction_certainty=", + inspect(prediction.departure_certainty), + " terminal_prediction=", + inspect(terminal_prediction) ]) end - {minutes, approximate?} = - case prediction.seconds_until_departure + @terminal_prediction_offset_seconds do - x when x <= @terminal_brd_seconds and prediction.stopped_at_predicted_stop? -> - {:boarding, false} - - x when x <= @terminal_brd_seconds -> - {1, false} - - x -> - compute_minutes(x, prediction.departure_certainty) - end - - case Content.Utilities.destination_for_prediction( - prediction.route_id, - prediction.direction_id, - prediction.destination_stop_id - ) do - {:ok, destination} -> - %__MODULE__{ - destination: destination, - minutes: minutes, - approximate?: approximate?, - route_id: prediction.route_id, - stop_id: prediction.stop_id, - trip_id: prediction.trip_id, - direction_id: prediction.direction_id, - width: width, - new_cars?: sign.location_engine.for_vehicle(prediction.vehicle_id) |> new_cars?(), - station_code: station_code, - zone: zone, - terminal?: true, - certainty: prediction.departure_certainty - } - - {:error, _} -> - Logger.warn("no_destination_for_prediction #{inspect(prediction)}") - nil - end + terminal_prediction end defp compute_minutes(sec, certainty) do From c3e0837c5d3f9ce36ea6aa6d1f0ef83de8c41e73 Mon Sep 17 00:00:00 2001 From: Kim Date: Tue, 20 Aug 2024 16:51:58 -0400 Subject: [PATCH 16/26] Log stopped_at_predicted_stop --- lib/content/message/predictions.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index 9af455a01..254d79fe3 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -230,6 +230,8 @@ defmodule Content.Message.Predictions do inspect(prediction.seconds_until_departure), " boarding_status=", inspect(prediction.boarding_status), + " stopped_at_predicted_stop=", + inspect(prediction.stopped_at_predicted_stop?), " vehicle_status=", inspect(prediction.vehicle_status), " vehicle_location_stop_id=", From a67c8c320ff89515bc7318b147c0ee4b32314983 Mon Sep 17 00:00:00 2001 From: Kim Date: Wed, 21 Aug 2024 13:56:08 -0400 Subject: [PATCH 17/26] increase buffer to account for negative departures --- lib/predictions/predictions.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index 8dc4addfd..c96148c71 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -23,7 +23,7 @@ defmodule Predictions.Predictions do |> Enum.reject( &((is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure) and is_nil(&1.seconds_until_passthrough)) or - (&1.seconds_until_departure && &1.seconds_until_departure < -5)) + (&1.seconds_until_departure && &1.seconds_until_departure < -10)) ) vehicles_running_revenue_trips = From 7fe2370ab42effe88954b7f270135f1573252cfe Mon Sep 17 00:00:00 2001 From: Kim Date: Wed, 21 Aug 2024 16:02:30 -0400 Subject: [PATCH 18/26] Account for skipped predictions when calculating seconds_until_passthrough --- lib/predictions/predictions.ex | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index c96148c71..d0ebc9e13 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -21,8 +21,7 @@ defmodule Predictions.Predictions do end) |> Stream.map(&prediction_from_update(&1, current_time)) |> Enum.reject( - &((is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure) and - is_nil(&1.seconds_until_passthrough)) or + &((is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure)) or (&1.seconds_until_departure && &1.seconds_until_departure < -10)) ) @@ -68,6 +67,9 @@ defmodule Predictions.Predictions do ) do current_time_seconds = DateTime.to_unix(current_time) + schedule_relationship = + translate_schedule_relationship(stop_time_update["schedule_relationship"]) + seconds_until_arrival = if stop_time_update["arrival"] && sufficient_certainty?(stop_time_update["arrival"], route_id), @@ -81,7 +83,7 @@ defmodule Predictions.Predictions do else: nil seconds_until_passthrough = - if not revenue_trip?, + if not revenue_trip? or schedule_relationship == :skipped, do: seconds_until_arrival || seconds_until_departure, else: nil @@ -102,8 +104,7 @@ defmodule Predictions.Predictions do seconds_until_departure: seconds_until_departure, departure_certainty: stop_time_update["departure"]["uncertainty"], seconds_until_passthrough: max(0, seconds_until_passthrough), - schedule_relationship: - translate_schedule_relationship(stop_time_update["schedule_relationship"]), + schedule_relationship: schedule_relationship, route_id: route_id, trip_id: trip_id, destination_stop_id: last_stop_id, From 135c50a169eb50a6fed1514a8b091531aecec103 Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 22 Aug 2024 14:06:11 -0400 Subject: [PATCH 19/26] Add filter for determining if prediction has passed --- lib/predictions/predictions.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index d0ebc9e13..de070482d 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -22,7 +22,7 @@ defmodule Predictions.Predictions do |> Stream.map(&prediction_from_update(&1, current_time)) |> Enum.reject( &((is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure)) or - (&1.seconds_until_departure && &1.seconds_until_departure < -10)) + has_departed?(&1)) ) vehicles_running_revenue_trips = @@ -163,4 +163,10 @@ defmodule Predictions.Predictions do true end end + + @spec has_departed?(Predictions.Prediction.t()) :: boolean() + defp has_departed?(prediction) do + prediction.seconds_until_departure && prediction.seconds_until_departure < 0 && + not prediction.stopped_at_predicted_stop? + end end From b005b047fc37f04f5042d1478ba2f1fbc0129681 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 26 Aug 2024 15:08:09 -0400 Subject: [PATCH 20/26] Remove extra logging --- lib/content/message/predictions.ex | 72 ------------------------------ lib/predictions/prediction.ex | 10 +---- lib/predictions/predictions.ex | 12 +---- 3 files changed, 3 insertions(+), 91 deletions(-) diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index 254d79fe3..edcd3361e 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -70,41 +70,6 @@ defmodule Content.Message.Predictions 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 - if sign.id in [ - "malden_center_platform", - "green_street_northbound", - "revere_beach_westbound", - "davis_southbound", - "quincy_adams_northbound", - "shawmut_northbound" - ] do - Logger.info([ - "prediction_info: ", - "station_code=", - station_code, - " zone=", - zone, - " trip_id=", - prediction.trip_id, - " stop_id=", - prediction.stop_id, - " vehicle_id=", - inspect(prediction.vehicle_id), - " direction_id=", - inspect(prediction.direction_id), - " seconds_until_departure=", - inspect(prediction.seconds_until_departure), - " boarding_status=", - inspect(prediction.boarding_status), - " vehicle_status=", - inspect(prediction.vehicle_status), - " vehicle_location_stop_id=", - inspect(prediction.vehicle_location_stop_id), - " vehicle_location_trip_id=", - inspect(prediction.vehicle_location_trip_id) - ]) - end - certainty = if prediction.seconds_until_arrival, do: prediction.arrival_certainty, @@ -210,43 +175,6 @@ defmodule Content.Message.Predictions do nil end - if prediction.seconds_until_departure + @terminal_prediction_offset_seconds <= - @terminal_brd_seconds do - Logger.info([ - "prediction_info: ", - "station_code=", - station_code, - " zone=", - zone, - " trip_id=", - prediction.trip_id, - " stop_id=", - prediction.stop_id, - " vehicle_id=", - inspect(prediction.vehicle_id), - " direction_id=", - inspect(prediction.direction_id), - " seconds_until_departure=", - inspect(prediction.seconds_until_departure), - " boarding_status=", - inspect(prediction.boarding_status), - " stopped_at_predicted_stop=", - inspect(prediction.stopped_at_predicted_stop?), - " vehicle_status=", - inspect(prediction.vehicle_status), - " vehicle_location_stop_id=", - inspect(prediction.vehicle_location_stop_id), - " vehicle_location_trip_id=", - inspect(prediction.vehicle_location_trip_id), - " computed_minute=", - inspect(minutes), - " prediction_certainty=", - inspect(prediction.departure_certainty), - " terminal_prediction=", - inspect(terminal_prediction) - ]) - end - terminal_prediction end diff --git a/lib/predictions/prediction.ex b/lib/predictions/prediction.ex index eea617f6b..ee9fe08f3 100644 --- a/lib/predictions/prediction.ex +++ b/lib/predictions/prediction.ex @@ -13,10 +13,7 @@ defmodule Predictions.Prediction do stopped_at_predicted_stop?: false, boarding_status: nil, revenue_trip?: true, - vehicle_id: nil, - vehicle_status: nil, - vehicle_location_stop_id: nil, - vehicle_location_trip_id: nil + vehicle_id: nil @type trip_id :: String.t() @@ -35,9 +32,6 @@ defmodule Predictions.Prediction do stopped_at_predicted_stop?: boolean(), boarding_status: String.t() | nil, revenue_trip?: boolean(), - vehicle_id: String.t() | nil, - vehicle_status: :incoming_at | :stopped_at | :in_transit_to, - vehicle_location_stop_id: String.t(), - vehicle_location_trip_id: String.t() + vehicle_id: String.t() | nil } end diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index de070482d..5727ebcea 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -88,13 +88,6 @@ defmodule Predictions.Predictions do else: nil vehicle_location = Engine.Locations.for_vehicle(vehicle_id) - vehicle_status = if not is_nil(vehicle_location), do: vehicle_location.status, else: "none" - - vehicle_locaton_stop_id = - if not is_nil(vehicle_location), do: vehicle_location.stop_id, else: "none" - - vehicle_location_trip_id = - if not is_nil(vehicle_location), do: vehicle_location.trip_id, else: "none" %Prediction{ stop_id: stop_time_update["stop_id"], @@ -113,10 +106,7 @@ defmodule Predictions.Predictions do stop_time_update["stop_id"] == vehicle_location.stop_id, boarding_status: stop_time_update["boarding_status"], revenue_trip?: revenue_trip?, - vehicle_id: vehicle_id, - vehicle_status: vehicle_status, - vehicle_location_stop_id: vehicle_locaton_stop_id, - vehicle_location_trip_id: vehicle_location_trip_id + vehicle_id: vehicle_id } end From 429bb18511a003e412ad64df3e469bd0b59baa03 Mon Sep 17 00:00:00 2001 From: Kim Date: Fri, 8 Nov 2024 12:48:29 -0500 Subject: [PATCH 21/26] read passthrough_time field directly --- lib/predictions/predictions.ex | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index 5727ebcea..4104d1bec 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -82,10 +82,9 @@ defmodule Predictions.Predictions do do: stop_time_update["departure"]["time"] - current_time_seconds, else: nil - seconds_until_passthrough = - if not revenue_trip? or schedule_relationship == :skipped, - do: seconds_until_arrival || seconds_until_departure, - else: nil + if stop_time_update["passthrough_time"], + do: stop_time_update["passthrough_time"] - current_time_seconds, + else: nil vehicle_location = Engine.Locations.for_vehicle(vehicle_id) From 18ee9ff3831db08f8ef51d2660fea8a120acc8c8 Mon Sep 17 00:00:00 2001 From: Kim Date: Fri, 8 Nov 2024 12:57:37 -0500 Subject: [PATCH 22/26] oops forgot the actual variable --- lib/predictions/predictions.ex | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index 4104d1bec..e6b034390 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -82,9 +82,10 @@ defmodule Predictions.Predictions do do: stop_time_update["departure"]["time"] - current_time_seconds, else: nil - if stop_time_update["passthrough_time"], - do: stop_time_update["passthrough_time"] - current_time_seconds, - else: nil + seconds_until_passthrough = + if stop_time_update["passthrough_time"], + do: stop_time_update["passthrough_time"] - current_time_seconds, + else: nil vehicle_location = Engine.Locations.for_vehicle(vehicle_id) From a4db7387f6253b5d85ffde7589799db515bc5e24 Mon Sep 17 00:00:00 2001 From: Kim Date: Wed, 13 Nov 2024 16:41:51 -0500 Subject: [PATCH 23/26] don't fiter out passthroughs --- lib/predictions/predictions.ex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index e6b034390..30bdca8fd 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -17,11 +17,13 @@ defmodule Predictions.Predictions do |> Stream.flat_map(&transform_stop_time_updates/1) |> Stream.filter(fn {update, _, _, _, _, _, _} -> (update["arrival"] && update["arrival"]["uncertainty"]) || - (update["departure"] && update["departure"]["uncertainty"]) + (update["departure"] && update["departure"]["uncertainty"]) || + update["passthrough_time"] end) |> Stream.map(&prediction_from_update(&1, current_time)) |> Enum.reject( - &((is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure)) or + &((is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure) and + is_nil(&1.passthrough_time)) or has_departed?(&1)) ) From 9ca909be6f39ab6b34e0b3c4674f7ed523039839 Mon Sep 17 00:00:00 2001 From: Kim Date: Wed, 13 Nov 2024 16:42:07 -0500 Subject: [PATCH 24/26] use the right field --- lib/predictions/predictions.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/predictions/predictions.ex b/lib/predictions/predictions.ex index 30bdca8fd..c0560d15d 100644 --- a/lib/predictions/predictions.ex +++ b/lib/predictions/predictions.ex @@ -23,7 +23,7 @@ defmodule Predictions.Predictions do |> Stream.map(&prediction_from_update(&1, current_time)) |> Enum.reject( &((is_nil(&1.seconds_until_arrival) and is_nil(&1.seconds_until_departure) and - is_nil(&1.passthrough_time)) or + is_nil(&1.seconds_until_passthrough)) or has_departed?(&1)) ) From 442d955ad0710439f364328028b3968a626ffef6 Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 14 Nov 2024 14:43:57 -0500 Subject: [PATCH 25/26] remove stops_away --- lib/content/message/predictions.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/content/message/predictions.ex b/lib/content/message/predictions.ex index 23c6e6ecc..1993b15e1 100644 --- a/lib/content/message/predictions.ex +++ b/lib/content/message/predictions.ex @@ -35,12 +35,11 @@ defmodule Content.Message.Predictions do end min = round(sec / 60) - stopped_at? = prediction.stops_away == 0 reverse_prediction? = Signs.Utilities.Predictions.reverse_prediction?(prediction, terminal?) {minutes, approximate?} = cond do - stopped_at? and (!terminal? or sec <= 30) -> {:boarding, false} + prediction.stopped_at_predicted_stop? and (!terminal? or sec <= 30) -> {:boarding, false} !terminal? and sec <= 30 -> {:arriving, false} !terminal? and sec <= 60 -> {:approaching, false} min > 60 -> {60, true} From 79d976d8a6127ede9f9c81e22a44f2cc2f810b3c Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 18 Nov 2024 09:44:56 -0500 Subject: [PATCH 26/26] Remove required concentrate urls from envrc template --- .envrc.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.envrc.template b/.envrc.template index bb29bf3fe..9414c3d7a 100644 --- a/.envrc.template +++ b/.envrc.template @@ -17,6 +17,6 @@ export API_V3_URL=https://api-dev-green.mbtace.com #export CHELSEA_BRIDGE_URL= #export CHELSEA_BRIDGE_AUTH= -# URLs of the enhanced trip-update and vehicle-position feeds. Required. +# URLs of the enhanced trip-update and vehicle-position feeds. #export TRIP_UPDATE_URL="https://s3.amazonaws.com/mbta-gtfs-s3/concentrate/TripUpdates_enhanced.json" #export VEHICLE_POSITIONS_URL="https://s3.amazonaws.com/mbta-gtfs-s3/concentrate/VehiclePositions_enhanced.json"