Skip to content

Commit

Permalink
move platform config out of signs.json (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
panentheos authored Oct 25, 2024
1 parent dee82d6 commit a38c463
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 403 deletions.
2 changes: 1 addition & 1 deletion lib/content/audio/approaching.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule Content.Audio.Approaching do
%__MODULE__{
destination: message.destination,
trip_id: message.trip_id,
platform: message.platform,
platform: Content.Utilities.stop_platform(message.stop_id),
route_id: message.route_id,
new_cars?: message.new_cars?,
crowding_description: if(include_crowding?, do: message.crowding_description)
Expand Down
2 changes: 1 addition & 1 deletion lib/content/audio/next_train_countdown.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule Content.Audio.NextTrainCountdown do
minutes: if(message.minutes == :approaching, do: 1, else: message.minutes),
verb: if(message.terminal?, do: :departs, else: :arrives),
track_number: Content.Utilities.stop_track_number(message.stop_id),
platform: message.platform,
platform: Content.Utilities.stop_platform(message.stop_id),
station_code: message.station_code,
zone: message.zone
}
Expand Down
2 changes: 1 addition & 1 deletion lib/content/audio/train_is_arriving.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Content.Audio.TrainIsArriving do
%__MODULE__{
destination: message.destination,
trip_id: message.trip_id,
platform: message.platform,
platform: Content.Utilities.stop_platform(message.stop_id),
route_id: message.route_id,
crowding_description: if(include_crowding?, do: message.crowding_description)
}
Expand Down
8 changes: 2 additions & 6 deletions lib/content/message/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ defmodule Content.Message.Predictions do
:direction_id,
:zone,
width: 18,
platform: nil,
new_cars?: false,
terminal?: false,
certainty: nil,
Expand All @@ -49,7 +48,6 @@ defmodule Content.Message.Predictions do
new_cars?: boolean(),
station_code: String.t() | nil,
zone: String.t() | nil,
platform: Content.platform() | nil,
terminal?: boolean(),
certainty: non_neg_integer() | nil,
crowding_data_confidence: :high | :low | nil,
Expand All @@ -61,12 +59,11 @@ defmodule Content.Message.Predictions do
String.t(),
String.t(),
Signs.Realtime.t(),
Content.platform() | nil,
integer()
) :: t() | nil
def non_terminal(prediction, station_code, zone, sign, platform \\ nil, width \\ 18)
def non_terminal(prediction, station_code, zone, sign, width \\ 18)

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

Expand Down Expand Up @@ -100,7 +97,6 @@ defmodule Content.Message.Predictions do
new_cars?: sign.location_engine.for_vehicle(prediction.vehicle_id) |> new_cars?(),
station_code: station_code,
zone: zone,
platform: platform,
certainty: certainty,
crowding_data_confidence: crowding_data_confidence,
crowding_description: crowding_description
Expand Down
5 changes: 5 additions & 0 deletions lib/content/utilities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ defmodule Content.Utilities do
def stop_track_number("Union Square-02"), do: 2
def stop_track_number(_), do: nil

@spec stop_platform(String.t()) :: Content.platform() | nil
def stop_platform("70086"), do: :ashmont
def stop_platform("70096"), do: :braintree
def stop_platform(_), do: nil

def stop_platform_name("70086"), do: "Ashmont"
def stop_platform_name("70096"), do: "Braintree"

Expand Down
20 changes: 1 addition & 19 deletions lib/signs/utilities/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ defmodule Signs.Utilities.Predictions do
Content.Message.Predictions.terminal(prediction, station_code, zone, sign)

true ->
Content.Message.Predictions.non_terminal(
prediction,
station_code,
zone,
sign,
platform(prediction, sources)
)
Content.Message.Predictions.non_terminal(prediction, station_code, zone, sign)
end
end)
|> Enum.reject(&is_nil(&1))
Expand Down Expand Up @@ -201,18 +195,6 @@ defmodule Signs.Utilities.Predictions do
false
end

defp platform(prediction, source_list) do
source_list
|> SourceConfig.get_source_by_stop_and_direction(
prediction.stop_id,
prediction.direction_id
)
|> case do
nil -> nil
source -> source.platform
end
end

# This is a temporary fix for a situation where spotty train sheet data can
# cause some predictions to not show up until right before they leave the
# terminal. This makes it appear that the next train will be much later than
Expand Down
14 changes: 0 additions & 14 deletions lib/signs/utilities/source_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,13 @@ defmodule Signs.Utilities.SourceConfig do
"routes": ["Orange"],
"direction_id": 0,
"headway_direction_name": "Forest Hills",
"platform": null,
"announce_arriving": true,
"announce_boarding": false
}
* stop_id: The GTFS stop_id that it uses for prediction data.
* routes: A list of routes that are relevant to this sign regarding alerts.
* direction_id: 0 or 1, used in tandem with the stop ID for predictions
* platform: mostly null, but :ashmont | :braintree for JFK/UMass, where it's used for the "next
train to X is approaching, on the Y platform" audio.
* announce_arriving: whether to play audio when a sign goes to ARR.
* announce_boarding: whether to play audio when a sign goes to BRD. Generally we do one or the
other. Considerations include how noisy the station is, what we've done in the past, how
Expand All @@ -96,7 +93,6 @@ defmodule Signs.Utilities.SourceConfig do
:stop_id,
:direction_id,
:routes,
:platform,
:announce_arriving?,
:announce_boarding?
]
Expand All @@ -108,7 +104,6 @@ defmodule Signs.Utilities.SourceConfig do
headway_stop_id: String.t() | nil,
direction_id: 0 | 1,
routes: [String.t()] | nil,
platform: Content.platform() | nil,
announce_arriving?: boolean(),
announce_boarding?: boolean(),
multi_berth?: boolean()
Expand Down Expand Up @@ -146,18 +141,10 @@ defmodule Signs.Utilities.SourceConfig do
%{
"stop_id" => stop_id,
"direction_id" => direction_id,
"platform" => platform,
"announce_arriving" => announce_arriving?,
"announce_boarding" => announce_boarding?
} = source
) do
platform =
case platform do
nil -> nil
"ashmont" -> :ashmont
"braintree" -> :braintree
end

multi_berth? =
case source["multi_berth"] do
true -> true
Expand All @@ -168,7 +155,6 @@ defmodule Signs.Utilities.SourceConfig do
stop_id: stop_id,
direction_id: direction_id,
routes: source["routes"],
platform: platform,
announce_arriving?: announce_arriving?,
announce_boarding?: announce_boarding?,
multi_berth?: multi_berth?
Expand Down
Loading

0 comments on commit a38c463

Please sign in to comment.