Skip to content

Commit

Permalink
refactor: Rename Groups.groups/2 to Subway.subway_status/2
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlarson committed Jan 29, 2025
1 parent 4d045d8 commit d8c8f53
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
7 changes: 7 additions & 0 deletions lib/dotcom/system_status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ defmodule Dotcom.SystemStatus do
|> SystemStatus.Alerts.for_day(datetime)
|> SystemStatus.Alerts.filter_relevant()
end

@doc """
Returns a map indicating the subway status for each of the subway lines.
"""
def subway_status() do
subway_alerts_for_today() |> SystemStatus.Subway.subway_status(Timex.now())
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Dotcom.SystemStatus.Groups do
defmodule Dotcom.SystemStatus.Subway do
@moduledoc """
A module that groups alerts into statuses for the system status
Expand All @@ -22,7 +22,7 @@ defmodule Dotcom.SystemStatus.Groups do
screen. See `Dotcom.SystemStatus` for more details.
## Example (no alerts)
iex> Dotcom.SystemStatus.Groups.groups([], Timex.now())
iex> Dotcom.SystemStatus.Subway.subway_status([], Timex.now())
%{
"Blue" => [%{branch_ids: [], status_entries: [%{time: :current, status: :normal, multiple: false}]}],
"Orange" => [%{branch_ids: [], status_entries: [%{time: :current, status: :normal, multiple: false}]}],
Expand All @@ -39,7 +39,7 @@ defmodule Dotcom.SystemStatus.Groups do
...> active_period: [{Timex.beginning_of_day(Timex.now()), nil}]
...> }
...> ]
iex> Dotcom.SystemStatus.Groups.groups(alerts, Timex.now())
iex> Dotcom.SystemStatus.Subway.subway_status(alerts, Timex.now())
%{
"Blue" => [%{branch_ids: [], status_entries: [%{time: :current, status: :normal, multiple: false}]}],
"Orange" => [
Expand Down Expand Up @@ -74,7 +74,7 @@ defmodule Dotcom.SystemStatus.Groups do
...> active_period: [{Timex.beginning_of_day(Timex.now()), nil}]
...> }
...> ]
iex> Dotcom.SystemStatus.Groups.groups(alerts, Timex.now())
iex> Dotcom.SystemStatus.Subway.subway_status(alerts, Timex.now())
%{
"Blue" => [%{branch_ids: [], status_entries: [%{time: :current, status: :normal, multiple: false}]}],
"Orange" => [%{branch_ids: [], status_entries: [%{time: :current, status: :normal, multiple: false}]}],
Expand Down Expand Up @@ -107,7 +107,7 @@ defmodule Dotcom.SystemStatus.Groups do
...> active_period: [{Timex.beginning_of_day(Timex.now()), nil}]
...> }
...> ]
iex> Dotcom.SystemStatus.Groups.groups(alerts, Timex.now())
iex> Dotcom.SystemStatus.Subway.subway_status(alerts, Timex.now())
%{
"Blue" => [%{branch_ids: [], status_entries: [%{time: :current, status: :normal, multiple: false}]}],
"Orange" => [%{branch_ids: [], status_entries: [%{time: :current, status: :normal, multiple: false}]}],
Expand All @@ -129,7 +129,7 @@ defmodule Dotcom.SystemStatus.Groups do
}
"""
def groups(alerts, time) do
def subway_status(alerts, time) do
@lines
|> Map.new(fn line ->
%{route_id: route_id, branches_with_statuses: branches_with_statuses} =
Expand Down
4 changes: 2 additions & 2 deletions lib/dotcom_web/live/system_status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ defmodule DotcomWeb.Live.SystemStatus do
use DotcomWeb, :live_view

alias Dotcom.SystemStatus
alias Dotcom.SystemStatus.Groups

def render(assigns) do
alerts = SystemStatus.subway_alerts_for_today()
statuses = Groups.groups(alerts, Timex.now())

statuses = SystemStatus.subway_status()

assigns =
assigns
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule Dotcom.SystemStatus.GroupsTest do
defmodule Dotcom.SystemStatus.SubwayTest do
use ExUnit.Case, async: true
doctest Dotcom.SystemStatus.Groups
doctest Dotcom.SystemStatus.Subway

alias Dotcom.SystemStatus.Groups
alias Dotcom.SystemStatus.Subway
alias Test.Support.Factories.Alerts.Alert
alias Test.Support.Factories.Alerts.InformedEntity
alias Test.Support.Factories.Alerts.InformedEntitySet
Expand All @@ -16,7 +16,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
describe "heavy rail groups" do
test "when there are no alerts, lists each line as normal" do
# Exercise
groups = Groups.groups([], time_today())
groups = Subway.subway_status([], time_today())

# Verify
@all_rail_lines
Expand All @@ -36,7 +36,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
alerts = [current_alert(route_id: affected_route_id, time: time, effect: effect)]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
[status] =
Expand All @@ -55,7 +55,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
alerts = [current_alert(route_id: affected_route_id, time: time, effect: effect)]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
[multiple] =
Expand All @@ -73,7 +73,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
alerts = [current_alert(route_id: affected_route_id, time: time)]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
times =
Expand All @@ -92,7 +92,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
alerts = [current_alert(route_id: affected_route_id, time: time)]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
@heavy_rail_lines
Expand All @@ -117,7 +117,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
alerts = [future_alert(route_id: affected_route_id, start_time: alert_start_time)]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
times =
Expand Down Expand Up @@ -145,7 +145,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
statuses =
Expand Down Expand Up @@ -178,7 +178,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
times =
Expand Down Expand Up @@ -206,7 +206,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
statuses =
Expand All @@ -231,7 +231,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
times =
Expand All @@ -256,7 +256,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
multiples =
Expand All @@ -282,7 +282,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
multiples =
Expand All @@ -308,7 +308,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
end)

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
statuses =
Expand All @@ -329,7 +329,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
alerts = [current_alert(route_id: affected_branch_id, effect: effect, time: time)]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
statuses =
Expand All @@ -350,7 +350,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
alerts = [current_alert(route_id: affected_branch_id, effect: effect, time: time)]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
normal_branch_ids = @green_line_branches |> List.delete(affected_branch_id)
Expand All @@ -373,7 +373,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
alerts = [current_alert(route_id: affected_branch_id, effect: effect, time: time)]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
normal_branch_ids = @green_line_branches |> List.delete(affected_branch_id)
Expand Down Expand Up @@ -403,7 +403,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
affected_branch_ids =
Expand All @@ -424,7 +424,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
alerts = [current_alert(route_id: "Red", time: time)]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
red_line_statuses = groups |> Map.fetch!("Red")
Expand All @@ -444,7 +444,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
alerts = [current_alert(route_id: "Mattapan", effect: effect, time: time)]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
statuses =
Expand All @@ -462,7 +462,7 @@ defmodule Dotcom.SystemStatus.GroupsTest do
alerts = [current_alert(route_id: "Mattapan", time: time)]

# Exercise
groups = Groups.groups(alerts, time)
groups = Subway.subway_status(alerts, time)

# Verify
statuses =
Expand Down

0 comments on commit d8c8f53

Please sign in to comment.