Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
de411db
add StopInPattern in GTFS GraphQL schema
miklcct Oct 29, 2024
3bab15a
refactor logic to be testable
miklcct Oct 29, 2024
3f5d535
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Nov 5, 2024
79d9457
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Nov 26, 2024
dcb5e51
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Dec 4, 2024
78312cb
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Dec 17, 2024
789d7a8
apply review suggestions
miklcct Dec 17, 2024
b101d73
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Jan 9, 2025
c1df84b
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Jan 30, 2025
684dbef
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Feb 11, 2025
8a9d64e
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Feb 21, 2025
cc3374f
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Mar 7, 2025
376fea9
formatting
miklcct Mar 7, 2025
3a0a603
Merge tag 'v2.7.0' into board-alight-in-pattern
miklcct Mar 12, 2025
d6c60e7
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Apr 15, 2025
dc644e4
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct May 6, 2025
2560142
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct May 20, 2025
775a15e
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Jun 4, 2025
b2d567b
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Jun 19, 2025
7f9c005
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Aug 21, 2025
b0fe474
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct Oct 9, 2025
cbddb66
remove unused imports
miklcct Oct 9, 2025
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 @@ -58,6 +58,7 @@
import org.opentripplanner.apis.gtfs.datafetchers.StopCallImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StopGeometriesImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StopImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StopInPatternImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StopOnRouteImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StopOnTripImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StopRelationshipImpl;
Expand Down Expand Up @@ -172,6 +173,7 @@ public static GraphQLSchema createSchema() {
.type(typeWiring.build(LocationImpl.class))
.type(typeWiring.build(LocationGroupImpl.class))
.type(typeWiring.build(stopAtDistanceImpl.class))
.type(typeWiring.build(StopInPatternImpl.class))
.type(typeWiring.build(StoptimeImpl.class))
.type(typeWiring.build(StoptimesInPatternImpl.class))
.type(typeWiring.build(TicketTypeImpl.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.opentripplanner.apis.gtfs.GraphQLRequestContext;
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;
import org.opentripplanner.apis.gtfs.model.StopInPatternModel;
import org.opentripplanner.apis.support.SemanticHash;
import org.opentripplanner.framework.graphql.GraphQLUtils;
import org.opentripplanner.routing.alertpatch.EntitySelector;
Expand Down Expand Up @@ -194,6 +195,19 @@ public DataFetcher<Iterable<Object>> stops() {
return this::getStops;
}

@Override
public DataFetcher<Iterable<Object>> stopsInPattern() {
return environment -> {
var pattern = getSource(environment);
var numberOfStops = pattern.numberOfStops();
var result = new StopInPatternModel[numberOfStops];
for (var i = 0; i < numberOfStops; i++) {
result[i] = StopInPatternModel.fromPatternAndIndex(pattern, i);
}
return List.of(result);
};
}

@Override
public DataFetcher<Iterable<Trip>> trips() {
return this::getTrips;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.opentripplanner.apis.gtfs.datafetchers;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;
import org.opentripplanner.apis.gtfs.mapping.PickDropMapper;
import org.opentripplanner.apis.gtfs.model.StopInPatternModel;

public class StopInPatternImpl implements GraphQLDataFetchers.GraphQLStopInPattern {

@Override
public DataFetcher<GraphQLTypes.GraphQLPickupDropoffType> dropOffType() {
return environment -> PickDropMapper.map(getSource(environment).dropoffType());
}

@Override
public DataFetcher<Integer> indexInPattern() {
return environment -> getSource(environment).indexInPattern();
}

@Override
public DataFetcher<GraphQLTypes.GraphQLPickupDropoffType> pickupType() {
return environment -> PickDropMapper.map(getSource(environment).pickupType());
}

@Override
public DataFetcher<Object> stop() {
return environment -> getSource(environment).stop();
}

private StopInPatternModel getSource(DataFetchingEnvironment environment) {
return environment.getSource();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@ public interface GraphQLPattern {

public DataFetcher<Iterable<Object>> stops();

public DataFetcher<Iterable<Object>> stopsInPattern();

public DataFetcher<Iterable<Trip>> trips();

public DataFetcher<Iterable<Trip>> tripsForDate();
Expand Down Expand Up @@ -1187,6 +1189,16 @@ public interface GraphQLStopGeometries {
public DataFetcher<Iterable<Geometry>> googleEncoded();
}

public interface GraphQLStopInPattern {
public DataFetcher<GraphQLPickupDropoffType> dropOffType();

public DataFetcher<Integer> indexInPattern();

public DataFetcher<GraphQLPickupDropoffType> pickupType();

public DataFetcher<Object> stop();
}

/** Stop that should (but not guaranteed) to exist on a route. */
public interface GraphQLStopOnRoute {
public DataFetcher<Route> route();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.opentripplanner.apis.gtfs.model;

import org.opentripplanner.model.PickDrop;
import org.opentripplanner.transit.model.network.TripPattern;
import org.opentripplanner.transit.model.site.StopLocation;

public record StopInPatternModel(
StopLocation stop,
int indexInPattern,
PickDrop pickupType,
PickDrop dropoffType
) {
public static StopInPatternModel fromPatternAndIndex(TripPattern pattern, int indexInPattern) {
return new StopInPatternModel(
pattern.getStop(indexInPattern),
indexInPattern,
pattern.getBoardType(indexInPattern),
pattern.getAlightType(indexInPattern)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,8 @@ type Pattern implements Node {
semanticHash: String
"List of stops served by this pattern"
stops: [Stop!]
"List of stops with pickup / dropoff type served by this pattern"
stopsInPattern: [StopInPattern!]!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you need this for? Is it just for the index? Isn't it straightforward to compute the index yourself, first item in the list is 0 and so on?

"Trips which run on this pattern"
trips: [Trip!]
"Trips which run on this pattern on the specified date"
Expand Down Expand Up @@ -2362,6 +2364,15 @@ type StopGeometries {
googleEncoded: [Geometry]
}

type StopInPattern {
"NULL means that the stop is cancelled from the pattern."
dropOffType: PickupDropoffType
indexInPattern: Int!
"NULL means that the stop is cancelled from the pattern."
pickupType: PickupDropoffType
stop: Stop!
}

"Stop that should (but not guaranteed) to exist on a route."
type StopOnRoute {
"Route which contains the stop."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.opentripplanner.apis.gtfs.model;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import org.junit.jupiter.api.Test;
import org.opentripplanner.model.PickDrop;
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
import org.opentripplanner.transit.model.network.Route;
import org.opentripplanner.transit.model.network.StopPattern;
import org.opentripplanner.transit.model.network.TripPattern;
import org.opentripplanner.transit.model.site.RegularStop;

public class StopInPatternModelTest {

private static final String ID = "1";
private static final String NAME = "short name";
private static final TimetableRepositoryForTest TEST_MODEL = TimetableRepositoryForTest.of();

private static final Route ROUTE = TimetableRepositoryForTest.route("routeId").build();
public static final RegularStop STOP_A = TEST_MODEL.stop("A").build();
public static final RegularStop STOP_B = TEST_MODEL.stop("B").build();
public static final RegularStop STOP_C = TEST_MODEL.stop("C").build();
private static final StopPattern STOP_PATTERN = getStopPattern();

private static StopPattern getStopPattern() {
var builder = StopPattern.create(3);

builder.stops.with(0, STOP_A);
builder.stops.with(1, STOP_B);
builder.stops.with(2, STOP_C);
builder.pickups.with(0, PickDrop.SCHEDULED);
builder.pickups.with(1, PickDrop.CALL_AGENCY);
builder.pickups.with(2, PickDrop.NONE);
builder.dropoffs.with(0, PickDrop.NONE);
builder.dropoffs.with(1, PickDrop.COORDINATE_WITH_DRIVER);
builder.dropoffs.with(2, PickDrop.SCHEDULED);
return builder.build();
}

public static final TripPattern PATTERN = TripPattern.of(id(ID))
.withName(NAME)
.withRoute(ROUTE)
.withStopPattern(STOP_PATTERN)
.build();

@Test
public void fromPatternAndIndex() {
assertEquals(
new StopInPatternModel(STOP_A, 0, PickDrop.SCHEDULED, PickDrop.NONE),
StopInPatternModel.fromPatternAndIndex(PATTERN, 0)
);
assertEquals(
new StopInPatternModel(STOP_B, 1, PickDrop.CALL_AGENCY, PickDrop.COORDINATE_WITH_DRIVER),
StopInPatternModel.fromPatternAndIndex(PATTERN, 1)
);
assertEquals(
new StopInPatternModel(STOP_C, 2, PickDrop.NONE, PickDrop.SCHEDULED),
StopInPatternModel.fromPatternAndIndex(PATTERN, 2)
);
}
}
Loading