From ed5c944c4b8d7200c664c52664cc483d6a5e7b8f Mon Sep 17 00:00:00 2001 From: Eddie Maldonado Date: Fri, 13 Oct 2023 12:41:04 -0400 Subject: [PATCH] fix: don't use HASTUS start / end place for through-routed trips (#2259) * fix: don't use HASTUS start / end place for through-routed trips * fix: handle lack of start / end place for trip on front-end --- assets/src/models/minischeduleData.ts | 8 ++++---- lib/schedule/hastus/trip.ex | 9 ++++++--- test/schedule/hastus/trip_test.exs | 9 +++++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/assets/src/models/minischeduleData.ts b/assets/src/models/minischeduleData.ts index 8e9e3c6ae..95415d252 100644 --- a/assets/src/models/minischeduleData.ts +++ b/assets/src/models/minischeduleData.ts @@ -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 = ( @@ -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 => ({ diff --git a/lib/schedule/hastus/trip.ex b/lib/schedule/hastus/trip.ex index 527379d88..98f545acc 100644 --- a/lib/schedule/hastus/trip.ex +++ b/lib/schedule/hastus/trip.ex @@ -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() @@ -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 diff --git a/test/schedule/hastus/trip_test.exs b/test/schedule/hastus/trip_test.exs index 7f1f65ca9..270d85b9d 100644 --- a/test/schedule/hastus/trip_test.exs +++ b/test/schedule/hastus/trip_test.exs @@ -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