use of org.opentripplanner.model.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 List<ApiStopShort> getStopsForRoute(@PathParam("routeId") String routeId) {
RoutingService routingService = createRoutingService();
Route route = getRoute(routingService, routeId);
Set<Stop> stops = new HashSet<>();
Collection<TripPattern> patterns = routingService.getPatternsForRoute().get(route);
for (TripPattern pattern : patterns) {
stops.addAll(pattern.getStops());
}
return StopMapper.mapToApiShort(stops);
}
use of org.opentripplanner.model.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 List<ApiTripShort> getTripsForRoute(@PathParam("routeId") String routeId) {
RoutingService routingService = createRoutingService();
Route route = getRoute(routingService, routeId);
List<Trip> trips = new ArrayList<>();
Collection<TripPattern> patterns = routingService.getPatternsForRoute().get(route);
for (TripPattern pattern : patterns) {
trips.addAll(pattern.getTrips());
}
return TripMapper.mapToApiShort(trips);
}
use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.
the class GenerateTripPatternsOperation method buildTripPatternForTrip.
private void buildTripPatternForTrip(Trip trip) {
// Check that the mode is supported
if (trip.getRoute().getMode() == null) {
issueStore.add(new GTFSModeNotSupported(trip, Integer.toString(trip.getRoute().getType())));
return;
}
// TODO: move to a validator module
if (!calendarServiceIds.contains(trip.getServiceId())) {
issueStore.add(new TripUndefinedService(trip));
// Invalid trip, skip it, it will break later
return;
}
int directionId = getDirectionId(trip);
Collection<StopTime> stopTimes = transitDaoBuilder.getStopTimesSortedByTrip().get(trip);
// If after filtering this trip does not contain at least 2 stoptimes, it does not serve any purpose.
if (stopTimes.size() < 2) {
issueStore.add(new TripDegenerate(trip));
return;
}
// Get the existing TripPattern for this filtered StopPattern, or create one.
StopPattern stopPattern = new StopPattern(stopTimes);
TripPattern tripPattern = findOrCreateTripPattern(stopPattern, trip.getRoute(), directionId);
// Create a TripTimes object for this list of stoptimes, which form one trip.
TripTimes tripTimes = new TripTimes(trip, stopTimes, deduplicator);
// If this trip is referenced by one or more lines in frequencies.txt, wrap it in a FrequencyEntry.
List<Frequency> frequencies = frequenciesForTrip.get(trip);
if (frequencies != null && !(frequencies.isEmpty())) {
for (Frequency freq : frequencies) {
tripPattern.add(new FrequencyEntry(freq, tripTimes));
freqCount++;
}
// TODO replace: createGeometry(graph, trip, stopTimes, hops);
} else // This trip was not frequency-based. Add the TripTimes directly to the TripPattern's scheduled timetable.
{
tripPattern.add(tripTimes);
scheduledCount++;
}
}
use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.
the class NetexMapper method mapTripPatterns.
private void mapTripPatterns(NetexImportDataIndexReadOnlyView netexIndex) {
TripPatternMapper tripPatternMapper = new TripPatternMapper(idFactory, transitBuilder.getStops(), transitBuilder.getRoutes(), transitBuilder.getShapePoints().keySet(), netexIndex.getRouteById(), netexIndex.getJourneyPatternsById(), netexIndex.getQuayIdByStopPointRef(), netexIndex.getDestinationDisplayById(), netexIndex.getServiceJourneyByPatternId(), deduplicator);
for (JourneyPattern journeyPattern : netexIndex.getJourneyPatternsById().localValues()) {
TripPatternMapper.Result result = tripPatternMapper.mapTripPattern(journeyPattern);
for (Map.Entry<Trip, List<StopTime>> it : result.tripStopTimes.entrySet()) {
transitBuilder.getStopTimesSortedByTrip().put(it.getKey(), it.getValue());
transitBuilder.getTripsById().add(it.getKey());
}
for (TripPattern it : result.tripPatterns) {
transitBuilder.getTripPatterns().put(it.stopPattern, it);
}
stopTimesByNetexId.putAll(result.stopTimeByNetexId);
}
}
use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.
the class OtpTransitServiceBuilder method fixOrRemovePatternsWhichReferenceNoneExistingTrips.
/**
* Remove none existing trips from patterns and then remove empty patterns
*/
private void fixOrRemovePatternsWhichReferenceNoneExistingTrips() {
int orgSize = tripPatterns.size();
List<Map.Entry<StopPattern, TripPattern>> removePatterns = new ArrayList<>();
for (Map.Entry<StopPattern, TripPattern> e : tripPatterns.entries()) {
TripPattern ptn = e.getValue();
ptn.removeTrips(t -> !tripsById.containsKey(t.getId()));
if (ptn.getTrips().isEmpty()) {
removePatterns.add(e);
}
}
for (Map.Entry<StopPattern, TripPattern> it : removePatterns) {
tripPatterns.remove(it.getKey(), it.getValue());
}
logRemove("TripPattern", orgSize, tripPatterns.size(), "No trips for pattern exist.");
}
Aggregations