Skip to content

Commit

Permalink
don't modify predictions when both lines ARR (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
panentheos authored Oct 28, 2024
1 parent 697c2eb commit b26f990
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 109 deletions.
39 changes: 1 addition & 38 deletions lib/signs/utilities/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Signs.Utilities.Predictions do
) :: Signs.Realtime.sign_messages() | nil
def prediction_messages(
predictions,
%{sources: sources, terminal?: terminal?},
%{terminal?: terminal?},
%{pa_ess_loc: station_code, text_zone: zone} = sign
) do
predictions
Expand Down Expand Up @@ -69,16 +69,6 @@ defmodule Signs.Utilities.Predictions do
[msg] ->
{msg, Content.Message.Empty.new()}

[
%Content.Message.Predictions{minutes: :arriving} = p1,
%Content.Message.Predictions{minutes: :arriving} = p2
] ->
if allowed_multi_berth_platform?(sources, p1, p2) do
{p1, p2}
else
{p1, %{p2 | minutes: 1}}
end

[msg1, msg2] ->
{msg1, msg2}
end
Expand Down Expand Up @@ -168,33 +158,6 @@ defmodule Signs.Utilities.Predictions do
boarding_status != "Stopped at station" && !approximate_arrival? && !approximate_departure?
end

defp allowed_multi_berth_platform?(source_list, p1, p2) do
allowed_multi_berth_platform?(
SourceConfig.get_source_by_stop_and_direction(
source_list,
p1.stop_id,
p1.direction_id
),
SourceConfig.get_source_by_stop_and_direction(
source_list,
p2.stop_id,
p2.direction_id
)
)
end

defp allowed_multi_berth_platform?(
%SourceConfig{multi_berth?: true} = s1,
%SourceConfig{multi_berth?: true} = s2
)
when s1 != s2 do
true
end

defp allowed_multi_berth_platform?(_, _) do
false
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
15 changes: 3 additions & 12 deletions lib/signs/utilities/source_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,15 @@ defmodule Signs.Utilities.SourceConfig do
:announce_arriving?,
:announce_boarding?
]
defstruct @enforce_keys ++
[:headway_stop_id, multi_berth?: false]
defstruct @enforce_keys ++ [:headway_stop_id]

@type source :: %__MODULE__{
stop_id: String.t(),
headway_stop_id: String.t() | nil,
direction_id: 0 | 1,
routes: [String.t()] | nil,
announce_arriving?: boolean(),
announce_boarding?: boolean(),
multi_berth?: boolean()
announce_boarding?: boolean()
}

@type config :: %{
Expand Down Expand Up @@ -145,19 +143,12 @@ defmodule Signs.Utilities.SourceConfig do
"announce_boarding" => announce_boarding?
} = source
) do
multi_berth? =
case source["multi_berth"] do
true -> true
_ -> false
end

%__MODULE__{
stop_id: stop_id,
direction_id: direction_id,
routes: source["routes"],
announce_arriving?: announce_arriving?,
announce_boarding?: announce_boarding?,
multi_berth?: multi_berth?
announce_boarding?: announce_boarding?
}
end

Expand Down
14 changes: 5 additions & 9 deletions priv/signs.json
Original file line number Diff line number Diff line change
Expand Up @@ -7111,8 +7111,7 @@
"Green-D"
],
"announce_arriving": false,
"announce_boarding": true,
"multi_berth": true
"announce_boarding": true
},
{
"stop_id": "70199",
Expand All @@ -7121,8 +7120,7 @@
"Green-E"
],
"announce_arriving": false,
"announce_boarding": true,
"multi_berth": true
"announce_boarding": true
}
]
}
Expand All @@ -7149,8 +7147,7 @@
"Green-B"
],
"announce_arriving": false,
"announce_boarding": true,
"multi_berth": true
"announce_boarding": true
},
{
"stop_id": "70197",
Expand All @@ -7159,8 +7156,7 @@
"Green-C"
],
"announce_arriving": false,
"announce_boarding": true,
"multi_berth": true
"announce_boarding": true
}
]
}
Expand Down Expand Up @@ -9748,4 +9744,4 @@
],
"max_minutes": 75
}
]
]
40 changes: 2 additions & 38 deletions test/signs/realtime_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -540,15 +540,15 @@ defmodule Signs.RealtimeTest do
Signs.Realtime.handle_info(:run_loop, @sign)
end

