Skip to content

Commit

Permalink
test prediction and headway logic at the sign level (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
panentheos authored Aug 17, 2023
1 parent 9a7db1c commit 237b53c
Show file tree
Hide file tree
Showing 6 changed files with 526 additions and 974 deletions.
9 changes: 5 additions & 4 deletions lib/engine/scheduled_headways.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Engine.ScheduledHeadways do
Initially we will quickly update any newly registered stop so that we have something to show,
then over time we will update every stop once every hour to make sure we stay up to date.
"""
@behaviour Engine.ScheduledHeadwaysAPI
use GenServer
require Logger
require Signs.Utilities.SignsConfig
Expand Down Expand Up @@ -34,7 +35,7 @@ defmodule Engine.ScheduledHeadways do
)
end

@spec init(Keyword.t()) :: {:ok, state()}
@impl true
def init(opts) do
headways_ets_table = opts[:headways_ets_table] || :scheduled_headways

Expand Down Expand Up @@ -95,7 +96,7 @@ defmodule Engine.ScheduledHeadways do
:ets.select(table_name, pattern)
end

@spec get_first_scheduled_departure([binary]) :: nil | DateTime.t()
@impl true
def get_first_scheduled_departure(stop_ids) do
get_first_last_departures(stop_ids)
|> Enum.map(&elem(&1, 0))
Expand All @@ -105,7 +106,7 @@ defmodule Engine.ScheduledHeadways do
@doc "Checks if the given time is after the first scheduled stop and before the last.
A buffer of minutes (positive) is subtracted from the first time. so that headways are
shown for a short time before the first train."
@spec display_headways?(:ets.tab(), [String.t()], DateTime.t(), non_neg_integer()) :: boolean()
@impl true
def display_headways?(
table \\ :scheduled_headways_first_last_departures,
stop_ids,
Expand Down Expand Up @@ -146,7 +147,7 @@ defmodule Engine.ScheduledHeadways do
|> Enum.min_by(&DateTime.to_unix/1, fn -> nil end)
end

@spec handle_info(:data_update, state) :: {:noreply, state}
@impl true
def handle_info(:data_update, state) do
schedule_data_update(self(), state.fetch_ms)

Expand Down
4 changes: 4 additions & 0 deletions lib/engine/scheduled_headways_api.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defmodule Engine.ScheduledHeadwaysAPI do
@callback display_headways?([String.t()], DateTime.t(), non_neg_integer()) :: boolean()
@callback get_first_scheduled_departure([binary]) :: nil | DateTime.t()
end
Loading

0 comments on commit 237b53c

Please sign in to comment.