use of org.opentripplanner.transit.raptor.speed_test.model.Itinerary in project OpenTripPlanner by opentripplanner.
the class ItineraryMapper method createItinerary.
private Itinerary createItinerary(Path<TripSchedule> path, StopAtDistance accessPath, StopAtDistance egressPath) {
if (path == null) {
return null;
}
Itinerary itinerary = new Itinerary();
itinerary.walkDistance = 0.0;
itinerary.transitTime = 0;
itinerary.waitingTime = 0;
itinerary.weight = path.cost();
int numberOfTransits = 0;
// Access leg
Leg leg = new Leg();
AccessPathLeg<TripSchedule> accessLeg = path.accessLeg();
leg.startTime = accessLeg.fromTime();
leg.endTime = accessLeg.toTime();
leg.from = request.tc().fromPlace;
leg.to = request.tc().toPlace;
leg.mode = WALK;
leg.distance = accessPath.distance;
itinerary.addLeg(leg);
PathLeg<TripSchedule> pathLeg = accessLeg.nextLeg();
int previousArrivalTime = -1;
while (pathLeg.isTransitLeg() || pathLeg.isTransferLeg()) {
leg = new Leg();
// Transfer leg if present
if (pathLeg.isTransferLeg()) {
TransferPathLeg<?> it = pathLeg.asTransferLeg();
previousArrivalTime = it.toTime();
leg.startTime = it.fromTime();
leg.endTime = previousArrivalTime;
leg.mode = WALK;
leg.from = mapToPlace(it.fromStop());
leg.to = mapToPlace(it.toStop());
// distanceMMToMeters (transferPath.getDistance());
leg.distance = -1.0;
} else {
// Transit leg
TransitPathLeg<TripSchedule> it = pathLeg.asTransitLeg();
itinerary.transitTime += it.toTime() - it.fromTime();
itinerary.waitingTime += it.fromTime() - previousArrivalTime;
previousArrivalTime = it.toTime();
++numberOfTransits;
leg.distance = 0.0;
TripSchedule tripSchedule = it.trip();
TripPattern tripPattern = tripSchedule.getOriginalTripPattern();
Route routeInfo = tripPattern.route;
leg.from = mapToPlace(it.fromStop());
leg.to = mapToPlace(it.toStop());
leg.route = routeInfo.getShortName();
leg.agencyName = routeInfo.getAgency().getName();
leg.tripShortName = tripSchedule.getOriginalTripPattern().name;
leg.agencyId = routeInfo.getAgency().getId();
leg.routeShortName = routeInfo.getShortName();
leg.routeLongName = routeInfo.getLongName();
leg.mode = TraverseMode.fromTransitMode(tripSchedule.getOriginalTripPattern().getMode());
leg.startTime = it.fromTime();
leg.endTime = it.toTime();
}
itinerary.addLeg(leg);
pathLeg = pathLeg.nextLeg();
}
// Egress leg
leg = new Leg();
EgressPathLeg<TripSchedule> egressLeg = pathLeg.asEgressLeg();
leg.startTime = egressLeg.fromTime();
leg.endTime = egressLeg.toTime();
leg.from = mapToPlace(egressLeg.fromStop());
leg.to = request.tc().toPlace;
leg.mode = WALK;
leg.distance = egressPath.distance;
itinerary.addLeg(leg);
itinerary.startTime = itinerary.legs.get(0).startTime;
itinerary.endTime = leg.endTime;
itinerary.duration = itinerary.endTime - itinerary.startTime;
// The number of transfers is the number of transits minus one, we can NOT count the number of Transfers
// in the path or itinerary, because transfers at the same stop does not produce a transfer object, just two
// transits following each other.
itinerary.transfers = numberOfTransits - 1;
return itinerary;
}
use of org.opentripplanner.transit.raptor.speed_test.model.Itinerary in project OpenTripPlanner by opentripplanner.
the class ItineraryMapper method mapItineraries.
public static List<Itinerary> mapItineraries(SpeedTestRequest request, Collection<Path<TripSchedule>> paths, EgressAccessRouter streetRouter, TransitLayer transitLayer) {
ItineraryMapper mapper = new ItineraryMapper(request, transitLayer);
List<Itinerary> itineraries = new ArrayList<>();
for (Path<TripSchedule> p : paths) {
int accessToStopIndex = p.accessLeg().toStop();
int egressToStopIndex = p.egressLeg().fromStop();
Itinerary itinerary = mapper.createItinerary(p, streetRouter.getAccessPath(accessToStopIndex), streetRouter.getEgressPath(egressToStopIndex));
itineraries.add(itinerary);
}
return itineraries;
}
Aggregations