Skip to content
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

If configured, add subway station entrances from OSM to walk steps #6076

Draft
wants to merge 32 commits into
base: dev-2.x
Choose a base branch
from

Conversation

HenrikSundell
Copy link

@HenrikSundell HenrikSundell commented Sep 18, 2024

Summary

This PR gets subway station entrance names from osm and adds the to walk steps.

Issue

Closes #6078

@leonardehrenfried
Copy link
Member

We need to harmonise our approaches as #6082 does something similar.

@t2gran t2gran added this to the 2.7 (next release) milestone Oct 16, 2024
# Conflicts:
#	application/src/main/java/org/opentripplanner/model/plan/Entrance.java
#	application/src/main/java/org/opentripplanner/model/plan/StepEntity.java
#	application/src/main/java/org/opentripplanner/street/model/vertex/StationEntranceVertex.java
#	application/src/main/java/org/opentripplanner/street/model/vertex/VertexFactory.java
#	application/src/main/java/org/opentripplanner/transit/service/datafetchers/StepEntityTypeResolver.java
#	doc/user/BuildConfiguration.md
@optionsome optionsome self-requested a review October 22, 2024 08:41
@optionsome optionsome added Config Change bump serialization id Add this label if you want the serialization id automatically bumped after merging the PR labels Oct 24, 2024
@optionsome optionsome changed the title Add subway station entrances to walk steps If configured, add subway station entrances from OSM to walk steps Oct 24, 2024
@@ -61,6 +72,10 @@ public ZoneId getTimeZone() {
return timeZone;
}

