Package org.opentripplanner.routing.edgetype

Examples of org.opentripplanner.routing.edgetype.Timetable


             */
            int minDelta = Integer.MAX_VALUE;
            int actDelta = 0;
            for (ServiceDay serviceDay : ctx.serviceDays) {
                TripPattern pattern = nextStop.getTripPattern();
                Timetable timetable = pattern.getUpdatedTimetable(opt, serviceDay);
                // Get the tripTimes including real-time updates for the serviceDay
                TripTimes tripTimes = timetable.getTripTimes(timetable.getTripIndex(tripId));

                int depTime = tripTimes.getDepartureTime(bestStopIndex);
                int arrTime = tripTimes.getArrivalTime(bestStopIndex + 1);
                int estTime = (int) Math.round(
                        depTime * fractionCovered + arrTime * (1 - fractionCovered));

                int time = serviceDay.secondsSinceMidnight(opt.dateTime);
                /*
                 * TODO Weight differently early vs late time, as the probability of any transit
                 * being late is higher than being early. However, this has impact if your bus is
                 * more than 12h late, I don't think this would happen really often.
                 */
                int deltaTime = Math.abs(time - estTime);
                if (deltaTime < minDelta) {
                    minDelta = deltaTime;
                    actDelta = time - estTime;
                    bestTripTimes = tripTimes;
                    bestServiceDay = serviceDay;
                }
            }
            if (minDelta > 60000) LOG.warn(       // Being more than 1h late should not happen often
                    "On-board depart: delta between scheduled/real-time and actual time suspiciously large: {} seconds.",
                    actDelta);
            else LOG.info(
                    "On-board depart: delta between scheduled/real-time and actual time is {} seconds.",
                    actDelta);
        } else {
            /* 2. Compute service day */
            for (ServiceDay serviceDay : ctx.serviceDays) {
                Timetable timetable = tripPattern.getUpdatedTimetable(opt, serviceDay);
                // Get the tripTimes including real-time updates for the serviceDay
                TripTimes tripTimes = timetable.getTripTimes(timetable.getTripIndex(tripId));

                int depTime = tripTimes.getDepartureTime(0);
                int arrTime = tripTimes.getArrivalTime(tripTimes.getNumStops() - 1);

                int time = serviceDay.secondsSinceMidnight(opt.dateTime);
View Full Code Here


        req.setRoutingContext(graph, (Vertex)null, (Vertex)null);
        State state = new State(req);
        for (TripPattern pattern : patternsForStop.get(stop)) {
            StopTimesInPattern times = new StopTimesInPattern(pattern);
            // Should actually be getUpdatedTimetable
            Timetable table = pattern.scheduledTimetable;
            // A Stop may occur more than once in a pattern, so iterate over all Stops.
            int sidx = 0;
            for (Stop currStop : table.pattern.stopPattern.stops) {
                if (currStop != stop) continue;
                for (ServiceDay sd : req.rctx.serviceDays) {
                    TripTimes tt = table.getNextTrip(state, sd, sidx, true);
                    if (tt != null) {
                        times.times.add(new TripTimeShort(tt, sidx, stop));
                    }
                }
                sidx++;
View Full Code Here

   public Response getStoptimesForTrip (@PathParam("tripId") String tripIdString) {
       AgencyAndId tripId = GtfsLibrary.convertIdFromString(tripIdString);
       Trip trip = index.tripForId.get(tripId);
       if (trip != null) {
           TripPattern pattern = index.patternForTrip.get(trip);
           Timetable table = pattern.scheduledTimetable;
           return Response.status(Status.OK).entity(TripTimeShort.fromTripTimes(table, trip)).build();
       } else {
           return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
       }
   }
View Full Code Here

     */
    private void applyUpdateToTripPattern(TripPattern pattern, String tripId, String stopId,
            int stopSeq, int arrive, int depart, ScheduleRelationship scheduleRelationship,
            int timestamp, ServiceDate serviceDate) throws ParseException {
        TimetableResolver snapshot = graph.timetableSnapshotSource.getTimetableSnapshot();
        Timetable timetable = snapshot.resolve(pattern, serviceDate);
        TimeZone timeZone = new SimpleTimeZone(-7, "PST");
        long today = serviceDate.getAsDate(timeZone).getTime() / 1000;
        TripDescriptor.Builder tripDescriptorBuilder = TripDescriptor.newBuilder();

        tripDescriptorBuilder.setTripId(tripId);

        StopTimeEvent.Builder departStopTimeEventBuilder = StopTimeEvent.newBuilder();
        StopTimeEvent.Builder arriveStopTimeEventBuilder = StopTimeEvent.newBuilder();

        departStopTimeEventBuilder.setTime(today + depart);
        arriveStopTimeEventBuilder.setTime(today + arrive);

        StopTimeUpdate.Builder stopTimeUpdateBuilder = StopTimeUpdate.newBuilder();

        stopTimeUpdateBuilder.setStopSequence(stopSeq);
        stopTimeUpdateBuilder.setDeparture(departStopTimeEventBuilder);
        stopTimeUpdateBuilder.setArrival(arriveStopTimeEventBuilder);
        stopTimeUpdateBuilder.setScheduleRelationship(scheduleRelationship);

        TripUpdate.Builder tripUpdateBuilder = TripUpdate.newBuilder();

        tripUpdateBuilder.setTrip(tripDescriptorBuilder);
        tripUpdateBuilder.addStopTimeUpdate(0, stopTimeUpdateBuilder);

        TripUpdate tripUpdate = tripUpdateBuilder.build();

        assertTrue(timetable.update(tripUpdate, timeZone, serviceDate));
    }
View Full Code Here

    private void applyUpdateToTripPattern(TripPattern pattern, String tripId, String stopId,
            int stopSeq, int arrive, int depart, ScheduleRelationship scheduleRelationship,
            int timestamp, ServiceDate serviceDate) throws ParseException {
        Graph graph = Context.getInstance().graph;
        TimetableResolver snapshot = graph.timetableSnapshotSource.getTimetableSnapshot();
        Timetable timetable = snapshot.resolve(pattern, serviceDate);
        TimeZone timeZone = new SimpleTimeZone(-7, "PST");
        long today = serviceDate.getAsDate(timeZone).getTime() / 1000;
        TripDescriptor.Builder tripDescriptorBuilder = TripDescriptor.newBuilder();

        tripDescriptorBuilder.setTripId(tripId);

        StopTimeEvent.Builder departStopTimeEventBuilder = StopTimeEvent.newBuilder();
        StopTimeEvent.Builder arriveStopTimeEventBuilder = StopTimeEvent.newBuilder();

        departStopTimeEventBuilder.setTime(today + depart);
        arriveStopTimeEventBuilder.setTime(today + arrive);

        StopTimeUpdate.Builder stopTimeUpdateBuilder = StopTimeUpdate.newBuilder();

        stopTimeUpdateBuilder.setStopSequence(stopSeq);
        stopTimeUpdateBuilder.setDeparture(departStopTimeEventBuilder);
        stopTimeUpdateBuilder.setArrival(arriveStopTimeEventBuilder);
        stopTimeUpdateBuilder.setScheduleRelationship(scheduleRelationship);

        TripUpdate.Builder tripUpdateBuilder = TripUpdate.newBuilder();

        tripUpdateBuilder.setTrip(tripDescriptorBuilder);
        tripUpdateBuilder.addStopTimeUpdate(0, stopTimeUpdateBuilder);

        TripUpdate tripUpdate = tripUpdateBuilder.build();

        assertTrue(timetable.update(tripUpdate, timeZone, serviceDate));
    }
View Full Code Here

        /* TripTimes grouped by the block ID and service ID of their trips. Must be a ListMultimap to allow sorting. */
        ListMultimap<BlockIdAndServiceId, TripTimes> tripTimesForBlock = ArrayListMultimap.create();

        LOG.info("Finding interlining trips based on block IDs.");
        for (TripPattern pattern : tripPatterns) {
            Timetable timetable = pattern.scheduledTimetable;
            /* TODO: Block semantics seem undefined for frequency trips, so skip them? */
            for (TripTimes tripTimes : timetable.tripTimes) {
                Trip trip = tripTimes.trip;
                if ( ! Strings.isNullOrEmpty(trip.getBlockId())) {
                    tripTimesForBlock.put(new BlockIdAndServiceId(trip), tripTimes);
View Full Code Here

        int tripIndex2 = pattern.scheduledTimetable.getTripIndex(tripId2);

        updater.applyTripUpdates(Arrays.asList(TripUpdate.parseFrom(cancellation)), "agency");

        TimetableResolver resolver = updater.getTimetableSnapshot();
        Timetable forToday = resolver.resolve(pattern, serviceDate);
        Timetable schedule = resolver.resolve(pattern, null);
        assertNotSame(forToday, schedule);
        assertNotSame(forToday.getTripTimes(tripIndex), schedule.getTripTimes(tripIndex));
        assertSame(forToday.getTripTimes(tripIndex2), schedule.getTripTimes(tripIndex2));

        TripTimes tripTimes = forToday.getTripTimes(tripIndex);
        for (int i = 0; i < tripTimes.getNumStops(); i++) {
            assertEquals(TripTimes.UNAVAILABLE, tripTimes.getDepartureTime(i));
            assertEquals(TripTimes.UNAVAILABLE, tripTimes.getArrivalTime(i));
View Full Code Here

        TripUpdate tripUpdate = tripUpdateBuilder.build();

        updater.applyTripUpdates(Arrays.asList(tripUpdate), "agency");

        TimetableResolver resolver = updater.getTimetableSnapshot();
        Timetable forToday = resolver.resolve(pattern, serviceDate);
        Timetable schedule = resolver.resolve(pattern, null);
        assertNotSame(forToday, schedule);
        assertNotSame(forToday.getTripTimes(tripIndex), schedule.getTripTimes(tripIndex));
        assertSame(forToday.getTripTimes(tripIndex2), schedule.getTripTimes(tripIndex2));
        assertEquals(1, forToday.getTripTimes(tripIndex).getArrivalDelay(1));
        assertEquals(1, forToday.getTripTimes(tripIndex).getDepartureDelay(1));
    }
View Full Code Here

TOP

Related Classes of org.opentripplanner.routing.edgetype.Timetable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.