Skip to content

Commit

Permalink
cleanup: Use Routes.Route.id_t() instead of String.t()
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlarson committed Feb 5, 2025
1 parent c00f06a commit d5960a6
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/dotcom/system_status/subway.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ defmodule Dotcom.SystemStatus.Subway do
time: status_time()
}

@type status_entry_group() :: %{branch_ids: [String.t()], status_entries: [status_entry()]}
@type status_entry_group() :: %{
branch_ids: [Routes.Route.id_t()],
status_entries: [status_entry()]
}

@lines ["Blue", "Green", "Orange", "Red"]
@green_line_branches ["Green-B", "Green-C", "Green-D", "Green-E"]
Expand Down Expand Up @@ -119,7 +122,7 @@ defmodule Dotcom.SystemStatus.Subway do
"Green" => [%{branch_ids: [], status_entries: [%{time: :current, status: :normal, multiple: false}]}]
}
"""
@spec subway_status([Alert.t()], DateTime.t()) :: %{String.t() => status_entry_group()}
@spec subway_status([Alert.t()], DateTime.t()) :: %{Routes.Route.id_t() => status_entry_group()}
def subway_status(alerts, time) do
@lines
|> Map.new(fn line ->
Expand All @@ -140,8 +143,8 @@ defmodule Dotcom.SystemStatus.Subway do
#
# The exact implementation depends on which line. Green and Red have
# branches, so they have special implementations.
@spec add_nested_statuses_for_line(String.t(), [Alert.t()], DateTime.t()) :: %{
route_id: String.t(),
@spec add_nested_statuses_for_line(Routes.Route.id_t(), [Alert.t()], DateTime.t()) :: %{
route_id: Routes.Route.id_t(),
branches_with_statuses: [status_entry_group()]
}
defp add_nested_statuses_for_line(line_id, alerts, time)
Expand Down Expand Up @@ -235,7 +238,9 @@ defmodule Dotcom.SystemStatus.Subway do

# Returns a list containing a single status entry group corresponding
# to the alerts for the given route.
@spec branches_with_statuses(String.t(), [Alert.t()], DateTime.t()) :: [status_entry_group()]
@spec branches_with_statuses(Routes.Route.id_t(), [Alert.t()], DateTime.t()) :: [
status_entry_group()
]
defp branches_with_statuses(route_id, alerts, time) do
route_id
|> statuses_for_route(alerts, time)
Expand Down Expand Up @@ -264,8 +269,8 @@ defmodule Dotcom.SystemStatus.Subway do
# Exchanges a route_id (a line_id or a branch_id - anything that
# might correspond to an alert) for a map with that route_id and the
# statuses affecting that route.
@spec add_statuses_for_route(String.t(), [Alert.t()], DateTime.t()) :: %{
route_id: String.t(),
@spec add_statuses_for_route(Routes.Route.id_t(), [Alert.t()], DateTime.t()) :: %{
route_id: Routes.Route.id_t(),
statuses: [status_entry()]
}
defp add_statuses_for_route(route_id, alerts, time) do
Expand All @@ -277,7 +282,7 @@ defmodule Dotcom.SystemStatus.Subway do

# Returns a list of statuses corresponding to the alerts for the
# given route.
@spec statuses_for_route(String.t(), [Alert.t()], DateTime.t()) :: [status_entry()]
@spec statuses_for_route(Routes.Route.id_t(), [Alert.t()], DateTime.t()) :: [status_entry()]
defp statuses_for_route(route_id, alerts, time) do
route_id
|> alerts_for_route(alerts)
Expand All @@ -287,7 +292,8 @@ defmodule Dotcom.SystemStatus.Subway do
# Returns a branch_with_status entry, to be used in the
# branches_with_statuses field in groups/2. If no branch_ids are
# provided, then uses an empty array.
@spec branch_with_statuses_entry([status_entry()], [String.t()]) :: status_entry_group()
@spec branch_with_statuses_entry([status_entry()], [Routes.Route.id_t()]) ::
status_entry_group()
defp branch_with_statuses_entry(statuses, branch_ids \\ []) do
%{
branch_ids: branch_ids,
Expand All @@ -298,7 +304,7 @@ defmodule Dotcom.SystemStatus.Subway do
# Given `alerts` and `route_id`, filters out only the alerts
# applicable to the given route, using the alert's "informed
# entities".
@spec alerts_for_route(String.t(), [Alert.t()]) :: [Alert.t()]
@spec alerts_for_route(Routes.Route.id_t(), [Alert.t()]) :: [Alert.t()]
defp alerts_for_route(route_id, alerts) do
alerts
|> Enum.filter(fn %Alert{informed_entity: informed_entity} ->
Expand Down

0 comments on commit d5960a6

Please sign in to comment.