public boolean getIncludeOsmSubwayEntrances() {
Copy link
Member

Choose a reason for hiding this comment

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

This could probably be just named includeOsmSubwayEntrances.

@@ -0,0 +1,3 @@
package org.opentripplanner.model.plan;

public abstract class StepEntity {}
Copy link
Member

Choose a reason for hiding this comment

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

We could discuss in a dev meeting if this is the best approach.

Comment on lines 7 to 14
public StationEntranceVertex(double x, double y, long nodeId, String entranceName) {
super(x, y, nodeId);
this.entranceName = entranceName;
}

public String getEntranceName() {
return entranceName;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be called entranceCode for the purpose we use. In the future, if we include entrances from GTFS with the same model, the name and code will be different things.

Copy link
Member

Choose a reason for hiding this comment

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

Or perhaps just code.

Copy link
Member

@t2gran t2gran Oct 25, 2024

Choose a reason for hiding this comment

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

Why not publicCode ?

Copy link
Member

Choose a reason for hiding this comment

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

In GTFS terminology, it's called stop_code in stops.txt. I'm not a native english speaker, but public code doesn't make it more understandable for me vs code.

Copy link
Member

Choose a reason for hiding this comment

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

public say it is used as information to the public. There are also other codes used for other things, like privateCode used by agencies for internal references.

public Object getEntity() {
return entity;
}

Copy link
Member

@t2gran t2gran Oct 24, 2024

Choose a reason for hiding this comment

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

I would like to se a diagram with boxes - forget about the class design for a moment and just draw the things we want to add in the future (next 1- 2 years). Then we can discuss how to group them and map the relationship.

Return an Object is no-go, and so is Entrance extends StepEntity.

Copy link
Member

Choose a reason for hiding this comment

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

I drew some sort of a process diagram with boxes together with @HenrikSundell.

entity-diagram

Copy link
Member

Choose a reason for hiding this comment

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

I think this method should probably still return StepEntity instead of Object but I think the step impl must return an Object for the entity which is then handled by StepEntityTypeResolver. It's possible that instead of doing the instanceof checks that are currently done to return correct schema types, we could cast the object to a StepEntity and then check if entrance field is non-null, or escalator field is non-null etc., but I'm not sure how much cleaner that solution is.

Copy link
Member

Choose a reason for hiding this comment

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

I just quickly tested and seems like it's possible to define a class that is used for an union from GraphQL (through codegen configuration). So with this current setup where the different entity types would have a shared base class, you could use that for the union. However, if they don't, then you need to return an Object from the stepImpl#entity() method.

Copy link
Member

Choose a reason for hiding this comment

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

New diagram
step-elements

Comment on lines 31 to 37
return entrance.getName() != null
? org.opentripplanner.framework.graphql.GraphQLUtils.getTranslation(
entrance.getName(),
environment
)
: null;
};
Copy link
Member

Choose a reason for hiding this comment

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

import org.opentripplanner.framework.graphql.GraphQLUtils and just use GraphQLUtils.getTranslation. Also, you can mark the input parameter in the getTranslation method as nullable and just pass in the entrance's name to the method as it does the null checks.

Copy link
Author

Choose a reason for hiding this comment

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

The reason for the full path is that org.opentripplanner.apis.gtfs.GraphQLUtils is already imported.

@@ -130,6 +134,13 @@ public String getExit() {
return exit;
}

/**
* Get information about building entrance or exit.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should say "subway stations's entrance" instead of building here. Also since there is already getExit here, maybe rename this and the highway exit rename methods so it's really clear that one is for highways, and the other is for stations.

// don't care what came before or comes after
var step = createWalkStep(forwardState, backState);

step.withRelativeDirection(RelativeDirection.ENTER_OR_EXIT_STATION);
Copy link
Member

Choose a reason for hiding this comment

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

You could add a comment here to explain that figuring out if something is an entrance or exit is difficult here.

private final String code;
private final boolean accessible;

public StationEntranceVertex(double x, double y, long nodeId, String code, boolean accessible) {
Copy link
Member

Choose a reason for hiding this comment

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

There is already a class called TransitEntranceVertex. I think we could probably use that instead of this. Although, I don't know if we should reserve the use of it just for pathways? Thoughts @leonardehrenfried ?

Copy link
Member

Choose a reason for hiding this comment

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

We decided we try to reuse the TransitEntranceVertex.

@@ -444,6 +444,18 @@ type Emissions {
co2: Grams
}

"Station entrance or exit."
Copy link
Member

Choose a reason for hiding this comment

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

You could clarify here that this can originate either from GTFS or from OSM.

type Entrance {
"Short text or a number that identifies the entrance or exit for passengers. For example, `A` or `B`."
code: String
"ID of the entrance in the format of `FeedId:EntranceId`."
Copy link
Member

Choose a reason for hiding this comment

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

Same here, you could mention that if the feed is osm, the entrance is from OSM data.

"Short text or a number that identifies the entrance or exit for passengers. For example, `A` or `B`."
code: String
"ID of the entrance in the format of `FeedId:EntranceId`."
entranceId: String
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
entranceId: String
entranceId: String!

@@ -2645,6 +2657,8 @@ type step {
distance: Float
"The elevation profile as a list of { distance, elevation } values."
elevationProfile: [elevationProfileComponent]
"Information about an station entrance or exit"
entrance: Entrance
Copy link
Member

Choose a reason for hiding this comment

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

Unless I'm totally mistaken, I think on this API level we still want to have the entity field which returns an entity union.

Copy link

codecov bot commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 59.00000% with 41 lines in your changes missing coverage. Please review.

Project coverage is 69.70%. Comparing base (2ead4da) to head (18b84f0).
Report is 143 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...ing/algorithm/mapping/StatesToWalkStepsMapper.java 0.00% 15 Missing and 1 partial ⚠️
...ner/street/model/vertex/StationEntranceVertex.java 0.00% 8 Missing ⚠️
...nner/graph_builder/module/osm/VertexGenerator.java 33.33% 3 Missing and 1 partial ⚠️
...ipplanner/apis/gtfs/datafetchers/EntranceImpl.java 78.57% 3 Missing ⚠️
...pis/gtfs/datafetchers/StepFeatureTypeResolver.java 66.66% 1 Missing and 1 partial ⚠️
..._builder/module/configure/GraphBuilderModules.java 0.00% 2 Missing ⚠️
...ner/graph_builder/module/osm/OsmModuleBuilder.java 33.33% 2 Missing ⚠️
...ntripplanner/apis/gtfs/generated/GraphQLTypes.java 0.00% 1 Missing ⚠️
...main/java/org/opentripplanner/osm/OsmProvider.java 66.66% 1 Missing ⚠️
...in/java/org/opentripplanner/osm/model/OsmNode.java 0.00% 1 Missing ⚠️
... and 1 more
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6076      +/-   ##
=============================================
- Coverage      69.75%   69.70%   -0.06%     
- Complexity     17657    17704      +47     
=============================================
  Files           2007     2011       +4     
  Lines          75573    75899     +326     
  Branches        7734     7764      +30     
=============================================
+ Hits           52716    52902     +186     
- Misses         20144    20279     +135     
- Partials        2713     2718       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Copy link
Member

@optionsome optionsome left a comment

Choose a reason for hiding this comment

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

We discussed yesterday in a developer meeting if ENTER_OR_EXIT_STATION needs to be exposed through the API at all or should we just use CONTINUE. I've thought about this a bit more and I think I would be ok with just using CONTINUE but we need to document on the enum in the schema that it's used also when going through entrances and we don't know into what direction. We can still keep the ENTER_OR_EXIT_STATION in the internal model but just map it into CONTINUE on API level.

private final String code;
private final boolean accessible;

public StationEntranceVertex(double x, double y, long nodeId, String code, boolean accessible) {
Copy link
Member

Choose a reason for hiding this comment

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

We decided we try to reuse the TransitEntranceVertex.

@@ -3328,6 +3345,7 @@ enum RelativeDirection {
CONTINUE
Copy link
Member

Choose a reason for hiding this comment

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

Add description for this enum value. Maybe we could add descriptions for some other values in this enum as well as not all of them are clear.

.withCoordinate(new WgsCoordinate(coordinate))
.withCode(ref)
.withWheelchairAccessibility(
accessible ? Accessibility.POSSIBLE : Accessibility.NOT_POSSIBLE
Copy link
Member

Choose a reason for hiding this comment

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

Should we also check if the tag is defined? If not, the value should be NO_INFORMATION.

@@ -356,19 +354,19 @@ private StreetVertex link(
ll.getSegmentIndex() == 0 &&
(ll.getSegmentFraction() < 1e-8 || ll.getSegmentFraction() * length < 0.1)
) {
start = (IntersectionVertex) edge.getFromVertex();
start = (Vertex) edge.getFromVertex();
Copy link
Member

Choose a reason for hiding this comment

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

Are these casts necessary here?

@@ -380,7 +378,7 @@ else if (
if (!linkedAreas.add(ael)) {
return null;
}
if (vertex instanceof IntersectionVertex iv) {
if (vertex instanceof Vertex iv) {
Copy link
Member

Choose a reason for hiding this comment

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

Are there vertices which are not instance of vertex?

Comment on lines 30 to 34
protected StreetTransitEntityLink(
StreetVertex fromv,
T tov,
Vertex fromv,
TransitEntranceVertex tov,
Accessibility wheelchairAccessibility
) {
Copy link
Member

Choose a reason for hiding this comment

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

Would it be enough to have a constructor that accepts (Vertex, Vertex, Accessibility)?

@@ -3328,6 +3345,7 @@ enum RelativeDirection {
CONTINUE
DEPART
ELEVATOR
ENTER_OR_EXIT_STATION
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to expose this enum value to users, it should be mapped to CONTINUE.

Comment on lines +22 to +25
import org.opentripplanner.street.search.TraverseMode;
import org.opentripplanner.street.search.state.State;
import org.opentripplanner.transit.model.basic.Accessibility;
import org.opentripplanner.transit.model.site.AreaStop;
Copy link
Member

Choose a reason for hiding this comment

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

These imports (o.o.street.search and o.o.transit) is to me a "code smell". Does it create circular dependencies?

@@ -35,6 +42,8 @@ public abstract class Vertex implements AStarVertex<State, Edge, Vertex>, Serial

private transient Edge[] outgoing = new Edge[0];
private RentalRestrictionExtension rentalRestrictions = RentalRestrictionExtension.NO_RESTRICTION;
private static final Set<AreaStop> EMPTY_SET = Set.of();
private Set<AreaStop> areaStops = EMPTY_SET;
Copy link
Member

Choose a reason for hiding this comment

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

Very few Vertexes have areaStops, I am not an expert on the AStar routing and design, but this does not look right to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump serialization id Add this label if you want the serialization id automatically bumped after merging the PR Config Change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Subway entrance names
4 participants