Search in sources :

Example 26 with ArrivalAndDepartureInstance

use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange06.

/**
 * This method tests to make sure upstream propagation isn't happening.
 *
 * Test configuration: Time point predictions are downstream of Stop A, which
 * means that the bus is predicted to have already passed the bus stop. There
 * only one bus stop (Stop B) which has a real time arrival time (time point
 * prediction). In this case getArrivalsAndDeparturesForStopInTimeRange() for
 * Stop A should return a predicted arrival time = 0, indicating that no
 * real-time information is available for Stop A.
 *
 * Current time = 14:00
 *          Schedule time    Real-time from feed
 * Stop A   13:30            -----
 * Stop B   13:45            13:40
 *
 * Since the bus already passed the bus stop A, and no real-time information
 * is available for Stop A, OBA should NOT propagate arrival estimate for Stop
 * B upstream to Stop A.
 */
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange06() {
    // Override the current time with a later time than the time point
    // predictions
    mCurrentTime = dateAsLong("2015-07-23 14:00");
    // Set time point predictions for stop B
    TimepointPredictionRecord tprB = new TimepointPredictionRecord();
    tprB.setTimepointId(mStopB.getId());
    long tprBTime = createPredictedTime(time(13, 40));
    tprB.setTimepointPredictedArrivalTime(tprBTime);
    tprB.setTripId(mTrip1.getId());
    // Call ArrivalsAndDeparturesForStopInTimeRange method in
    // ArrivalAndDepartureServiceImpl
    List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForStopInTimeRangeByTimepointPredictionRecord(Arrays.asList(tprB));
    long predictedArrivalTimeStopB = getPredictedArrivalTimeByStopId(arrivalsAndDepartures, mStopB.getId());
    /**
     * Check if the predictedArrivalTime for stop B is exactly the same as
     * TimepointPredictionRecord.
     */
    assertEquals(tprB.getTimepointPredictedArrivalTime(), predictedArrivalTimeStopB);
    /**
     * Check predicted departure for Stop B too, to make sure its propagated
     * from provided predicted arrival time
     */
    long scheduledArrivalTimeForStopB = getScheduledArrivalTimeByStopId(mTrip1, mStopB.getId());
    long scheduledDepartureTimeForStopB = getScheduledDepartureTimeByStopId(mTrip1, mStopB.getId());
    long predictedDepartureTimeStopB = getPredictedDepartureTimeByStopId(arrivalsAndDepartures, mStopB.getId());
    long deltaB = TimeUnit.MILLISECONDS.toSeconds(predictedArrivalTimeStopB) - scheduledArrivalTimeForStopB;
    assertEquals(scheduledDepartureTimeForStopB + deltaB, TimeUnit.MILLISECONDS.toSeconds(predictedDepartureTimeStopB));
    /**
     * Make sure the predictedArrivalTime for stop A is equals to 0 - in other
     * words, we should show no real-time information for this stop and use the
     * scheduled time instead.
     */
    long predictedArrivalTimeA = getPredictedArrivalTimeByStopId(arrivalsAndDepartures, mStopA.getId());
    assertEquals(0, predictedArrivalTimeA);
}
Also used : TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) Test(org.junit.Test)

Example 27 with ArrivalAndDepartureInstance

use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange09.

