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

Correct the display of flex legs #93

Merged
merged 3 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/ext/java/org/opentripplanner/ext/flex/FlexLegMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static public void fixFlexTripLeg(Leg leg, FlexTripEdge flexTripEdge) {
}

public static void addFlexPlaces(Leg leg, FlexTripEdge flexEdge, Locale requestedLocale) {
leg.from = Place.forStop(flexEdge.s1, flexEdge.flexTemplate.fromStopIndex, null);
leg.to = Place.forStop(flexEdge.s2, flexEdge.flexTemplate.toStopIndex, null);
leg.from = Place.forFlexStop(flexEdge.s1, flexEdge.getFromVertex(), flexEdge.flexTemplate.fromStopIndex, null);
leg.to = Place.forFlexStop(flexEdge.s2, flexEdge.getToVertex(), flexEdge.flexTemplate.toStopIndex, null);
}
}
5 changes: 3 additions & 2 deletions src/ext/java/org/opentripplanner/ext/flex/FlexRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import java.util.Locale;
import org.opentripplanner.common.model.T2;
import org.opentripplanner.ext.flex.flexpathcalculator.FlexPathCalculator;
import org.opentripplanner.ext.flex.flexpathcalculator.StreetFlexPathCalculator;
Expand Down Expand Up @@ -88,7 +89,7 @@ public FlexRouter(
}
}

public Collection<Itinerary> createFlexOnlyItineraries() {
public Collection<Itinerary> createFlexOnlyItineraries(Locale locale) {
calculateFlexAccessTemplates();
calculateFlexEgressTemplates();

Expand All @@ -103,7 +104,7 @@ public Collection<Itinerary> createFlexOnlyItineraries() {
StopLocation transferStop = template.getTransferStop();
if (this.flexEgressTemplates.stream().anyMatch(t -> t.getAccessEgressStop().equals(transferStop))) {
for(NearbyStop egress : streetEgressByStop.get(transferStop)) {
Itinerary itinerary = template.createDirectItinerary(egress, arriveBy, departureTime, startOfTime);
Itinerary itinerary = template.createDirectItinerary(egress, arriveBy, departureTime, startOfTime, locale);
if (itinerary != null) {
itineraries.add(itinerary);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public FlexAccessTemplate(
}

public Itinerary createDirectItinerary(
NearbyStop egress, boolean arriveBy, int departureTime, ZonedDateTime startOfTime
NearbyStop egress, boolean arriveBy, int departureTime, ZonedDateTime startOfTime,
Locale locale
) {
List<Edge> egressEdges = egress.edges;

Expand Down Expand Up @@ -89,7 +90,7 @@ public Itinerary createDirectItinerary(

Itinerary itinerary = GraphPathToItineraryMapper.generateItinerary(
new GraphPath(state),
Locale.ENGLISH
locale
);

ZonedDateTime zdt = startOfTime.plusSeconds(timeShift);
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/opentripplanner/model/plan/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ public static Place forStop(StopLocation stop, Integer stopIndex, Integer stopSe
.build();
}

public static Place forFlexStop(
StopLocation stop,
Vertex vertex,
Integer stopIndex,
Integer stopSequence
) {
// The actual vertex is used because the StopLocation coordinates may not be equal to the vertex's
// coordinates.
return defaults(vertex, stop.getName())
.vertexType(VertexType.TRANSIT)
.stop(stop)
.stopIndex(stopIndex)
.stopSequence(stopSequence)
.build();
}

public static Place forStop(TransitStopVertex vertex, String name) {
return defaults(vertex, name)
.vertexType(VertexType.TRANSIT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,18 @@ private static State[][] sliceStates(State[] states) {
int[] legIndexPairs = {0, states.length - 1};
List<int[]> legsIndexes = new ArrayList<int[]>();

TraverseMode lastMode = null;
for (int i = 1; i < states.length - 1; i++) {
var backState = states[i];
var forwardState = states[i + 1];
var backMode = backState.getBackMode();
var forwardMode = forwardState.getBackMode();

var modeChange = backMode != forwardMode && backMode != null && forwardMode != null;
if (backMode != null) {
lastMode = backMode;
}

var modeChange = lastMode != forwardMode && lastMode != null && forwardMode != null;
var parkingChange = backState.isVehicleParked() != forwardState.isVehicleParked();
var rentalChange = isRentalPickUp(backState) || isRentalDropOff(backState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static List<Itinerary> route(
egressStops
);

return new ArrayList<>(flexRouter.createFlexOnlyItineraries());
return new ArrayList<>(flexRouter.createFlexOnlyItineraries(request.locale));
}
}
}