Skip to content

Commit 11cbb86

Browse files
committed
Add viaLocationType to Place in GTFS API
1 parent a3ab67c commit 11cbb86

33 files changed

Lines changed: 417 additions & 50 deletions

application/src/ext/java/org/opentripplanner/ext/flex/FlexRouter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.opentripplanner.model.PathTransfer;
2424
import org.opentripplanner.model.plan.Itinerary;
2525
import org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper;
26+
import org.opentripplanner.routing.api.request.RouteRequest;
2627
import org.opentripplanner.routing.graph.Graph;
2728
import org.opentripplanner.routing.graphfinder.NearbyStop;
2829
import org.opentripplanner.routing.graphfinder.TransitServiceResolver;
@@ -120,7 +121,7 @@ public FlexRouter(
120121
);
121122
}
122123

123-
public List<Itinerary> createFlexOnlyItineraries(boolean arriveBy) {
124+
public List<Itinerary> createFlexOnlyItineraries(boolean arriveBy, RouteRequest request) {
124125
OTPRequestTimeoutException.checkForTimeout();
125126

126127
var directFlexPaths = new FlexDirectPathFactory(
@@ -136,7 +137,7 @@ public List<Itinerary> createFlexOnlyItineraries(boolean arriveBy) {
136137
for (DirectFlexPath it : directFlexPaths) {
137138
var startTime = startOfTime.plusSeconds(it.startTime());
138139
var itinerary = graphPathToItineraryMapper
139-
.generateItinerary(new GraphPath<>(it.state()))
140+
.generateItinerary(new GraphPath<>(it.state()), request)
140141
.withTimeShiftToStartAt(startTime);
141142

142143
if (itinerary != null) {

application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public DataFetcher<StopArrival> from() {
110110
source.start(),
111111
source.start(),
112112
source.boardStopPosInPattern(),
113-
source.boardingGtfsStopSequence()
113+
source.boardingGtfsStopSequence(),
114+
source.from().viaLocationType
114115
);
115116
};
116117
}
@@ -271,7 +272,8 @@ public DataFetcher<StopArrival> to() {
271272
source.end(),
272273
source.end(),
273274
source.alightStopPosInPattern(),
274-
source.alightGtfsStopSequence()
275+
source.alightGtfsStopSequence(),
276+
source.to().viaLocationType
275277
);
276278
};
277279
}

application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/PlaceImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.opentripplanner.model.plan.VertexType;
1212
import org.opentripplanner.model.plan.leg.LegCallTime;
1313
import org.opentripplanner.model.plan.leg.StopArrival;
14+
import org.opentripplanner.model.plan.leg.ViaLocationType;
1415
import org.opentripplanner.service.vehicleparking.model.VehicleParking;
1516
import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace;
1617
import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation;
@@ -168,6 +169,14 @@ public DataFetcher<String> vertexType() {
168169
};
169170
}
170171

172+
@Override
173+
public DataFetcher<ViaLocationType> viaLocationType() {
174+
return environment -> {
175+
var stopArrival = getSource(environment);
176+
return stopArrival.viaLocationType;
177+
};
178+
}
179+
171180
private VehicleParking getBikePark(DataFetchingEnvironment environment) {
172181
StopArrival stopArrival = getSource(environment);
173182
var vehicleParkingWithEntrance = stopArrival.place.vehicleParkingWithEntrance;

application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/PlanImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public DataFetcher<DebugOutput> debugOutput() {
2828
@Override
2929
public DataFetcher<StopArrival> from() {
3030
return environment ->
31-
new StopArrival(getSource(environment).getTripPlan().from, null, null, null, null);
31+
new StopArrival(getSource(environment).getTripPlan().from, null, null, null, null, null);
3232
}
3333

3434
@Override
@@ -115,7 +115,7 @@ public DataFetcher<Long> searchWindowUsed() {
115115
@Override
116116
public DataFetcher<StopArrival> to() {
117117
return environment ->
118-
new StopArrival(getSource(environment).getTripPlan().to, null, null, null, null);
118+
new StopArrival(getSource(environment).getTripPlan().to, null, null, null, null, null);
119119
}
120120

121121
private RoutingResponse getSource(DataFetchingEnvironment environment) {

application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.opentripplanner.model.plan.leg.LegCallTime;
4747
import org.opentripplanner.model.plan.leg.LegRealTimeEstimate;
4848
import org.opentripplanner.model.plan.leg.StopArrival;
49+
import org.opentripplanner.model.plan.leg.ViaLocationType;
4950
import org.opentripplanner.model.plan.walkstep.WalkStep;
5051
import org.opentripplanner.routing.alertpatch.TransitAlert;
5152
import org.opentripplanner.routing.api.response.RoutingError;
@@ -761,6 +762,8 @@ public interface GraphQLPlace {
761762
public DataFetcher<VehicleRentalStation> vehicleRentalStation();
762763

763764
public DataFetcher<String> vertexType();
765+
766+
public DataFetcher<ViaLocationType> viaLocationType();
764767
}
765768

766769
/** Interface for places, e.g. stops, stations, parking areas.. */

application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5693,6 +5693,12 @@ public enum GraphQLVertexType {
56935693
TRANSIT,
56945694
}
56955695

5696+
/** Categorization for via locations. */
5697+
public enum GraphQLViaLocationType {
5698+
PASS_THROUGH,
5699+
VISIT,
5700+
}
5701+
56965702
public static class GraphQLWalkPreferencesInput {
56975703

56985704
private org.opentripplanner.framework.model.Cost boardCost;

application/src/main/java/org/opentripplanner/apis/gtfs/generated/graphql-codegen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ config:
136136
CallSchedule: org.opentripplanner.apis.gtfs.model.CallSchedule#CallSchedule
137137
CallScheduledTime: org.opentripplanner.apis.gtfs.model.CallScheduledTime#CallScheduledTime
138138
RentalVehicleFuel: org.opentripplanner.service.vehiclerental.model.RentalVehicleFuel#RentalVehicleFuel
139-
139+
ViaLocationType: org.opentripplanner.model.plan.leg.ViaLocationType#ViaLocationType

application/src/main/java/org/opentripplanner/model/plan/Place.java

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.opentripplanner.framework.i18n.LocalizedString;
77
import org.opentripplanner.framework.i18n.NonLocalizedString;
88
import org.opentripplanner.model.GenericLocation;
9+
import org.opentripplanner.model.plan.leg.ViaLocationType;
910
import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace;
1011
import org.opentripplanner.service.vehiclerental.street.VehicleRentalPlaceVertex;
1112
import org.opentripplanner.street.model.vertex.StreetVertex;
@@ -42,32 +43,43 @@ public class Place {
4243
/**
4344
* Reference to the stop if the type is {@link VertexType#TRANSIT}.
4445
*/
46+
@Nullable
4547
public final StopLocation stop;
4648

4749
/**
4850
* The vehicle rental place if the type is {@link VertexType#VEHICLERENTAL}.
4951
*/
52+
@Nullable
5053
public final VehicleRentalPlace vehicleRentalPlace;
5154

5255
/**
5356
* The vehicle parking entrance if the type is {@link VertexType#VEHICLEPARKING}.
5457
*/
58+
@Nullable
5559
public final VehicleParkingWithEntrance vehicleParkingWithEntrance;
5660

61+
/**
62+
* Categorization for a via location, if the place is a via location in the request.
63+
*/
64+
@Nullable
65+
public final ViaLocationType viaLocationType;
66+
5767
private Place(
5868
I18NString name,
5969
WgsCoordinate coordinate,
6070
VertexType vertexType,
61-
StopLocation stop,
62-
VehicleRentalPlace vehicleRentalPlace,
63-
VehicleParkingWithEntrance vehicleParkingWithEntrance
71+
@Nullable StopLocation stop,
72+
@Nullable VehicleRentalPlace vehicleRentalPlace,
73+
@Nullable VehicleParkingWithEntrance vehicleParkingWithEntrance,
74+
@Nullable ViaLocationType viaLocationType
6475
) {
6576
this.name = name;
6677
this.coordinate = coordinate;
6778
this.vertexType = vertexType;
6879
this.stop = stop;
6980
this.vehicleRentalPlace = vehicleRentalPlace;
7081
this.vehicleParkingWithEntrance = vehicleParkingWithEntrance;
82+
this.viaLocationType = viaLocationType;
7183
}
7284

7385
public static Place normal(Double lat, Double lon, I18NString name) {
@@ -77,23 +89,61 @@ public static Place normal(Double lat, Double lon, I18NString name) {
7789
VertexType.NORMAL,
7890
null,
7991
null,
92+
null,
8093
null
8194
);
8295
}
8396

97+
public static Place normal(
98+
Vertex vertex,
99+
I18NString name,
100+
@Nullable ViaLocationType viaLocationType
101+
) {
102+
return new Place(
103+
name,
104+
WgsCoordinate.creatOptionalCoordinate(vertex.getLat(), vertex.getLon()),
105+
VertexType.NORMAL,
106+
null,
107+
null,
108+
null,
109+
viaLocationType
110+
);
111+
}
112+
84113
public static Place normal(Vertex vertex, I18NString name) {
85114
return new Place(
86115
name,
87116
WgsCoordinate.creatOptionalCoordinate(vertex.getLat(), vertex.getLon()),
88117
VertexType.NORMAL,
89118
null,
90119
null,
120+
null,
91121
null
92122
);
93123
}
94124

125+
public static Place forStop(StopLocation stop, @Nullable ViaLocationType viaLocationType) {
126+
return new Place(
127+
stop.getName(),
128+
stop.getCoordinate(),
129+
VertexType.TRANSIT,
130+
stop,
131+
null,
132+
null,
133+
viaLocationType
134+
);
135+
}
136+
95137
public static Place forStop(StopLocation stop) {
96-
return new Place(stop.getName(), stop.getCoordinate(), VertexType.TRANSIT, stop, null, null);
138+
return new Place(
139+
stop.getName(),
140+
stop.getCoordinate(),
141+
VertexType.TRANSIT,
142+
stop,
143+
null,
144+
null,
145+
null
146+
);
97147
}
98148

99149
public static Place forFlexStop(StopLocation stop, Vertex vertex) {
@@ -114,6 +164,7 @@ public static Place forFlexStop(StopLocation stop, Vertex vertex) {
114164
VertexType.TRANSIT,
115165
stop,
116166
null,
167+
null,
117168
null
118169
);
119170
}
@@ -140,6 +191,7 @@ public static Place forVehicleRentalPlace(VehicleRentalPlaceVertex vertex) {
140191
VertexType.VEHICLERENTAL,
141192
null,
142193
vertex.getStation(),
194+
null,
143195
null
144196
);
145197
}
@@ -166,7 +218,8 @@ public static Place forVehicleParkingEntrance(VehicleParkingEntranceVertex verte
166218
.vehicleParking(vertex.getVehicleParking())
167219
.entrance(vertex.getParkingEntrance())
168220
.realtime(realTime)
169-
.build()
221+
.build(),
222+
null
170223
);
171224
}
172225

@@ -208,6 +261,7 @@ public String toString() {
208261
.addEnum("vertexType", vertexType)
209262
.addObj("vehicleRentalPlace", vehicleRentalPlace)
210263
.addObj("vehicleParkingEntrance", vehicleParkingWithEntrance)
264+
.addObj("viaLocationType", viaLocationType)
211265
.toString();
212266
}
213267
}

application/src/main/java/org/opentripplanner/model/plan/leg/FrequencyTransitLeg.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public List<StopArrival> listIntermediateStops() {
6969
ServiceDateUtils.toZonedDateTime(serviceDate(), zoneId(), departureTime)
7070
),
7171
i,
72-
tripTimes().gtfsSequenceOfStopIndex(i)
72+
tripTimes().gtfsSequenceOfStopIndex(i),
73+
null
7374
);
7475
visits.add(visit);
7576
}

application/src/main/java/org/opentripplanner/model/plan/leg/ScheduledTransitLeg.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ public class ScheduledTransitLeg implements TransitLeg {
7777
private final TripOnServiceDate tripOnServiceDate;
7878
private final double distanceMeters;
7979

80+
@Nullable
81+
private final ViaLocationType fromViaLocationType;
82+
83+
@Nullable
84+
private final ViaLocationType toViaLocationType;
85+
8086
// Sandbox fields
8187
private final Float accessibilityScore;
8288
private final Emission emissionPerPerson;
@@ -125,6 +131,8 @@ protected ScheduledTransitLeg(ScheduledTransitLegBuilder<?> builder) {
125131
Objects.requireNonNull(builder.distanceMeters(), "distanceMeters")
126132
);
127133
this.transitAlerts = Set.copyOf(builder.alerts());
134+
this.fromViaLocationType = builder.fromViaLocationType();
135+
this.toViaLocationType = builder.toViaLocationType();
128136

129137
// Sandbox
130138
this.accessibilityScore = builder.accessibilityScore();
@@ -294,12 +302,12 @@ public TripOnServiceDate tripOnServiceDate() {
294302

295303
@Override
296304
public Place from() {
297-
return Place.forStop(tripPattern.getStop(boardStopPosInPattern));
305+
return Place.forStop(tripPattern.getStop(boardStopPosInPattern), fromViaLocationType);
298306
}
299307

300308
@Override
301309
public Place to() {
302-
return Place.forStop(tripPattern.getStop(alightStopPosInPattern));
310+
return Place.forStop(tripPattern.getStop(alightStopPosInPattern), toViaLocationType);
303311
}
304312

305313
@Override
@@ -467,8 +475,20 @@ public String toString() {
467475
.addObj("transferFromPrevLeg", transferFromPrevLeg)
468476
.addObj("transferToNextLeg", transferToNextLeg)
469477
.addColSize("transitAlerts", transitAlerts)
478+
.addObj("fromViaLocationType", fromViaLocationType)
479+
.addObj("toViaLocationType", toViaLocationType)
470480
.addObj("emissionPerPerson", emissionPerPerson)
471481
.addColSize("fareProducts", fareOffers)
472482
.toString();
473483
}
484+
485+
@Nullable
486+
ViaLocationType fromViaLocationType() {
487+
return fromViaLocationType;
488+
}
489+
490+
@Nullable
491+
ViaLocationType toViaLocationType() {
492+
return toViaLocationType;
493+
}
474494
}

0 commit comments

Comments
 (0)