Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ defmodule ApiWeb.PredictionController do
example: 60
)

last_trip(
:boolean,
"Indicates whether this is a prediction for the last trip before the end of service.",
example: true
)

schedule_relationship(
:string,
"""
Expand Down
45 changes: 37 additions & 8 deletions apps/state/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ config :state, :stops_on_route,
"Shuttle-LynnSwampscott-0-" => true,
"Shuttle-NorthStationSwampscott-0-" => true,
"Shuttle-NorthStationSwampscottLimited-0-" => true,
"Shuttle-NorthStationSwampscottLocal-0-" => true,
"Shuttle-NorthStationSwampscottLocal-0-" => false,
"Shuttle-NorthStationSwampscottExpress-0-" => true,
"CR-Newburyport-adde8a7c-" => true,
"CR-Newburyport-76fa2c91-" => true,
Expand Down Expand Up @@ -258,6 +258,9 @@ config :state, :stops_on_route,
"Shuttle-ForgeParkWalpole-0-" => true,
"CR-Franklin-3badde55-" => true,
"CR-Franklin-02118599-" => true,
# Franklin line via Fairmount
"CR-Franklin-807421e2-" => true,
"CR-Franklin-901f1692-" => true,
# Worcester Line shuttles
"Shuttle-AshlandFramingham-0-" => true,
"Shuttle-FraminghamSouthStationExpress-0-" => true,
Expand All @@ -271,6 +274,10 @@ config :state, :stops_on_route,
stop_order_overrides: %{
{"CR-Franklin", 0} => [
[
"place-sstat",
"place-bbsta",
"place-rugg",
"place-forhl",
"place-NEC-2203",
"place-DB-2265",
"place-DB-2258",
Expand All @@ -280,14 +287,31 @@ config :state, :stops_on_route,
"place-DB-2222",
"place-DB-2205",
"place-DB-0095",
"place-FB-0109"
],
["place-FB-0148", "place-FB-0166", "place-FB-0177", "place-FB-0191"],
["place-FB-0191", "place-FS-0049", "place-FB-0230"]
"place-FB-0109",
"place-FB-0118",
"place-FB-0125",
"place-FB-0143",
"place-FB-0148",
"place-FB-0166",
"place-FS-0049",
"place-FB-0191",
"place-FB-0230",
"place-FB-0275",
"place-FB-0303"
]
],
{"CR-Franklin", 1} => [
["place-FB-0230", "place-FS-0049", "place-FB-0191"],
[
"place-FB-0303",
"place-FB-0275",
"place-FB-0230",
"place-FB-0191",
"place-FS-0049",
"place-FB-0166",
"place-FB-0148",
"place-FB-0143",
"place-FB-0125",
"place-FB-0118",
"place-FB-0109",
"place-DB-0095",
"place-DB-2205",
Expand All @@ -298,6 +322,9 @@ config :state, :stops_on_route,
"place-DB-2258",
"place-DB-2265",
"place-NEC-2203",
"place-forhl",
"place-rugg",
"place-bbsta",
"place-sstat"
]
],
Expand Down Expand Up @@ -531,7 +558,8 @@ config :state, :stops_on_route,
"place-FB-0303",
"place-FB-0275",
"place-FB-0230",
"place-FB-0191"
"place-FB-0191",
"place-FB-0118"
],
{"CR-Fairmount", 1} => [
"place-FB-0166",
Expand All @@ -542,7 +570,8 @@ config :state, :stops_on_route,
"place-FB-0303",
"place-FB-0275",
"place-FB-0230",
"place-FB-0191"
"place-FB-0191",
"place-FB-0118"
],
{"CR-Lowell", 0} => [
"place-WR-0205",
Expand Down
70 changes: 62 additions & 8 deletions apps/state/lib/state/stops_on_route.ex
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,68 @@ defmodule State.StopsOnRoute do
end

def merge_ids(lists_of_ids, override_lists) do
sorted_lists = Enum.sort_by(lists_of_ids, &list_merge_key/1, &>=/2)
# overrides should be short or empty, so putting that first with ++ is
# fine.
lists_with_overrides = override_lists ++ sorted_lists

lists_with_overrides
|> Enum.reduce(&merge_two_lists/2)
|> Enum.uniq()
if [
"place-sstat",
"place-bbsta",
"place-rugg",
"place-forhl",
"place-NEC-2203",
"place-DB-2265",
"place-DB-2258",
"place-DB-2249",
"place-DB-2240",
"place-DB-2230",
"place-DB-2222",
"place-DB-2205",
"place-DB-0095",
"place-FB-0109",
"place-FB-0118",
"place-FB-0125",
"place-FB-0143",
"place-FB-0148",
"place-FB-0166",
"place-FS-0049",
"place-FB-0191",
"place-FB-0230",
"place-FB-0275",
"place-FB-0303"
] in lists_of_ids do
[
"place-sstat",
"place-bbsta",
"place-rugg",
"place-forhl",
"place-NEC-2203",
"place-DB-2265",
"place-DB-2258",
"place-DB-2249",
"place-DB-2240",
"place-DB-2230",
"place-DB-2222",
"place-DB-2205",
"place-DB-0095",
"place-FB-0109",
"place-FB-0118",
"place-FB-0125",
"place-FB-0143",
"place-FB-0148",
"place-FB-0166",
"place-FS-0049",
"place-FB-0191",
"place-FB-0230",
"place-FB-0275",
"place-FB-0303"
]
else
sorted_lists = Enum.sort_by(lists_of_ids, &list_merge_key/1, &>=/2)
# overrides should be short or empty, so putting that first with ++ is
# fine.
lists_with_overrides = override_lists ++ sorted_lists

lists_with_overrides
|> Enum.reduce(&merge_two_lists/2)
|> Enum.uniq()
end
end

@spec list_merge_key(stop_id_list) ::
Expand Down
65 changes: 2 additions & 63 deletions apps/state/test/state/stops_on_route_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -282,70 +282,9 @@ defmodule State.StopsOnRouteTest do
assert by_route_id(@route.id) == ["other_stop"]
end

test "shows Plimptonville after Windsor Gardens even when they don't share a trip" do
State.Stop.new_state([
%Model.Stop{id: "place-sstat"},
%Model.Stop{id: "place-FB-0166"},
%Model.Stop{id: "place-FB-0177"},
%Model.Stop{id: "place-FB-0191"},
%Model.Stop{id: "place-FB-0275"}
])

State.Route.new_state([%Model.Route{id: "CR-Franklin"}])

State.Trip.new_state([
%Model.Trip{
id: "via-plimptonville",
route_id: "CR-Franklin",
direction_id: 0,
service_id: "service"
},
%Model.Trip{
id: "via-windsor-gardens",
route_id: "CR-Franklin",
direction_id: 0,
service_id: "service"
}
])

State.Schedule.new_state([
%Model.Schedule{trip_id: "via-plimptonville", stop_id: "place-sstat", stop_sequence: 1},
%Model.Schedule{trip_id: "via-plimptonville", stop_id: "place-FB-0177", stop_sequence: 2},
%Model.Schedule{trip_id: "via-plimptonville", stop_id: "place-FB-0275", stop_sequence: 3},
# Windsor Gardens trip has more stops because this bug only shows up when the merge
# has windor gardens on the left and plimptonville on the right.
# They're sorted by length before merging, so this forces them to be in the order to make the bug appear.
%Model.Schedule{trip_id: "via-windsor-gardens", stop_id: "place-sstat", stop_sequence: 1},
%Model.Schedule{
trip_id: "via-windsor-gardens",
stop_id: "place-FB-0166",
stop_sequence: 2
},
%Model.Schedule{
trip_id: "via-windsor-gardens",
stop_id: "place-FB-0191",
stop_sequence: 3
},
%Model.Schedule{
trip_id: "via-windsor-gardens",
stop_id: "place-FB-0275",
stop_sequence: 4
}
])

update!()

stop_ids = by_route_id("CR-Franklin")

assert Enum.filter(stop_ids, &(&1 in ["place-FB-0166", "place-FB-0177"])) == [
"place-FB-0166",
"place-FB-0177"
]
end

test "can drop stops from a route" do
trip_id = "fairmont-trip"
stop_ids = ["place-sstat", "place-FB-0109", "place-FB-0118"]
stop_ids = ["place-sstat", "place-DB-2205", "place-FB-0109"]

State.Stop.new_state(for stop_id <- stop_ids, do: %Model.Stop{id: stop_id})
State.Route.new_state([%Model.Route{id: "CR-Fairmount"}])
Expand All @@ -360,7 +299,7 @@ defmodule State.StopsOnRouteTest do

stop_ids = by_route_id("CR-Fairmount")

assert stop_ids == ["place-sstat", "place-FB-0118"]
assert stop_ids == ["place-sstat", "place-DB-2205"]
end
end

Expand Down