/**
 * This method tests loop routes (the same stop is visited more
 * than once in the same trip) when stop_sequence is missing in the real-time feed.
 * It applies the prediction if there is more than one prediction in the same trip
 * (i.e., the stop_id can be disambiguated).
 *
 * Test configuration: There are two time point predictions for the 2nd and the last stop.
 * But time point predictions do not have stop_sequences. There is a single trip
 * in the block.  In this case getArrivalsAndDeparturesForStopInTimeRange() for the
 * first instance of Stop A should not have any real-time data (i.e., the schedule time
 * should be shown).  The  Stop B should return a predicted arrival time =  13:50 (the prediction
 * for this stop). The last Stop A should return a predicted arrival time = 13:58
 * (the estimate for the last Stop A instance).
 *
 * Current time = 14:00
 *          Schedule time    Real-time from feed      GTFS stop_sequence
 * Stop A   13:30            -----                          0
 * Stop B   13:45            13:50                          1
 * Stop A   13:55            13:58                          2
 */
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange09() {
    // Override the current time with a later time than the time point
    // predictions
    mCurrentTime = dateAsLong("2015-07-23 14:00");
    // Set time point predictions for stop A (last instance)
    TimepointPredictionRecord tprA = new TimepointPredictionRecord();
    tprA.setTimepointId(mStopA.getId());
    long tprATime = createPredictedTime(time(13, 58));
    tprA.setTimepointPredictedArrivalTime(tprATime);
    tprA.setTripId(mTrip1.getId());
    // Set time point predictions for stop B
    TimepointPredictionRecord tprB = new TimepointPredictionRecord();
    tprB.setTimepointId(mStopB.getId());
    long tprBTime = createPredictedTime(time(13, 50));
    tprB.setTimepointPredictedArrivalTime(tprBTime);
    tprB.setTripId(mTrip1.getId());
    // Call ArrivalsAndDeparturesForStopInTimeRange method in
    // ArrivalAndDepartureServiceImpl
    List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord(Arrays.asList(tprB, tprA), mStopB);
    long predictedArrivalTimeStopB = getPredictedArrivalTimeByStopId(arrivalsAndDepartures, mStopB.getId());
    /**
     * Make sure the predictedArrivalTime for stop A (the first stop)  is equals to 0 - in other
     * words, we should show no real-time information for this stop and use the
     * scheduled time instead.
     */
    long predictedArrivalTimeA = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), 0);
    assertEquals(0, predictedArrivalTimeA);
    /**
     * Check if the predictedArrivalTime for stop B is exactly the same as
     * TimepointPredictionRecord.
     */
    assertEquals(tprB.getTimepointPredictedArrivalTime(), predictedArrivalTimeStopB);
    /**
     * Make sure the predictedArrivalTime for stop A (the last stop)  is exactly the same as
     * TimepointPredictionRecord.
     */
    predictedArrivalTimeA = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), 2);
    assertEquals(tprA.getTimepointPredictedArrivalTime(), predictedArrivalTimeA);
}
Also used : TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) Test(org.junit.Test)

Example 28 with ArrivalAndDepartureInstance

use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord.

/**
 * Set up the BlockLocationServiceImpl for the test, using the given
 * timepointPredictions
 *
 * This method creates a loop route with a single trip and two stops in a block
 * Stop A is visited twice in the route
 *
 * stop_id     trip_id    stop_sequence
 *    A           1             0
 *    B           1             1
 *    A           1             2
 *
 * @param timepointPredictions real-time predictions to apply to the
 *          BlockLocationServiceImpl
 * @param stop stop_id for this stop is used to call getArrivalsAndDeparturesForStopInTimeRange()
 * @return a list of ArrivalAndDepartureInstances which is used to access
 *         predicted arrival/departure times for a stop, for comparison
 *         against the expected values
 */
