Search in sources :

Example 16 with TimepointPredictionRecord

use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange05.

/**
 * This method tests a request for an arrival time for a stop, when the
 * current time is greater than the arrival time prediction for that stop
 * (Stop B). In other words, the bus is predicted to have already passed the
 * stop (Stop B).
 *
 * Test configuration: There are 2 bus stops which have the real time arrival
 * times (time point predictions) - Stop A and B. In this case
 * getArrivalsAndDeparturesForStopInTimeRange() should return last received
 * time point prediction for particular stop we're requesting information for.
 *
 * Current time = 14:00
 *          Schedule time    Real-time from feed
 * Stop A   13:30            13:30
 * Stop B   13:40            13:50
 */
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange05() {
    // 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
    TimepointPredictionRecord tprA = new TimepointPredictionRecord();
    tprA.setTimepointId(mStopA.getId());
    long tprATime = createPredictedTime(time(13, 30));
    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 = getArrivalsAndDeparturesForStopInTimeRangeByTimepointPredictionRecord(Arrays.asList(tprA, tprB));
    long predictedArrivalTimeStopA = getPredictedArrivalTimeByStopId(arrivalsAndDepartures, mStopA.getId());
    long predictedArrivalTimeStopB = getPredictedArrivalTimeByStopId(arrivalsAndDepartures, mStopB.getId());
    /**
     * Check if the predictedArrivalTime is exactly the same as
     * TimepointPrediction for both stops
     */
    assertEquals(tprA.getTimepointPredictedArrivalTime(), predictedArrivalTimeStopA);
    assertEquals(tprB.getTimepointPredictedArrivalTime(), predictedArrivalTimeStopB);
    /**
     * Check if the predictedDepartureTimes and scheduledDepartureTimes have the
     * same delta as arrival predictions and scheduled arrival times for both
     * stops
     */
    long predictedDepartureTimeStopA = getPredictedDepartureTimeByStopId(arrivalsAndDepartures, mStopA.getId());
    long predictedDepartureTimeStopB = getPredictedDepartureTimeByStopId(arrivalsAndDepartures, mStopB.getId());
    long scheduledArrivalTimeForStopA = getScheduledArrivalTimeByStopId(mTrip1, mStopA.getId());
    long scheduledArrivalTimeForStopB = getScheduledArrivalTimeByStopId(mTrip1, mStopB.getId());
    long scheduledDepartureTimeForStopA = getScheduledDepartureTimeByStopId(mTrip1, mStopA.getId());
    long scheduledDepartureTimeForStopB = getScheduledDepartureTimeByStopId(mTrip1, mStopB.getId());
    long deltaA = TimeUnit.MILLISECONDS.toSeconds(predictedArrivalTimeStopA) - scheduledArrivalTimeForStopA;
    assertEquals(scheduledDepartureTimeForStopA + deltaA, TimeUnit.MILLISECONDS.toSeconds(predictedDepartureTimeStopA));
    long deltaB = TimeUnit.MILLISECONDS.toSeconds(predictedArrivalTimeStopB) - scheduledArrivalTimeForStopB;
    assertEquals(scheduledDepartureTimeForStopB + deltaB, TimeUnit.MILLISECONDS.toSeconds(predictedDepartureTimeStopB));
}
Also used : TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) Test(org.junit.Test)

Example 17 with TimepointPredictionRecord

use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange08.

/**
 * 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, one for the first stop
 * and one for second stop, and there is a single trip in the block. The time point
 * predictions do not have stop_sequences. In this case, propagation should happen as normal.
 * getArrivalsAndDeparturesForStopInTimeRange() the first Stop A  and stop B predictions
 * should match with time point predictions. The last Stop A should return a predicted
 * arrival based on stop B (6 min delay).
 *
 * Current time = 14:00
 *          Schedule time    Real-time from feed      GTFS stop_sequence
 * Stop A   13:30            13:35                          0
 * Stop B   13:45            13:51                          1
 * Stop A   13:55            -----                          2
 */
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange08() {
    // 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
    TimepointPredictionRecord tprA = new TimepointPredictionRecord();
    tprA.setTimepointId(mStopA.getId());
    long tprATime = createPredictedTime(time(13, 35));
    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, 51));
    tprB.setTimepointPredictedArrivalTime(tprBTime);
    tprB.setTripId(mTrip1.getId());
    // Call ArrivalsAndDeparturesForStopInTimeRange method in
    // ArrivalAndDepartureServiceImpl
    List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord(Arrays.asList(tprA, tprB), mStopB);
    long predictedArrivalTimeStopB = getPredictedArrivalTimeByStopId(arrivalsAndDepartures, mStopB.getId());
    /**
     * 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 first stop)  is exactly the same as
     * TimepointPredictionRecord.
     */
    long predictedArrivalTimeA = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), 0);
    assertEquals(tprA.getTimepointPredictedArrivalTime(), predictedArrivalTimeA);
    /**
     * Make sure the predictedArrivalTime for stop A (the last stop)  is propagated based on
     * TimepointPredictionRecord of the stop B
     */
    long scheduledArrivalTimeStopB = getScheduledArrivalTimeByStopId(mTrip1, mStopB.getId());
    long scheduledArrivalTimeLastStopA = getScheduledArrivalTimeByStopId(mTrip1, mStopA.getId(), 2);
    /**
     * Calculate the delay of the previous stop(stop B)
     */
    long delta = TimeUnit.MILLISECONDS.toSeconds(predictedArrivalTimeStopB) - scheduledArrivalTimeStopB;
    predictedArrivalTimeA = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), 2);
    assertEquals(scheduledArrivalTimeLastStopA + delta, TimeUnit.MILLISECONDS.toSeconds(predictedArrivalTimeA));
}
Also used : TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) Test(org.junit.Test)

