Skip to content

Commit

Permalink
fix: Crowding App alert logic (#2043)
Browse files Browse the repository at this point in the history
* Only look at active alerts.

* Use static now reference.

* Fix test.
  • Loading branch information
cmaddox5 authored May 9, 2024
1 parent f6232cf commit e564287
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/screens/v2/candidate_generator/widgets/train_crowding.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.TrainCrowding do
}

get_instance(
any_alert_makes_this_a_terminal?(alerts, location_context),
any_alert_makes_this_a_terminal?(alerts, location_context, now),
common_params
)
else
Expand Down Expand Up @@ -301,9 +301,11 @@ defmodule Screens.V2.CandidateGenerator.Widgets.TrainCrowding do
end

# Given alerts at this station, check to see if any alert make this a temporary terminal
defp any_alert_makes_this_a_terminal?(alerts, location_context) do
defp any_alert_makes_this_a_terminal?(alerts, location_context, now) do
Enum.any?(alerts, fn alert ->
temporary_terminal?(%{alert: alert, location_context: location_context})
if Alert.happening_now?(alert, now) do
temporary_terminal?(%{alert: alert, location_context: location_context})
end
end)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ defmodule Screens.V2.CandidateGenerator.Widgets.TrainCrowdingTest do
app_id: :triptych_v2
}

now = ~U[2023-08-16 21:04:00Z]

next_train_prediction =
struct(Prediction, %{
vehicle:
Expand Down Expand Up @@ -135,7 +137,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.TrainCrowdingTest do
%{direction_id: nil, route: "Orange", route_type: 1, stop: "place-state"},
%{direction_id: nil, route: "Orange", route_type: 1, stop: "place-tumnl"}
],
active_period: [{~U[2023-08-16 20:04:00Z], ~U[2023-08-16 22:04:06Z]}],
active_period: [{DateTime.add(now, -1, :hour), DateTime.add(now, 2, :hour)}],
lifecycle: "NEW",
timeframe: nil,
created_at: ~U[2023-08-16 20:04:02Z],
Expand All @@ -149,7 +151,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.TrainCrowdingTest do
%{
config: config,
logging_options: %{is_real_screen: false, screen_id: "TEST", triptych_pane: nil},
now: ~U[2023-08-16 21:04:00Z],
now: now,
next_train_prediction: next_train_prediction,
fetch_predictions_fn: fn _ -> {:ok, [next_train_prediction]} end,
fetch_location_context_fn: fn _, _, _ -> {:ok, location_context} end,
Expand Down

0 comments on commit e564287

Please sign in to comment.