private List<ArrivalAndDepartureInstance> getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord(List<TimepointPredictionRecord> timepointPredictions, StopEntryImpl stop) {
    TargetTime target = new TargetTime(mCurrentTime, mCurrentTime);
    // Setup block
    BlockEntryImpl block = block("blockA");
    stopTime(0, mStopA, mTrip1, time(13, 30), time(13, 35), 1000);
    stopTime(1, mStopB, mTrip1, time(13, 45), time(13, 50), 2000);
    stopTime(2, mStopA, mTrip1, time(13, 55), time(13, 55), 2000);
    BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("sA"), lsids()), mTrip1);
    BlockStopTimeEntry bstAA = blockConfig.getStopTimes().get(0);
    BlockStopTimeEntry bstAB = blockConfig.getStopTimes().get(1);
    BlockStopTimeEntry bstBA = blockConfig.getStopTimes().get(2);
    // Setup block location instance for trip B
    BlockInstance blockInstance = new BlockInstance(blockConfig, mServiceDate);
    BlockLocation blockLocationB = new BlockLocation();
    blockLocationB.setActiveTrip(bstBA.getTrip());
    blockLocationB.setBlockInstance(blockInstance);
    blockLocationB.setClosestStop(bstBA);
    blockLocationB.setDistanceAlongBlock(400);
    blockLocationB.setInService(true);
    blockLocationB.setNextStop(bstAA);
    blockLocationB.setPredicted(false);
    blockLocationB.setScheduledDistanceAlongBlock(400);
    blockLocationB.setTimepointPredictions(timepointPredictions);
    // Mock StopTimeInstance with time frame
    long stopTimeFrom = dateAsLong("2015-07-23 00:00");
    long stopTimeTo = dateAsLong("2015-07-24 00:00");
    StopTimeInstance sti1 = new StopTimeInstance(bstAA, blockInstance.getState());
    ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
    in1.setBlockLocation(blockLocationB);
    in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime()));
    in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
    StopTimeInstance sti2 = new StopTimeInstance(bstAB, blockInstance.getState());
    ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
    in2.setBlockLocation(blockLocationB);
    StopTimeInstance sti3 = new StopTimeInstance(bstBA, blockInstance.getState());
    ArrivalAndDepartureInstance in3 = new ArrivalAndDepartureInstance(sti3);
    in3.setBlockLocation(blockLocationB);
    in3.setPredictedArrivalTime((long) (in3.getScheduledArrivalTime()));
    in3.setPredictedDepartureTime((long) (in3.getScheduledDepartureTime()));
    Date fromTimeBuffered = new Date(stopTimeFrom - _blockStatusService.getRunningLateWindow() * 1000);
    Date toTimeBuffered = new Date(stopTimeTo + _blockStatusService.getRunningEarlyWindow() * 1000);
    Mockito.when(_stopTimeService.getStopTimeInstancesInTimeRange(stop, fromTimeBuffered, toTimeBuffered, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED)).thenReturn(Arrays.asList(sti1, sti2, sti3));
    // Create and add vehicle location record cache
    VehicleLocationRecordCacheImpl _cache = new VehicleLocationRecordCacheImpl();
    VehicleLocationRecord vlr = new VehicleLocationRecord();
    vlr.setBlockId(blockLocationB.getBlockInstance().getBlock().getBlock().getId());
    vlr.setTripId(mTrip1.getId());
    vlr.setTimepointPredictions(blockLocationB.getTimepointPredictions());
    vlr.setTimeOfRecord(mCurrentTime);
    vlr.setVehicleId(new AgencyAndId("1", "123"));
    // Create ScheduledBlockLocation for cache
    ScheduledBlockLocation sbl = new ScheduledBlockLocation();
    sbl.setActiveTrip(blockLocationB.getActiveTrip());
    // Add data to cache
    _cache.addRecord(blockInstance, vlr, sbl, null);
    _blockLocationService.setVehicleLocationRecordCache(_cache);
    ScheduledBlockLocationServiceImpl scheduledBlockLocationServiceImpl = new ScheduledBlockLocationServiceImpl();
    _blockLocationService.setScheduledBlockLocationService(scheduledBlockLocationServiceImpl);
    // Call ArrivalAndDepartureService
    return _service.getArrivalsAndDeparturesForStopInTimeRange(stop, target, stopTimeFrom, stopTimeTo);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) VehicleLocationRecordCacheImpl(org.onebusaway.transit_data_federation.impl.realtime.VehicleLocationRecordCacheImpl) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) Date(java.util.Date) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) ScheduledBlockLocationServiceImpl(org.onebusaway.transit_data_federation.impl.blocks.ScheduledBlockLocationServiceImpl) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 29 with ArrivalAndDepartureInstance

use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange15.

