Skip to content

Commit

Permalink
fix: support separate alert status for top/bottom
Browse files Browse the repository at this point in the history
different alert status per top/bottom config are needed to support
showing an alert status based message on a single source config. this is
most common when top and bottom source configs are for different
lines/routes.

previously the alert_status for a sign was reduced down to a single
value which could cause weird behavior when an alert was only effecting
one of the two source configs.
  • Loading branch information
sloanelybutsurely committed Jul 17, 2024
1 parent 9f26a22 commit 7e22344
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
37 changes: 32 additions & 5 deletions lib/signs/realtime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,27 @@ defmodule Signs.Realtime do
end

def handle_info(:run_loop, sign) do
sign_stop_ids = SourceConfig.sign_stop_ids(sign.source_config)
sign_routes = SourceConfig.sign_routes(sign.source_config)
alert_status = sign.alerts_engine.max_stop_status(sign_stop_ids, sign_routes)
sign_config = sign.config_engine.sign_config(sign.id)
current_time = sign.current_time_fn.()

alert_status =
case sign.source_config do
{top, bottom} ->
top_alert_status = get_alert_status_for_source_config(top, sign.alerts_engine)
bottom_alert_status = get_alert_status_for_source_config(bottom, sign.alerts_engine)

{top_alert_status, bottom_alert_status}

source_config ->
alert_status = get_alert_status_for_source_config(source_config, sign.alerts_engine)

alert_status
end
|> then(fn
{alert_status, alert_status} -> alert_status
alert_status -> alert_status
end)

first_scheduled_departures =
case sign.source_config do
{top, bottom} ->
Expand All @@ -160,8 +175,12 @@ defmodule Signs.Realtime do
}

source ->
{sign.headway_engine.get_first_scheduled_departure(sign_stop_ids),
source.headway_destination}
{
source
|> SourceConfig.sign_stop_ids()
|> sign.headway_engine.get_first_scheduled_departure(),
source.headway_destination
}
end

prev_predictions_lookup =
Expand Down Expand Up @@ -286,4 +305,12 @@ defmodule Signs.Realtime do
def decrement_ticks(sign) do
%{sign | tick_read: sign.tick_read - 1}
end

defp get_alert_status_for_source_config(config, alerts_engine) do
stop_ids = SourceConfig.sign_stop_ids(config)
routes = SourceConfig.sign_routes(config)
alert_status = alerts_engine.max_stop_status(stop_ids, routes)

alert_status
end
end
34 changes: 31 additions & 3 deletions lib/signs/utilities/messages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,41 @@ defmodule Signs.Utilities.Messages do
:top | :bottom
) :: Signs.Realtime.line_content()
defp get_paging_headway_or_alert_messages(
%Signs.Realtime{source_config: {top, bottom}} = sign,
%Signs.Realtime{source_config: {config, _bottom}} = sign,
current_time,
{alert_status, _},
:top
) do
get_paging_alert_message(alert_status, sign.uses_shuttles, config.headway_destination) ||
Signs.Utilities.Headways.get_paging_message(sign, config, current_time)
end

defp get_paging_headway_or_alert_messages(
%Signs.Realtime{source_config: {_top, config}} = sign,
current_time,
{_, alert_status},
:bottom
) do
get_paging_alert_message(alert_status, sign.uses_shuttles, config.headway_destination) ||
Signs.Utilities.Headways.get_paging_message(sign, config, current_time)
end

defp get_paging_headway_or_alert_messages(
%Signs.Realtime{source_config: {config, _bottom}} = sign,
current_time,
alert_status,
line
:top
) do
config = if(line == :top, do: top, else: bottom)
get_paging_alert_message(alert_status, sign.uses_shuttles, config.headway_destination) ||
Signs.Utilities.Headways.get_paging_message(sign, config, current_time)
end

defp get_paging_headway_or_alert_messages(
%Signs.Realtime{source_config: {_top, config}} = sign,
current_time,
alert_status,
:bottom
) do
get_paging_alert_message(alert_status, sign.uses_shuttles, config.headway_destination) ||
Signs.Utilities.Headways.get_paging_message(sign, config, current_time)
end
Expand Down

0 comments on commit 7e22344

Please sign in to comment.