use of org.opentripplanner.model.calendar.ServiceDate 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.calendar.ServiceDate in project OpenTripPlanner by opentripplanner.
the class IndexAPI method getStoptimesForStopAndDate.
/**
* Return upcoming vehicle arrival/departure times at the given stop.
* @param date in YYYYMMDD or YYYY-MM-DD format
*/
@GET
@Path("/stops/{stopId}/stoptimes/{date}")
public List<ApiStopTimesInPattern> getStoptimesForStopAndDate(@PathParam("stopId") String stopId, @PathParam("date") String date, @QueryParam("omitNonPickups") boolean omitNonPickups) {
RoutingService routingService = createRoutingService();
Stop stop = getStop(routingService, stopId);
ServiceDate serviceDate = parseServiceDate("date", date);
List<StopTimesInPattern> stopTimes = routingService.getStopTimesForStop(stop, serviceDate, omitNonPickups);
return StopTimesInPatternMapper.mapToApi(stopTimes);
}
use of org.opentripplanner.model.calendar.ServiceDate in project OpenTripPlanner by opentripplanner.
the class CalendarServiceDataFactoryImpl method getServiceDatesForServiceId.
private Set<ServiceDate> getServiceDatesForServiceId(FeedScopedId serviceId, TimeZone serviceIdTimeZone) {
Set<ServiceDate> activeDates = new HashSet<>();
ServiceCalendar c = findCalendarForServiceId(serviceId);
if (c != null) {
addDatesFromCalendar(c, serviceIdTimeZone, activeDates);
}
List<ServiceCalendarDate> dates = calendarDatesByServiceId.get(serviceId);
if (dates != null) {
for (ServiceCalendarDate cd : dates) {
addAndRemoveDatesFromCalendarDate(cd, activeDates);
}
}
return activeDates;
}
use of org.opentripplanner.model.calendar.ServiceDate in project OpenTripPlanner by opentripplanner.
the class CalendarServiceDataFactoryImpl method addAndRemoveDatesFromCalendarDate.
private void addAndRemoveDatesFromCalendarDate(ServiceCalendarDate calendarDate, Set<ServiceDate> activeDates) {
ServiceDate serviceDate = calendarDate.getDate();
Date targetDate = calendarDate.getDate().getAsDate();
Calendar c = Calendar.getInstance();
c.setTime(targetDate);
switch(calendarDate.getExceptionType()) {
case ServiceCalendarDate.EXCEPTION_TYPE_ADD:
addServiceDate(activeDates, serviceDate);
break;
case ServiceCalendarDate.EXCEPTION_TYPE_REMOVE:
activeDates.remove(serviceDate);
break;
default:
LOG.warn("unknown CalendarDate exception type: " + calendarDate.getExceptionType());
break;
}
}
use of org.opentripplanner.model.calendar.ServiceDate in project OpenTripPlanner by opentripplanner.
the class TimetableSnapshotSource method purgeExpiredData.
private boolean purgeExpiredData() {
final ServiceDate today = new ServiceDate();
// TODO: Base this on numberOfDaysOfLongestTrip for tripPatterns
// Just to be safe...
final ServiceDate previously = today.previous().previous();
// Purge data only if we have changed date
if (lastPurgeDate != null && lastPurgeDate.compareTo(previously) >= 0) {
return false;
}
LOG.debug("purging expired realtime data");
lastPurgeDate = previously;
return buffer.purgeExpiredData(previously);
}
Aggregations