use of org.opentripplanner.model.TripTimeShort in project OpenTripPlanner by opentripplanner.
the class TripTimeShortHelper method getIntermediateTripTimeShortsForLeg.
/**
* Find trip time shorts for all intermediate stops for a leg.
*/
public List<TripTimeShort> getIntermediateTripTimeShortsForLeg(Leg leg, RoutingService routingService) {
if (!leg.isTransitLeg()) {
return List.of();
}
ServiceDate serviceDate = leg.serviceDate;
List<TripTimeShort> tripTimes = routingService.getTripTimesShort(leg.getTrip(), serviceDate);
List<TripTimeShort> filteredTripTimes = new ArrayList<>();
long startTimeSeconds = (leg.startTime.toInstant().toEpochMilli() - serviceDate.getAsDate().getTime()) / 1000;
long endTimeSeconds = (leg.endTime.toInstant().toEpochMilli() - serviceDate.getAsDate().getTime()) / 1000;
boolean boardingStopFound = false;
for (TripTimeShort tripTime : tripTimes) {
long boardingTime = leg.realTime ? tripTime.realtimeDeparture : tripTime.scheduledDeparture;
if (!boardingStopFound) {
boardingStopFound = boardingTime == startTimeSeconds && matchesQuayOrSiblingQuay(leg.from.stopId, tripTime.stopId, routingService);
continue;
}
long arrivalTime = leg.realTime ? tripTime.realtimeArrival : tripTime.scheduledArrival;
if (arrivalTime == endTimeSeconds && matchesQuayOrSiblingQuay(leg.to.stopId, tripTime.stopId, routingService)) {
break;
}
filteredTripTimes.add(tripTime);
}
return filteredTripTimes;
}
use of org.opentripplanner.model.TripTimeShort in project OpenTripPlanner by opentripplanner.
the class TripTimeShortHelper method getTripTimeShortForToPlace.
/**
* Find trip time short for the to place in transit leg, or null.
*/
public TripTimeShort getTripTimeShortForToPlace(Leg leg, RoutingService routingService) {
if (!leg.isTransitLeg()) {
return null;
}
ServiceDate serviceDate = leg.serviceDate;
List<TripTimeShort> tripTimes = routingService.getTripTimesShort(leg.getTrip(), serviceDate);
long endTimeSeconds = (leg.endTime.toInstant().toEpochMilli() - serviceDate.getAsDate().getTime()) / 1000;
if (leg.realTime) {
return tripTimes.stream().filter(tripTime -> tripTime.realtimeArrival == endTimeSeconds && matchesQuayOrSiblingQuay(leg.to.stopId, tripTime.stopId, routingService)).findFirst().orElse(null);
}
return tripTimes.stream().filter(tripTime -> tripTime.scheduledArrival == endTimeSeconds && matchesQuayOrSiblingQuay(leg.to.stopId, tripTime.stopId, routingService)).findFirst().orElse(null);
}
use of org.opentripplanner.model.TripTimeShort in project OpenTripPlanner by opentripplanner.
the class LegacyGraphQLNodeTypeResolver method getType.
@Override
public GraphQLObjectType getType(TypeResolutionEnvironment environment) {
Object o = environment.getObject();
GraphQLSchema schema = environment.getSchema();
if (o instanceof Agency)
return schema.getObjectType("Agency");
if (o instanceof TransitAlert)
return schema.getObjectType("Alert");
if (o instanceof BikePark)
return schema.getObjectType("BikePark");
if (o instanceof BikeRentalStation)
return schema.getObjectType("BikeRentalStation");
// if (o instanceof Cluster) return schema.getObjectType("Cluster");
if (o instanceof PatternAtStop)
return schema.getObjectType("DepartureRow");
if (o instanceof TripPattern)
return schema.getObjectType("Pattern");
if (o instanceof PlaceAtDistance)
return schema.getObjectType("placeAtDistance");
if (o instanceof Route)
return schema.getObjectType("Route");
if (o instanceof Stop)
return schema.getObjectType("Stop");
if (o instanceof Station)
return schema.getObjectType("Stop");
if (o instanceof TripTimeShort)
return schema.getObjectType("Stoptime");
if (o instanceof StopAtDistance)
return schema.getObjectType("stopAtDistance");
if (o instanceof FareRuleSet)
return schema.getObjectType("TicketType");
if (o instanceof Trip)
return schema.getObjectType("Trip");
return null;
}
use of org.opentripplanner.model.TripTimeShort in project OpenTripPlanner by opentripplanner.
the class StopTimesHelper method stopTimesForStop.
/**
* Fetch upcoming vehicle departures from a stop.
* It goes though all patterns passing the stop for the previous, current and next service date.
* It uses a priority queue to keep track of the next departures. The queue is shared between all
* dates, as services from the previous service date can visit the stop later than the current
* service date's services. This happens eg. with sleeper trains.
*
* TODO: Add frequency based trips
* @param stop Stop object to perform the search for
* @param startTime Start time for the search. Seconds from UNIX epoch
* @param timeRange Searches forward for timeRange seconds from startTime
* @param numberOfDepartures Number of departures to fetch per pattern
* @param omitNonPickups If true, do not include vehicles that will not pick up passengers.
*/
public static List<StopTimesInPattern> stopTimesForStop(RoutingService routingService, TimetableSnapshot timetableSnapshot, Stop stop, long startTime, int timeRange, int numberOfDepartures, boolean omitNonPickups) {
if (startTime == 0) {
startTime = System.currentTimeMillis() / 1000;
}
List<StopTimesInPattern> ret = new ArrayList<>();
Date date = new Date(startTime * 1000);
ServiceDate[] serviceDates = { new ServiceDate(date).previous(), new ServiceDate(date), new ServiceDate(date).next() };
Collection<TripPattern> patternsForStop = routingService.getPatternsForStop(stop, true);
for (TripPattern pattern : patternsForStop) {
Queue<TripTimeShort> pq = listTripTimeShortsForPatternAtStop(routingService, timetableSnapshot, stop, pattern, startTime, timeRange, numberOfDepartures, omitNonPickups, serviceDates);
if (pq.size() != 0) {
StopTimesInPattern stopTimes = new StopTimesInPattern(pattern);
while (pq.size() != 0) {
stopTimes.times.add(0, pq.poll());
}
ret.add(stopTimes);
}
}
return ret;
}
use of org.opentripplanner.model.TripTimeShort in project OpenTripPlanner by opentripplanner.
the class LegacyGraphQLStopImpl method stopTimesForPattern.
@Override
public DataFetcher<Iterable<TripTimeShort>> stopTimesForPattern() {
return environment -> getValue(environment, stop -> {
RoutingService routingService = getRoutingService(environment);
LegacyGraphQLTypes.LegacyGraphQLStopStopTimesForPatternArgs args = new LegacyGraphQLTypes.LegacyGraphQLStopStopTimesForPatternArgs(environment.getArguments());
TripPattern pattern = routingService.getTripPatternForId(FeedScopedId.parseId(args.getLegacyGraphQLId()));
if (pattern == null) {
return null;
}
;
return routingService.stopTimesForPatternAtStop(stop, pattern, args.getLegacyGraphQLStartTime(), args.getLegacyGraphQLTimeRange(), args.getLegacyGraphQLNumberOfDepartures(), args.getLegacyGraphQLOmitNonPickups());
}, station -> null);
}
Aggregations