Skip to content

Commit

Permalink
feat: replace case with SourceConfig.map in realtime run_loop
Browse files Browse the repository at this point in the history
Replaces other instances of `case` clauses to match out source config
values and map over the results in the `:run_loop` of `Signs.Realtime`
  • Loading branch information
sloanelybutsurely committed Jul 22, 2024
1 parent 7dc83b0 commit e3d9b5c
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions lib/signs/realtime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,13 @@ defmodule Signs.Realtime do
|> SourceConfig.simplify()

first_scheduled_departures =
case sign.source_config do
{top, bottom} ->
{
{sign.headway_engine.get_first_scheduled_departure(SourceConfig.sign_stop_ids(top)),
top.headway_destination},
{sign.headway_engine.get_first_scheduled_departure(
SourceConfig.sign_stop_ids(bottom)
), bottom.headway_destination}
}

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

prev_predictions_lookup =
for prediction <- sign.prev_predictions, into: %{} do
Expand All @@ -185,14 +177,7 @@ defmodule Signs.Realtime do
end

service_end_statuses_per_source =
case sign.source_config do
{top_source, bottom_source} ->
{has_service_ended_for_source?(sign, top_source, current_time),
has_service_ended_for_source?(sign, bottom_source, current_time)}

source ->
has_service_ended_for_source?(sign, source, current_time)
end
SourceConfig.map(sign.source_config, &has_service_ended_for_source?(sign, &1, current_time))

{new_top, new_bottom} =
Utilities.Messages.get_messages(
Expand Down

0 comments on commit e3d9b5c

Please sign in to comment.