Skip to content

Commit d17caa5

Browse files
committed
fixup! [SPIKE] Unavailable trips
1 parent 3e293e6 commit d17caa5

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

lib/dotcom/trip_plan/itinerary.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ defmodule Dotcom.TripPlan.Itinerary do
1414
@enforce_keys [:start, :stop]
1515
defstruct [
1616
:duration,
17+
:generalized_cost,
1718
:start,
1819
:stop,
1920
:passes,
@@ -25,6 +26,7 @@ defmodule Dotcom.TripPlan.Itinerary do
2526

2627
@type t :: %__MODULE__{
2728
duration: non_neg_integer(),
29+
generalized_cost: non_neg_integer(),
2830
start: DateTime.t(),
2931
stop: DateTime.t(),
3032
legs: [Leg.t()],

lib/dotcom/trip_plan/itinerary_group.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ defmodule Dotcom.TripPlan.ItineraryGroup do
55

66
alias Dotcom.TripPlan.Itinerary
77

8-
defstruct [:itineraries, :representative_index, :representative_time_key, :summary]
8+
defstruct [
9+
:generalized_cost,
10+
:itineraries,
11+
:representative_index,
12+
:representative_time_key,
13+
:summary
14+
]
915

1016
@type summarized_leg :: %{
1117
routes: [Routes.Route.t()],
@@ -25,6 +31,7 @@ defmodule Dotcom.TripPlan.ItineraryGroup do
2531
}
2632

2733
@type t :: %__MODULE__{
34+
generalized_cost: non_neg_integer(),
2835
itineraries: [Itinerary.t()],
2936
representative_index: non_neg_integer(),
3037
representative_time_key: :start | :stop,

lib/dotcom/trip_plan/itinerary_groups.ex

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ defmodule Dotcom.TripPlan.ItineraryGroups do
2121
"""
2222
@spec from_itineraries([Itinerary.t()], Keyword.t()) :: [ItineraryGroup.t()]
2323
def from_itineraries(itineraries, opts \\ []) do
24-
ideal_itineraries =
25-
(opts[:ideal_itineraries] || [])
26-
|> Enum.group_by(&{&1.accessible?, unique_legs_to_hash(&1)})
27-
2824
actual_itineraries =
2925
itineraries
3026
|> Enum.group_by(&{&1.accessible?, unique_legs_to_hash(&1)})
3127

28+
best_actual_cost = itineraries |> Enum.map(& &1.generalized_cost) |> Enum.min()
29+
30+
ideal_itineraries =
31+
(opts[:ideal_itineraries] || [])
32+
|> Enum.reject(&(&1.generalized_cost > best_actual_cost))
33+
|> Enum.group_by(&{&1.accessible?, unique_legs_to_hash(&1)})
34+
3235
unavailable_itineraries =
3336
ideal_itineraries
3437
|> Enum.reject(fn {hash, _} -> actual_itineraries |> Map.has_key?(hash) end)
@@ -99,6 +102,7 @@ defmodule Dotcom.TripPlan.ItineraryGroups do
99102
|> Map.put(:unavailable?, opts[:unavailable?])
100103

101104
%ItineraryGroup{
105+
generalized_cost: limited_itineraries |> Enum.map(& &1.generalized_cost) |> Enum.min(),
102106
itineraries: ItineraryTag.sort_tagged(limited_itineraries),
103107
representative_index: representative_index,
104108
representative_time_key: if(opts[:take_from_end], do: :stop, else: :start),

lib/dotcom/trip_plan/parser.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ defmodule Dotcom.TripPlan.Parser do
2222
%Schema.Itinerary{
2323
accessibility_score: accessibility_score,
2424
duration: seconds,
25+
generalized_cost: generalized_cost,
2526
legs: legs,
2627
walk_distance: meters
2728
} = itinerary
@@ -32,6 +33,7 @@ defmodule Dotcom.TripPlan.Parser do
3233
Itinerary,
3334
Map.merge(Map.from_struct(itinerary), %{
3435
accessible?: accessibility_score == 1 || all_mbta_buses?(legs),
36+
generalized_cost: generalized_cost,
3537
duration: minutes(seconds),
3638
legs: legs_with_fares,
3739
stop: itinerary.end,

lib/dotcom_web/components/trip_planner/results.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ defmodule DotcomWeb.Components.TripPlanner.Results do
101101
</.button>
102102
</div>
103103
</div>
104+
<div>Cost: {@itinerary.generalized_cost}</div>
104105
<.itinerary_detail itinerary={@itinerary} />
105106
</div>
106107
"""
@@ -130,6 +131,7 @@ defmodule DotcomWeb.Components.TripPlanner.Results do
130131
>
131132
Unavailable
132133
</div>
134+
<div>Cost: {group.generalized_cost}</div>
133135
<.itinerary_summary summary={group.summary} />
134136
<div :if={!group.summary.unavailable?} class="flex justify-end items-center">
135137
<div :if={ItineraryGroup.options_text(group)} class="grow text-sm text-grey-dark">

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"nimble_ownership": {:hex, :nimble_ownership, "1.0.1", "f69fae0cdd451b1614364013544e66e4f5d25f36a2056a9698b793305c5aa3a6", [:mix], [], "hexpm", "3825e461025464f519f3f3e4a1f9b68c47dc151369611629ad08b636b73bb22d"},
8282
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
8383
"nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"},
84-
"open_trip_planner_client": {:git, "https://github.com/mbta/open_trip_planner_client.git", "f713e07f538b4ab24351809cd3a1e173032f60df", [branch: "jdl/trip-planner/unavailable-trips-spike"]},
84+
"open_trip_planner_client": {:git, "https://github.com/mbta/open_trip_planner_client.git", "68580ac8abd49c0807ca97df6fcf4e10876be34a", [branch: "jdl/trip-planner/unavailable-trips-spike"]},
8585
"parallel_stream": {:hex, :parallel_stream, "1.1.0", "f52f73eb344bc22de335992377413138405796e0d0ad99d995d9977ac29f1ca9", [:mix], [], "hexpm", "684fd19191aedfaf387bbabbeb8ff3c752f0220c8112eb907d797f4592d6e871"},
8686
"parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"},
8787
"phoenix": {:hex, :phoenix, "1.7.21", "14ca4f1071a5f65121217d6b57ac5712d1857e40a0833aff7a691b7870fc9a3b", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "336dce4f86cba56fed312a7d280bf2282c720abb6074bdb1b61ec8095bdd0bc9"},

0 commit comments

Comments
 (0)