From 7e22344a8ba184a40e90b318c6aa8ac7f5d8a08a Mon Sep 17 00:00:00 2001 From: sloane <1699281+sloanelybutsurely@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:37:46 -0400 Subject: [PATCH] fix: support separate alert status for top/bottom 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. --- lib/signs/realtime.ex | 37 ++++++++++++++++++++++++++++----- lib/signs/utilities/messages.ex | 34 +++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/lib/signs/realtime.ex b/lib/signs/realtime.ex index 0afb2c5af..5b96e5ec0 100644 --- a/lib/signs/realtime.ex +++ b/lib/signs/realtime.ex @@ -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} -> @@ -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 = @@ -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 diff --git a/lib/signs/utilities/messages.ex b/lib/signs/utilities/messages.ex index 9fb52f1e6..40b961f5c 100644 --- a/lib/signs/utilities/messages.ex +++ b/lib/signs/utilities/messages.ex @@ -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