use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.
the class SkipStop method apply.
@Override
public Collection<TripPattern> apply(TripPattern original) {
if (!couldMatch(original))
return Arrays.asList(original);
// figure out which stops we skip
TIntList skippedStops = new TIntArrayList();
// retained stops
// we use stop times to carry a little additional information, e.g. pickup/dropoff type.
List<StopTime> stopTimes = Lists.newArrayList();
{
int i = 0;
for (Stop stop : original.getStops()) {
if (stopId.contains(stop.getId().getId()))
skippedStops.add(i);
else {
// make a fake stop time
StopTime stopTime = new StopTime();
stopTime.setStop(stop);
stopTime.setPickupType(original.stopPattern.pickups[i]);
stopTime.setDropOffType(original.stopPattern.dropoffs[i]);
stopTimes.add(stopTime);
}
i++;
}
}
if (skippedStops.isEmpty()) {
LOG.warn("No stops found to skip on matched trip pattern {}", original);
return Arrays.asList(original);
}
if (original.getStops().size() - skippedStops.size() < 2) {
// TODO best way to handle this case?
LOG.warn("Trip with skipped stops would have less that two stops for TripPattern {}, not skipping stops", original);
return Arrays.asList(original);
}
// make the new stop pattern
StopPattern sp = new StopPattern(stopTimes);
TripPattern modified = new TripPattern(original.route, sp);
// Any trips that are not matched keep the original trip pattern, so put them here.
TripPattern originalClone = new TripPattern(original.route, original.stopPattern);
// keep track of what we have to return
boolean anyTripsMatched = false;
boolean allTripsMatched = true;
for (TripTimes tt : original.scheduledTimetable.tripTimes) {
if (!matches(tt.trip)) {
// this trip should not be modified
allTripsMatched = false;
originalClone.scheduledTimetable.addTripTimes(tt);
} else {
// This trip should be modified
anyTripsMatched = true;
modified.scheduledTimetable.addTripTimes(omitStops(tt, skippedStops.toArray()));
}
}
for (FrequencyEntry fe : original.scheduledTimetable.frequencyEntries) {
if (!matches(fe.tripTimes.trip)) {
allTripsMatched = false;
originalClone.scheduledTimetable.addFrequencyEntry(fe);
} else {
anyTripsMatched = true;
TripTimes newtt = omitStops(fe.tripTimes, skippedStops.toArray());
FrequencyEntry newfe = new FrequencyEntry(fe.startTime, fe.endTime, fe.headway, fe.exactTimes, newtt);
modified.scheduledTimetable.addFrequencyEntry(newfe);
}
}
if (!anyTripsMatched)
return Arrays.asList(original);
List<TripPattern> ret = Lists.newArrayList();
ret.add(modified);
if (!allTripsMatched)
ret.add(originalClone);
return ret;
}
use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.
the class TimetableSnapshotSource method getPatternForTripId.
/**
* Retrieve a trip pattern given a feed id and trid id.
*
* @param feedId feed id for the trip id
* @param tripId trip id without agency
* @return trip pattern or null if no trip pattern was found
*/
private TripPattern getPatternForTripId(String feedId, String tripId) {
Trip trip = graphIndex.tripForId.get(new AgencyAndId(feedId, tripId));
TripPattern pattern = graphIndex.patternForTrip.get(trip);
return pattern;
}
use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getTripsForRoute.
/**
* Return all trips in any pattern on the given route.
*/
@GET
@Path("/routes/{routeId}/trips")
public Response getTripsForRoute(@PathParam("routeId") String routeIdString) {
AgencyAndId routeId = GtfsLibrary.convertIdFromString(routeIdString);
Route route = index.routeForId.get(routeId);
if (route != null) {
List<Trip> trips = Lists.newArrayList();
Collection<TripPattern> patterns = index.patternsForRoute.get(route);
for (TripPattern pattern : patterns) {
trips.addAll(pattern.getTrips());
}
return Response.status(Status.OK).entity(TripShort.list(trips)).build();
} else {
return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
}
}
use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getStopsForTrip.
@GET
@Path("/trips/{tripId}/stops")
public Response getStopsForTrip(@PathParam("tripId") String tripIdString) {
AgencyAndId tripId = GtfsLibrary.convertIdFromString(tripIdString);
Trip trip = index.tripForId.get(tripId);
if (trip != null) {
TripPattern pattern = index.patternForTrip.get(trip);
Collection<Stop> stops = pattern.getStops();
return Response.status(Status.OK).entity(StopShort.list(stops)).build();
} else {
return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
}
}
use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getStopsForRoute.
/**
* Return all stops in any pattern on a given route.
*/
@GET
@Path("/routes/{routeId}/stops")
public Response getStopsForRoute(@PathParam("routeId") String routeIdString) {
AgencyAndId routeId = GtfsLibrary.convertIdFromString(routeIdString);
Route route = index.routeForId.get(routeId);
if (route != null) {
Set<Stop> stops = Sets.newHashSet();
Collection<TripPattern> patterns = index.patternsForRoute.get(route);
for (TripPattern pattern : patterns) {
stops.addAll(pattern.getStops());
}
return Response.status(Status.OK).entity(StopShort.list(stops)).build();
} else {
return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
}
}
Aggregations