Skip to content

Commit

Permalink
Rearrange struct keys and update schedule (#2153)
Browse files Browse the repository at this point in the history
* rearrange struct keys and update schedule

* remove test for exceptions

* change key order
  • Loading branch information
anthonyshull authored Aug 20, 2024
1 parent dd13a0b commit ef0e865
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 57 deletions.
6 changes: 3 additions & 3 deletions assets/ts/schedule/components/__schedule.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ export interface SimpleStopMap {
}

export interface ScheduleNote {
peak_service: string;
alternate_text: string | null;
exceptions: ServiceException[];
offpeak_service: string | null;
peak_service: string;
saturday_service: string;
sunday_service: string;
exceptions: ServiceException[];
alternate_text: string | null;
}

export interface ServiceException {
Expand Down
66 changes: 30 additions & 36 deletions lib/dotcom/schedule_note.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ defmodule Dotcom.ScheduleNote do
alias Phoenix.HTML
alias Routes.Route

defstruct peak_service: "",
defstruct alternate_text: nil,
exceptions: [],
offpeak_service: "",
peak_service: "",
saturday_service: "",
sunday_service: "",
exceptions: [],
alternate_text: nil
sunday_service: ""

@type exception :: %{
type: String.t(),
service: String.t()
}

@type t :: %__MODULE__{
peak_service: String.t(),
alternate_text: String.t() | nil,
exceptions: [exception],
offpeak_service: String.t() | nil,
peak_service: String.t(),
saturday_service: String.t(),
sunday_service: String.t(),
exceptions: [exception],
alternate_text: String.t() | nil
sunday_service: String.t()
}

@spec new(Route.t()) :: t | nil
Expand All @@ -39,85 +39,79 @@ defmodule Dotcom.ScheduleNote do
def schedule_note(%Route{id: "Red"}) do
%__MODULE__{
peak_service: "6 \u2013 20 minutes",
saturday_service: "9 \u2013 21 minutes",
sunday_service: "9 \u2013 20 minutes"
saturday_service: "9 \u2013 18 minutes",
sunday_service: "9 \u2013 18 minutes"
}
end

def schedule_note(%Route{id: "Mattapan"}) do
%__MODULE__{
peak_service: "6 \u2013 7 minutes",
saturday_service: "12 \u2013 13 minutes",
sunday_service: "12 \u2013 13 minutes",
offpeak_service: "8 \u2013 12 minutes",
exceptions: [
%{
type: "weekend mornings and late night",
service: "26 minutes"
}
]
peak_service: "7 minutes",
saturday_service: "13 minutes",
sunday_service: "13 minutes"
}
end

def schedule_note(%Route{id: "Orange"}) do
%__MODULE__{
peak_service: "7 \u2013 10 minutes",
saturday_service: "10 \u2013 11 minutes",
sunday_service: "13 \u2013 15 minutes"
peak_service: "6 \u2013 9 minutes",
saturday_service: "9 \u2013 10 minutes",
sunday_service: "12 \u2013 14 minutes"
}
end

def schedule_note(%Route{id: "Blue"}) do
%__MODULE__{
peak_service: "5 \u2013 6 minutes",
saturday_service: "10 \u2013 11 minutes",
sunday_service: "13 \u2013 15 minutes",
offpeak_service: "7 \u2013 13 minutes"
offpeak_service: "6 \u2013 13 minutes",
peak_service: "4 \u2013 5 minutes",
saturday_service: "9 minutes",
sunday_service: "9 minutes"
}
end

def schedule_note(%Route{id: "Green"}) do
%__MODULE__{
offpeak_service: "7 \u2013 12 minutes",
peak_service: "6 \u2013 8 minutes",
saturday_service: "8 \u2013 12 minutes",
sunday_service: "9 \u2013 13 minutes",
offpeak_service: "7 \u2013 12 minutes"
sunday_service: "9 \u2013 13 minutes"
}
end

def schedule_note(%Route{id: "Green-B"}) do
%__MODULE__{
offpeak_service: "7 \u2013 12 minutes",
peak_service: "6 \u2013 8 minutes",
saturday_service: "8 \u2013 12 minutes",
sunday_service: "9 \u2013 13 minutes",
offpeak_service: "7 \u2013 12 minutes"
sunday_service: "9 \u2013 13 minutes"
}
end

def schedule_note(%Route{id: "Green-C"}) do
%__MODULE__{
offpeak_service: "7 \u2013 12 minutes",
peak_service: "6 \u2013 8 minutes",
saturday_service: "8 \u2013 12 minutes",
sunday_service: "9 \u2013 13 minutes",
offpeak_service: "7 \u2013 12 minutes"
sunday_service: "9 \u2013 13 minutes"
}
end

def schedule_note(%Route{id: "Green-D"}) do
%__MODULE__{
offpeak_service: "7 \u2013 12 minutes",
peak_service: "6 \u2013 8 minutes",
saturday_service: "8 \u2013 12 minutes",
sunday_service: "9 \u2013 13 minutes",
offpeak_service: "7 \u2013 12 minutes"
sunday_service: "9 \u2013 13 minutes"
}
end

def schedule_note(%Route{id: "Green-E"}) do
%__MODULE__{
offpeak_service: "7 \u2013 12 minutes",
peak_service: "6 \u2013 8 minutes",
saturday_service: "8 \u2013 12 minutes",
sunday_service: "9 \u2013 13 minutes",
offpeak_service: "7 \u2013 12 minutes"
sunday_service: "9 \u2013 13 minutes"
}
end

Expand Down
18 changes: 0 additions & 18 deletions test/dotcom/lib/schedule_note_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,6 @@ defmodule Dotcom.ScheduleNoteTest do
)
end

test "handles lines with exceptions to offpeak service" do
note_for_mattapan = ScheduleNote.new(@mattapan)

assert(
note_for_mattapan.peak_service && note_for_mattapan.saturday_service &&
note_for_mattapan.sunday_service
)

assert %{
exceptions: [
%{
type: "weekend mornings and late night",
service: "26 minutes"
}
]
} = note_for_mattapan
end

test "returns alternate HTML text for special cases" do
note_for_cr_foxboro = ScheduleNote.new(@foxboro)
assert(note_for_cr_foxboro.alternate_text)
Expand Down

0 comments on commit ef0e865

Please sign in to comment.