Skip to content

Commit

Permalink
fix: don't use HASTUS start / end place for through-routed trips (#2259)
Browse files Browse the repository at this point in the history
* fix: don't use HASTUS start / end place for through-routed trips

* fix: handle lack of start / end place for trip on front-end
  • Loading branch information
lemald authored Oct 13, 2023
1 parent 5b61262 commit ed5c944
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 4 additions & 4 deletions assets/src/models/minischeduleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ interface TripData {
run_id: RunId | null
start_time: Time
end_time: Time
start_place: string
end_place: string
start_place: string | null
end_place: string | null
}

const isBreakData = (
Expand Down Expand Up @@ -117,8 +117,8 @@ const tripFromData = (tripData: TripData): Trip => ({
runId: tripData.run_id,
startTime: tripData.start_time,
endTime: tripData.end_time,
startPlace: tripData.start_place,
endPlace: tripData.end_place,
startPlace: tripData.start_place || "",
endPlace: tripData.end_place || "",
})

const asDirectedFromData = (asDirectedData: AsDirectedData): AsDirected => ({
Expand Down
9 changes: 6 additions & 3 deletions lib/schedule/hastus/trip.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ defmodule Schedule.Hastus.Trip do
block_id: Block.id(),
start_time: Util.Time.time_of_day(),
end_time: Util.Time.time_of_day(),
start_place: Place.id(),
end_place: Place.id(),
start_place: Place.id() | nil,
end_place: Place.id() | nil,
# nil means nonrevenue
route_id: Route.id() | nil,
trip_id: Trip.id()
Expand Down Expand Up @@ -121,7 +121,10 @@ defmodule Schedule.Hastus.Trip do
_ -> 0
end
end)
|> Enum.map(&%__MODULE__{trip | trip_id: &1})
# Since these trips are split up in GTFS, start and end place from HASTUS are not
# necessarily accurate. Origin and destination should be derived from stop times
# instead. See Schedule.Trip.merge/3
|> Enum.map(&%__MODULE__{trip | trip_id: &1, start_place: nil, end_place: nil})
else
[trip]
end
Expand Down
9 changes: 7 additions & 2 deletions test/schedule/hastus/trip_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ defmodule Schedule.Hastus.TripTest do

assert result == [
hastus_trip1,
%Trip{hastus_trip2 | trip_id: "through_routed_1"},
%Trip{hastus_trip2 | trip_id: "through_routed_2"}
%Trip{
hastus_trip2
| trip_id: "through_routed_1",
start_place: nil,
end_place: nil
},
%Trip{hastus_trip2 | trip_id: "through_routed_2", start_place: nil, end_place: nil}
]
end
end
Expand Down

0 comments on commit ed5c944

Please sign in to comment.