Example 18 with TimepointPredictionRecord

use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange07.

/**
 * 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 is only one time point prediction for the first stop,
 * and there is only one trip in the block. But time point predictions do not have
 * stop_sequences. 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 (i.e., we drop the prediction,
 * because it is ambiguous and could refer to more than one stop instance - Stop A
 * appears twice).
 *
 * Current time = 14:00
 *          Schedule time    Real-time from feed      GTFS stop_sequence
 * Stop A   13:30            13:35                          0
 * Stop B   13:45            -----                          1
 * Stop A   13:55            -----                          2
 *
 * Since we
 */
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange07() {
    // 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
    TimepointPredictionRecord tprA = new TimepointPredictionRecord();
    tprA.setTimepointId(mStopA.getId());
    long tprBTime = createPredictedTime(time(13, 35));
    tprA.setTimepointPredictedArrivalTime(tprBTime);
    tprA.setTripId(mTrip1.getId());
    // Call ArrivalsAndDeparturesForStopInTimeRange method in
    // ArrivalAndDepartureServiceImpl
    List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord(Arrays.asList(tprA), mStopA);
    /**
     * Make sure the predictedArrivalTime for stop A (first and the last stop) and stop B
     * is equals to 0 - in other words, we should show no real-time information for this trip
     * and use the scheduled time instead.
     */
    // 
    long predictedArrivalTimeA = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), 0);
    assertEquals(0, predictedArrivalTimeA);
    long predictedArrivalTimeB = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), 1);
    assertEquals(0, predictedArrivalTimeB);
    predictedArrivalTimeA = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), 2);
    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 19 with TimepointPredictionRecord

use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange14.

/**
 * 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 2 and trip 3) is ambiguous and cannot be matched.  This
 * test also ensures the we aren't accidentally recognizing two adjacent updates in
 * the 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            -----                          2           t1
 *
 * Stop A   14:05            -----                          0           t2
 * Stop B   14:15            -----                          1           t2
 * Stop A   14:25            14:30                          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 testGetArrivalsAndDeparturesForStopInTimeRange14() {
    // 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 2 stop A
    TimepointPredictionRecord tpr2A = new TimepointPredictionRecord();
    tpr2A.setTimepointId(mStopA.getId());
    long tprAATime = createPredictedTime(time(14, 30));
    tpr2A.setTimepointPredictedArrivalTime(tprAATime);
    tpr2A.setTripId(mTrip2.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(tpr2A, 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 20 with TimepointPredictionRecord

use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange12.

/**
 * 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.  There is only one prediction
 * for the first or the last stop in a loop route, and there it is ambiguous and
 * should be dropped.  As a result, all stops should show scheduled time.
 *
 * 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            -----                          2           t1
 *
 * Stop A   14:05            14:10                          0           t2
 * Stop B   14:15            -----                          1           t2
 * Stop A   14:25            -----                          2           t2
 *
 * Stop A   14:30            -----                          0           t3
 * Stop B   14:45            -----                          1           t3
 * Stop A   14:55            -----                          2           t3
 */
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange12() {
    // 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 2 stop A
    TimepointPredictionRecord tprA = new TimepointPredictionRecord();
    tprA.setTimepointId(mStopA.getId());
    long tprATime = createPredictedTime(time(14, 10));
    tprA.setTimepointPredictedArrivalTime(tprATime);
    tprA.setTripId(mTrip2.getId());
    // Call ArrivalsAndDeparturesForStopInTimeRange method in
    // ArrivalAndDepartureServiceImpl
    List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecordWithMultipleTrips(Arrays.asList(tprA), 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 propagation happening.
     */
    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)

Aggregations

TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)36 Test (org.junit.Test)20 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)17 ArrayList (java.util.ArrayList)10 Date (java.util.Date)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)6 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)6 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)5 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)4 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)4 TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)4 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)4 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)4 StopTimeEvent (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent)3 HashMap (java.util.HashMap)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 TripBean (org.onebusaway.transit_data.model.trips.TripBean)3 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)3 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)3