test "does not allow ARR on second line if platform does not have multiple berths" do
test "allows ARR on second line" do
expect(Engine.Predictions.Mock, :for_stop, fn _, _ ->
[
prediction(destination: :cleveland_circle, arrival: 15, stop_id: "1"),
prediction(destination: :riverside, arrival: 16, stop_id: "1")
]
end)

expect_messages({"Clvlnd Cir ARR", "Riverside 1 min"})
expect_messages({"Clvlnd Cir ARR", "Riverside ARR"})

expect_audios([{:canned, {"103", ["90007"], :audio_visual}}], [
{"Attention passengers: The next C train to Cleveland Circle is now arriving.",
Expand All @@ -558,42 +558,6 @@ defmodule Signs.RealtimeTest do
Signs.Realtime.handle_info(:run_loop, @sign)
end

test "allows ARR on second line if platform does have multiple berths" do
expect(Engine.Predictions.Mock, :for_stop, fn _, _ ->
[prediction(destination: :cleveland_circle, arrival: 15, stop_id: "1", trip_id: "1")]
end)

expect(Engine.Predictions.Mock, :for_stop, fn _, _ ->
[prediction(destination: :riverside, arrival: 16, stop_id: "2", trip_id: "2")]
end)

expect_messages({"Clvlnd Cir ARR", "Riverside ARR"})

expect_audios(
[
{:canned, {"103", ["90007"], :audio_visual}},
{:canned, {"103", ["90008"], :audio_visual}}
],
[
{"Attention passengers: The next C train to Cleveland Circle is now arriving.",
[{"C train to Clvlnd Cir", "now arriving", 6}]},
{"Attention passengers: The next D train to Riverside is now arriving.",
[{"D train to Riverside", "now arriving", 6}]}
]
)

Signs.Realtime.handle_info(:run_loop, %{
@sign
| source_config: %{
@sign.source_config
| sources: [
%{@src | stop_id: "1", multi_berth?: true},
%{@src | stop_id: "2", multi_berth?: true}
]
}
})
end

test "doesn't sort 0 stops away to first for terminals when another departure is sooner" do
expect(Engine.Predictions.Mock, :for_stop, fn _, _ ->
[
Expand Down
18 changes: 6 additions & 12 deletions test/signs/utilities/source_config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ defmodule Signs.Utilities.SourceConfigTest do
"routes": ["Bar"],
"direction_id": 1,
"announce_arriving": true,
"announce_boarding": false,
"multi_berth": true
"announce_boarding": false
}
]
}
Expand Down Expand Up @@ -80,8 +79,7 @@ defmodule Signs.Utilities.SourceConfigTest do
"routes": ["Bar"],
"direction_id": 1,
"announce_arriving": true,
"announce_boarding": false,
"multi_berth": true
"announce_boarding": false
}
]
}
Expand All @@ -100,16 +98,14 @@ defmodule Signs.Utilities.SourceConfigTest do
routes: ["Foo"],
direction_id: 0,
announce_arriving?: false,
announce_boarding?: false,
multi_berth?: false
announce_boarding?: false
},
%SourceConfig{
stop_id: "234",
routes: ["Bar"],
direction_id: 1,
announce_arriving?: true,
announce_boarding?: false,
multi_berth?: true
announce_boarding?: false
}
]
}
Expand Down Expand Up @@ -162,16 +158,14 @@ defmodule Signs.Utilities.SourceConfigTest do
routes: ["Foo"],
direction_id: 0,
announce_arriving?: false,
announce_boarding?: false,
multi_berth?: false
announce_boarding?: false
},
%SourceConfig{
stop_id: "234",
routes: ["Bar"],
direction_id: 1,
announce_arriving?: true,
announce_boarding?: false,
multi_berth?: true
announce_boarding?: false
}
]
}
Expand Down

0 comments on commit b26f990

Please sign in to comment.