Search in sources :

Example 6 with ServiceDate

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);
}
Also used : TripTimeShort(org.opentripplanner.model.TripTimeShort) ServiceDate(org.opentripplanner.model.calendar.ServiceDate)

Example 7 with ServiceDate

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);
}
Also used : ServiceDate(org.opentripplanner.model.calendar.ServiceDate) ApiStop(org.opentripplanner.api.model.ApiStop) Stop(org.opentripplanner.model.Stop) RoutingService(org.opentripplanner.routing.RoutingService) StopTimesInPattern(org.opentripplanner.model.StopTimesInPattern) ApiStopTimesInPattern(org.opentripplanner.api.model.ApiStopTimesInPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 8 with ServiceDate

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;
}
Also used : ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) HashSet(java.util.HashSet) ServiceCalendar(org.opentripplanner.model.calendar.ServiceCalendar)

Example 9 with ServiceDate

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;
    }
}
Also used : ServiceDate(org.opentripplanner.model.calendar.ServiceDate) ServiceCalendar(org.opentripplanner.model.calendar.ServiceCalendar) Calendar(java.util.Calendar) Date(java.util.Date) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate)

Example 10 with ServiceDate

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);
}
Also used : ServiceDate(org.opentripplanner.model.calendar.ServiceDate)

Aggregations

ServiceDate (org.opentripplanner.model.calendar.ServiceDate)40 FeedScopedId (org.opentripplanner.model.FeedScopedId)15 ArrayList (java.util.ArrayList)11 TripPattern (org.opentripplanner.model.TripPattern)10 Test (org.junit.Test)9 Stop (org.opentripplanner.model.Stop)9 Trip (org.opentripplanner.model.Trip)9 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)8 Date (java.util.Date)8 HashSet (java.util.HashSet)7 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)6 ZonedDateTime (java.time.ZonedDateTime)6 TripTimeShort (org.opentripplanner.model.TripTimeShort)6 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)6 Calendar (java.util.Calendar)5 Timetable (org.opentripplanner.model.Timetable)4 ServiceCalendarDate (org.opentripplanner.model.calendar.ServiceCalendarDate)4 EstimatedCall (uk.org.siri.siri20.EstimatedCall)4 TimetableHelper.createUpdatedTripTimes (org.opentripplanner.ext.siri.TimetableHelper.createUpdatedTripTimes)3 Route (org.opentripplanner.model.Route)3