/**
 * This method tests loop routes (the same stop is visited more
 * than once in the same trip) when stop_sequence is missing in the real-time feed.
 * It applies the prediction if there is more than one prediction in the same trip
 * (i.e., the stop_id can be disambiguated).
 *
 * Test configuration: There are three different loop trips and each trip has 3 stops.
 * Time point predictions does not have stop sequences, and therefore the update for
 * each trip Stop A (in trip 1 and trip 3) is ambiguous and cannot be matched.  This
 * test also ensures the we aren't accidentally recognizing two updates in the same block
 * as being part of the same trip.  As a result, the updates should be dropped
 * and schedule time should be provided.
 *
 * Current time = 14:00
 *          Schedule time    Real-time from feed   GTFS stop_sequence  trip_id
 * Stop A   13:30            -----                          0           t1
 * Stop B   13:45            -----                          1           t1
 * Stop A   13:55            14:00                          2           t1
 *
 * Stop A   14:05            -----                          0           t2
 * Stop B   14:15            -----                          1           t2
 * Stop A   14:25            -----                          2           t2
 *
 * Stop A   14:30            14:40                          0           t3
 * Stop B   14:45            -----                          1           t3
 * Stop A   14:55            -----                          2           t3
 */
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange15() {
    // Override the current time with a later time than the time point
    // predictions
    mCurrentTime = dateAsLong("2015-07-23 14:00");
    // Set time point predictions for trip 1 stop A
    TimepointPredictionRecord tpr1A = new TimepointPredictionRecord();
    tpr1A.setTimepointId(mStopA.getId());
    long tprAATime = createPredictedTime(time(14, 00));
    tpr1A.setTimepointPredictedArrivalTime(tprAATime);
    tpr1A.setTripId(mTrip1.getId());
    // Set time point predictions for trip 3 stop A
    TimepointPredictionRecord tpr3A = new TimepointPredictionRecord();
    tpr3A.setTimepointId(mStopA.getId());
    long tprATime = createPredictedTime(time(14, 40));
    tpr3A.setTimepointPredictedArrivalTime(tprATime);
    tpr3A.setTripId(mTrip3.getId());
    // Call ArrivalsAndDeparturesForStopInTimeRange method in
    // ArrivalAndDepartureServiceImpl
    List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecordWithMultipleTrips(Arrays.asList(tpr1A, tpr3A), mStopB);
    // First trip in block
    long predictedArrivalTimeStop1A = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip1.getId(), 0);
    long predictedArrivalTimeStop1B = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), mTrip1.getId(), 1);
    long predictedArrivalTimeStop1C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip1.getId(), 2);
    // Second trip in block
    long predictedArrivalTimeStop2A = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip2.getId(), 0);
    long predictedArrivalTimeStop2B = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), mTrip2.getId(), 1);
    long predictedArrivalTimeStop2C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip2.getId(), 2);
    // Third trip in block
    long predictedArrivalTimeStop3A = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip3.getId(), 0);
    long predictedArrivalTimeStop3B = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), mTrip3.getId(), 1);
    long predictedArrivalTimeStop3C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip3.getId(), 2);
    /**
     * Check the all stops and make sure no real-time information has been applied.
     */
    assertEquals(predictedArrivalTimeStop1A, 0);
    assertEquals(predictedArrivalTimeStop1B, 0);
    assertEquals(predictedArrivalTimeStop1C, 0);
    assertEquals(predictedArrivalTimeStop2A, 0);
    assertEquals(predictedArrivalTimeStop2B, 0);
    assertEquals(predictedArrivalTimeStop2C, 0);
    assertEquals(predictedArrivalTimeStop3A, 0);
    assertEquals(predictedArrivalTimeStop3B, 0);
    assertEquals(predictedArrivalTimeStop3C, 0);
}
Also used : TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) Test(org.junit.Test)

Example 30 with ArrivalAndDepartureInstance

use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange16.

