-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add StopInPattern in GTFS GraphQL schema #6206
Open
miklcct
wants to merge
5
commits into
opentripplanner:dev-2.x
Choose a base branch
from
Jnction:board-alight-in-pattern
base: dev-2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
de411db
add StopInPattern in GTFS GraphQL schema
miklcct 3bab15a
refactor logic to be testable
miklcct 3f5d535
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct 79d9457
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct dcb5e51
Merge branch 'dev-2.x' into board-alight-in-pattern
miklcct File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/StopInPatternImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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.model.StopInPatternModel; | ||
import org.opentripplanner.transit.model.network.TripPattern; | ||
|
||
public class StopInPatternImpl implements GraphQLDataFetchers.GraphQLStopInPattern { | ||
|
||
@Override | ||
public DataFetcher<String> dropoffType() { | ||
return environment -> StoptimeImpl.getGraphqlPickDrop(getSource(environment).dropoffType()); | ||
} | ||
|
||
@Override | ||
public DataFetcher<Integer> indexInPattern() { | ||
return environment -> getSource(environment).indexInPattern(); | ||
} | ||
|
||
@Override | ||
public DataFetcher<TripPattern> pattern() { | ||
return environment -> getSource(environment).pattern(); | ||
} | ||
|
||
@Override | ||
public DataFetcher<String> pickupType() { | ||
return environment -> StoptimeImpl.getGraphqlPickDrop(getSource(environment).pickupType()); | ||
} | ||
|
||
@Override | ||
public DataFetcher<Object> stop() { | ||
return environment -> getSource(environment).stop(); | ||
} | ||
|
||
private StopInPatternModel getSource(DataFetchingEnvironment environment) { | ||
return environment.getSource(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
application/src/main/java/org/opentripplanner/apis/gtfs/model/StopInPatternModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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, | ||
TripPattern pattern, | ||
int indexInPattern, | ||
PickDrop pickupType, | ||
PickDrop dropoffType | ||
) { | ||
public static StopInPatternModel fromPatternAndIndex(TripPattern pattern, int indexInPattern) { | ||
return new StopInPatternModel( | ||
pattern.getStop(indexInPattern), | ||
pattern, | ||
indexInPattern, | ||
pattern.getBoardType(indexInPattern), | ||
pattern.getAlightType(indexInPattern) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -901,6 +901,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!]! | ||||||
"Trips which run on this pattern" | ||||||
trips: [Trip!] | ||||||
"Trips which run on this pattern on the specified date" | ||||||
|
@@ -2172,6 +2174,16 @@ type StopGeometries { | |||||
googleEncoded: [Geometry] | ||||||
} | ||||||
|
||||||
type StopInPattern { | ||||||
"NULL means that the stop is cancelled from the pattern." | ||||||
dropoffType: PickupDropoffType | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
indexInPattern: Int! | ||||||
pattern: Pattern! | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need the pattern? Seems like you already have it. |
||||||
"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." | ||||||
|
69 changes: 69 additions & 0 deletions
69
application/src/test/java/org/opentripplanner/apis/gtfs/model/StopInPatternModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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, PATTERN, 0, PickDrop.SCHEDULED, PickDrop.NONE), | ||
StopInPatternModel.fromPatternAndIndex(PATTERN, 0) | ||
); | ||
assertEquals( | ||
new StopInPatternModel( | ||
STOP_B, | ||
PATTERN, | ||
1, | ||
PickDrop.CALL_AGENCY, | ||
PickDrop.COORDINATE_WITH_DRIVER | ||
), | ||
StopInPatternModel.fromPatternAndIndex(PATTERN, 1) | ||
); | ||
assertEquals( | ||
new StopInPatternModel(STOP_C, PATTERN, 2, PickDrop.NONE, PickDrop.SCHEDULED), | ||
StopInPatternModel.fromPatternAndIndex(PATTERN, 2) | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?