/**
 * This method tests loop routes (the same stop is visited more
 * than once in the same trip) when stop_sequence is missing in the real-time feed.
 * It applies the prediction if there is more than one prediction in the same trip
 * (i.e., the stop_id can be disambiguated).
 *
 * Test configuration: There are three different loop trips and each trip has 3 stops.
 * Time point predictions do not have stop sequences, and therefore the update for
 * trip1 Stop A is ambiguous and cannot be matched.  However, for trip 3, there are at least
 * two updates, so we can infer that the update for Stop A should be applied to the first
 * stop instance.  This test also ensures the we aren't accidentally recognizing two updates
 * in the same block as being part of the same trip (for trip 1).  As a result, the update
 * for trip 1 should be dropped, but the updates for trip 3 should be applied.
 *
 * Current time = 14:00
 *          Schedule time    Real-time from feed   GTFS stop_sequence  trip_id
 * Stop A   13:30            -----                          0           t1
 * Stop B   13:45            -----                          1           t1
 * Stop A   13:55            14:00                          2           t1
 *
 * Stop A   14:05            -----                          0           t2
 * Stop B   14:15            -----                          1           t2
 * Stop A   14:25            -----                          2           t2
 *
 * Stop A   14:30            14:40                          0           t3
 * Stop B   14:45            14:50                          1           t3
 * Stop A   14:55            -----                          2           t3
 */
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange16() {
    // Override the current time with a later time than the time point
    // predictions
    mCurrentTime = dateAsLong("2015-07-23 14:00");
    // Set time point prediction for trip 1 stop A
    TimepointPredictionRecord tpr1A = new TimepointPredictionRecord();
    tpr1A.setTimepointId(mStopA.getId());
    long tprAATime = createPredictedTime(time(14, 00));
    tpr1A.setTimepointPredictedArrivalTime(tprAATime);
    tpr1A.setTripId(mTrip1.getId());
    // Set time point predictions for trip 3 stop A and stop B
    TimepointPredictionRecord tpr3A = new TimepointPredictionRecord();
    tpr3A.setTimepointId(mStopA.getId());
    long tprATime = createPredictedTime(time(14, 40));
    tpr3A.setTimepointPredictedArrivalTime(tprATime);
    tpr3A.setTripId(mTrip3.getId());
    TimepointPredictionRecord tpr3B = new TimepointPredictionRecord();
    tpr3B.setTimepointId(mStopB.getId());
    long tprBTime = createPredictedTime(time(14, 50));
    tpr3B.setTimepointPredictedArrivalTime(tprBTime);
    tpr3B.setTripId(mTrip3.getId());
    // Call ArrivalsAndDeparturesForStopInTimeRange method in
    // ArrivalAndDepartureServiceImpl
    List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecordWithMultipleTrips(Arrays.asList(tpr1A, tpr3A, tpr3B), mStopB);
    // First trip in block
    long predictedArrivalTimeStop1A = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip1.getId(), 0);
    long predictedArrivalTimeStop1B = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), mTrip1.getId(), 1);
    long predictedArrivalTimeStop1C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip1.getId(), 2);
    // Second trip in block
    long predictedArrivalTimeStop2A = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip2.getId(), 0);
    long predictedArrivalTimeStop2B = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), mTrip2.getId(), 1);
    long predictedArrivalTimeStop2C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip2.getId(), 2);
    // Third trip in block
    long predictedArrivalTimeStop3A = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip3.getId(), 0);
    long predictedArrivalTimeStop3B = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), mTrip3.getId(), 1);
    /**
     * Make sure no real-time info is applied to trips 1 and 2
     */
    assertEquals(predictedArrivalTimeStop1A, 0);
    assertEquals(predictedArrivalTimeStop1B, 0);
    assertEquals(predictedArrivalTimeStop1C, 0);
    assertEquals(predictedArrivalTimeStop2A, 0);
    assertEquals(predictedArrivalTimeStop2B, 0);
    assertEquals(predictedArrivalTimeStop2C, 0);
    /**
     * Check last three predictions in trip 3.  We should have predictions for these stops.
     */
    assertEquals(predictedArrivalTimeStop3A, tpr3A.getTimepointPredictedArrivalTime());
    assertEquals(predictedArrivalTimeStop3B, tpr3B.getTimepointPredictedArrivalTime());
    long scheduledArrivalTime3B = getScheduledArrivalTimeByStopId(mTrip3, mStopB.getId(), 1);
    // Calculate the delay of the last stop A in trip B
    long delta = TimeUnit.MILLISECONDS.toSeconds(predictedArrivalTimeStop3B) - scheduledArrivalTime3B;
    long scheduledArrivalTimeStop3C = getScheduledArrivalTimeByStopId(mTrip3, mStopA.getId(), 2);
    long predictedArrivalTime3C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip3.getId(), 2);
    // Check propagation of trip 3 Stop B to the last instance of Stop A
    assertEquals(scheduledArrivalTimeStop3C + delta, TimeUnit.MILLISECONDS.toSeconds(predictedArrivalTime3C));
}
Also used : TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) Test(org.junit.Test)

Aggregations

ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)37 Test (org.junit.Test)18 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)17 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)12 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)10 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)10 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)9 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)9 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)8 Date (java.util.Date)7 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)7 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)6 ArrayList (java.util.ArrayList)5 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)5 ScheduledBlockLocationServiceImpl (org.onebusaway.transit_data_federation.impl.blocks.ScheduledBlockLocationServiceImpl)5 VehicleLocationRecordCacheImpl (org.onebusaway.transit_data_federation.impl.realtime.VehicleLocationRecordCacheImpl)5 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)5 HashMap (java.util.HashMap)3 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)3 StopBean (org.onebusaway.transit_data.model.StopBean)3