use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class GtfsRealtimeTripLibraryTest method testTprInterpolation_1.
/**
* Same as above, but we should NOT create new timepoint prediction records
* because the stop has already been served. Only thing different is current
* time.
*
* Current time = 7:33. Trip update delay = 2 minutes
* Schedule time Real-time from feed Timepoint predicted departure time
* Stop A 7:30 ----- ----
* Stop B 7:40 7:43 7:43
*/
@Test
public void testTprInterpolation_1() {
_library.setCurrentTime(time(7, 33) * 1000);
TripEntryImpl tripA = trip("tripA");
stopTime(0, stop("stopA", 0, 0), tripA, time(7, 30), 0.0);
stopTime(1, stop("stopB", 0, 0), tripA, time(7, 40), 10.0);
BlockEntryImpl blockA = block("blockA");
BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA);
BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
StopTimeUpdate.Builder stopTimeUpdate = stopTimeUpdateWithDepartureDelay("stopB", 180);
TripUpdate.Builder tripUpdate = tripUpdate("tripA", _library.getCurrentTime() / 1000, 120, stopTimeUpdate);
Mockito.when(_entitySource.getTrip("tripA")).thenReturn(tripA);
Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceA));
VehicleLocationRecord record = vehicleLocationRecord(tripUpdate);
long stopADept = getPredictedDepartureTimeByStopId(record, "stopA");
// no tpr for this stop
assertEquals(stopADept, -1);
long stopBDept = getPredictedDepartureTimeByStopId(record, "stopB");
assertEquals(stopBDept, time(7, 43) * 1000);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class GtfsRealtimeTripLibraryTest method testTprOnFutureTrip.
/**
* This method tests that we propagate a time point prediction record
* when it comes from a trip that hasn't started yet.
*
* Current time = 7:31. Trip update delay = 2 minutes
* Schedule time Real-time from feed
* Stop A (trip A) 7:30 7:33
* Stop A (trip B) 7:40 7:44
*/
@Test
public void testTprOnFutureTrip() {
_library.setCurrentTime(time(7, 31) * 1000);
TripEntryImpl tripA = trip("tripA");
TripEntryImpl tripB = trip("tripB");
StopEntryImpl stopA = stop("stopA", 0, 0);
stopTime(0, stopA, tripA, time(7, 30), 0.0);
stopTime(0, stopA, tripB, time(7, 40), 0.0);
BlockEntryImpl blockA = block("blockA");
BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA, tripB);
BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
StopTimeUpdate.Builder stuA = stopTimeUpdateWithDepartureDelay("stopA", 180);
TripUpdate.Builder tuA = tripUpdate("tripA", _library.getCurrentTime() / 1000, 120, stuA);
StopTimeUpdate.Builder stuB = stopTimeUpdateWithDepartureDelay("stopA", 240);
TripUpdate.Builder tuB = tripUpdate("tripB", _library.getCurrentTime() / 1000, 0, stuB);
tuA.setVehicle(vehicle("bus1"));
tuB.setVehicle(vehicle("bus1"));
Mockito.when(_entitySource.getTrip("tripA")).thenReturn(tripA);
Mockito.when(_entitySource.getTrip("tripB")).thenReturn(tripB);
Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceA));
VehicleLocationRecord record = vehicleLocationRecord(tuA, tuB);
long tripADept = getPredictedDepartureTimeByStopIdAndTripId(record, "stopA", "tripA");
assertEquals(tripADept, time(7, 33) * 1000);
long tripBDept = getPredictedDepartureTimeByStopIdAndTripId(record, "stopA", "tripB");
assertEquals(tripBDept, time(7, 44) * 1000);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class ServiceAlertsServiceImplTest method testGetServiceAlertsForVehicleJourney.
@Test
public void testGetServiceAlertsForVehicleJourney() {
/**
* These alerts should match
*/
ServiceAlertRecord alert2 = new ServiceAlertRecord();
alert2.setAgencyId("1");
alert2.setServiceAlertId("B");
ServiceAlertsSituationAffectsClause affectsClause2 = new ServiceAlertsSituationAffectsClause();
affectsClause2.setAgencyId("1");
affectsClause2.setTripId("TripA");
alert2.getAllAffects().add(affectsClause2);
alert2 = _service.createOrUpdateServiceAlert(alert2);
ServiceAlertRecord alert3 = new ServiceAlertRecord();
alert3.setAgencyId("1");
alert3.setServiceAlertId("C");
ServiceAlertsSituationAffectsClause affectsClause3 = new ServiceAlertsSituationAffectsClause();
affectsClause3.setAgencyId("1");
affectsClause3.setRouteId("RouteX");
alert3.getAllAffects().add(affectsClause3);
alert3 = _service.createOrUpdateServiceAlert(alert3);
ServiceAlertRecord alert4 = new ServiceAlertRecord();
alert4.setAgencyId("1");
alert4.setServiceAlertId("D");
ServiceAlertsSituationAffectsClause affectsClause4 = new ServiceAlertsSituationAffectsClause();
affectsClause4.setAgencyId("1");
affectsClause4.setRouteId("RouteX");
affectsClause4.setDirectionId("1");
alert4.getAllAffects().add(affectsClause4);
alert4 = _service.createOrUpdateServiceAlert(alert4);
/**
* These alerts shouldn't match
*/
ServiceAlertRecord alert5 = new ServiceAlertRecord();
alert5.setAgencyId("1");
alert5.setServiceAlertId("E");
ServiceAlertsSituationAffectsClause affectsClause5 = new ServiceAlertsSituationAffectsClause();
affectsClause5.setAgencyId("1");
affectsClause5.setStopId("10021");
affectsClause5.setTripId("TripA");
alert5.getAllAffects().add(affectsClause5);
alert5 = _service.createOrUpdateServiceAlert(alert5);
ServiceAlertRecord alert6 = new ServiceAlertRecord();
alert6.setAgencyId("1");
alert6.setServiceAlertId("F");
ServiceAlertsSituationAffectsClause affectsClause6 = new ServiceAlertsSituationAffectsClause();
affectsClause6.setAgencyId("1");
affectsClause6.setStopId("10020");
affectsClause6.setTripId("TripB");
alert6.getAllAffects().add(affectsClause6);
alert6 = _service.createOrUpdateServiceAlert(alert6);
ServiceAlertRecord alert7 = new ServiceAlertRecord();
alert7.setAgencyId("1");
alert7.setServiceAlertId("G");
ServiceAlertsSituationAffectsClause affectsClause7 = new ServiceAlertsSituationAffectsClause();
affectsClause7.setAgencyId("1");
affectsClause7.setTripId("TripB");
alert7.getAllAffects().add(affectsClause7);
alert7 = _service.createOrUpdateServiceAlert(alert7);
ServiceAlertRecord alert8 = new ServiceAlertRecord();
alert8.setAgencyId("1");
alert8.setServiceAlertId("H");
ServiceAlertsSituationAffectsClause affectsClause8 = new ServiceAlertsSituationAffectsClause();
affectsClause8.setAgencyId("1");
affectsClause8.setRouteId("RouteY");
alert8.getAllAffects().add(affectsClause8);
alert8 = _service.createOrUpdateServiceAlert(alert8);
ServiceAlertRecord alert9 = new ServiceAlertRecord();
alert9.setAgencyId("1");
alert9.setServiceAlertId("I");
ServiceAlertsSituationAffectsClause affectsClause9 = new ServiceAlertsSituationAffectsClause();
affectsClause9.setAgencyId("1");
affectsClause9.setRouteId("RouteX");
affectsClause9.setDirectionId("0");
alert9.getAllAffects().add(affectsClause9);
alert9 = _service.createOrUpdateServiceAlert(alert9);
RouteEntryImpl route = route("RouteX");
routeCollection("RouteX", route);
StopEntryImpl stop = stop("10020", 47.0, -122.0);
TripEntryImpl trip = trip("TripA");
trip.setRoute(route);
trip.setDirectionId("1");
stopTime(0, stop, trip, time(8, 53), 0);
BlockEntryImpl block = block("block");
BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("a"), lsids()), trip);
BlockTripInstance blockTripInstance = new BlockTripInstance(blockConfig.getTrips().get(0), new InstanceState(System.currentTimeMillis()));
List<ServiceAlertRecord> alerts = _service.getServiceAlertsForVehicleJourney(System.currentTimeMillis(), blockTripInstance, new AgencyAndId("1", "1111"));
assertEquals(3, alerts.size());
assertTrue(alerts.contains(alert2));
assertTrue(alerts.contains(alert3));
assertTrue(alerts.contains(alert4));
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class ServiceAlertsServiceImplTest method testGetServiceAlertsForStopCall.
@Test
public void testGetServiceAlertsForStopCall() {
/**
* These alerts should match
*/
ServiceAlertRecord alert1 = new ServiceAlertRecord();
alert1.setAgencyId("1");
alert1.setServiceAlertId("A");
ServiceAlertsSituationAffectsClause affectsClause = new ServiceAlertsSituationAffectsClause();
affectsClause.setAgencyId("1");
affectsClause.setStopId("10020");
affectsClause.setTripId("TripA");
alert1.getAllAffects().add(affectsClause);
alert1 = _service.createOrUpdateServiceAlert(alert1);
ServiceAlertRecord alert2 = new ServiceAlertRecord();
alert2.setAgencyId("1");
alert2.setServiceAlertId("B");
ServiceAlertsSituationAffectsClause affectsClause2 = new ServiceAlertsSituationAffectsClause();
affectsClause2.setAgencyId("1");
affectsClause2.setTripId("TripA");
alert2.getAllAffects().add(affectsClause2);
alert2 = _service.createOrUpdateServiceAlert(alert2);
ServiceAlertRecord alert3 = new ServiceAlertRecord();
alert3.setAgencyId("1");
alert3.setServiceAlertId("C");
ServiceAlertsSituationAffectsClause affectsClause3 = new ServiceAlertsSituationAffectsClause();
affectsClause3.setAgencyId("1");
affectsClause3.setRouteId("RouteX");
alert3.getAllAffects().add(affectsClause3);
alert3 = _service.createOrUpdateServiceAlert(alert3);
ServiceAlertRecord alert4 = new ServiceAlertRecord();
alert4.setAgencyId("1");
alert4.setServiceAlertId("D");
ServiceAlertsSituationAffectsClause affectsClause4 = new ServiceAlertsSituationAffectsClause();
affectsClause4.setAgencyId("1");
affectsClause4.setRouteId("RouteX");
affectsClause4.setDirectionId("1");
alert4.getAllAffects().add(affectsClause4);
alert4 = _service.createOrUpdateServiceAlert(alert4);
/**
* These alerts shouldn't match
*/
ServiceAlertRecord alert5 = new ServiceAlertRecord();
alert5.setAgencyId("1");
alert5.setServiceAlertId("E");
ServiceAlertsSituationAffectsClause affectsClause5 = new ServiceAlertsSituationAffectsClause();
affectsClause5.setAgencyId("1");
affectsClause5.setStopId("10021");
affectsClause5.setTripId("TripA");
alert5.getAllAffects().add(affectsClause5);
alert5 = _service.createOrUpdateServiceAlert(alert5);
ServiceAlertRecord alert6 = new ServiceAlertRecord();
alert6.setAgencyId("1");
alert6.setServiceAlertId("F");
ServiceAlertsSituationAffectsClause affectsClause6 = new ServiceAlertsSituationAffectsClause();
affectsClause6.setAgencyId("1");
affectsClause6.setStopId("10020");
affectsClause6.setTripId("TripB");
alert6.getAllAffects().add(affectsClause6);
alert6 = _service.createOrUpdateServiceAlert(alert6);
ServiceAlertRecord alert7 = new ServiceAlertRecord();
alert7.setAgencyId("1");
alert7.setServiceAlertId("G");
ServiceAlertsSituationAffectsClause affectsClause7 = new ServiceAlertsSituationAffectsClause();
affectsClause7.setAgencyId("1");
affectsClause7.setTripId("TripB");
alert7.getAllAffects().add(affectsClause7);
alert7 = _service.createOrUpdateServiceAlert(alert7);
ServiceAlertRecord alert8 = new ServiceAlertRecord();
alert8.setAgencyId("1");
alert8.setServiceAlertId("H");
ServiceAlertsSituationAffectsClause affectsClause8 = new ServiceAlertsSituationAffectsClause();
affectsClause8.setAgencyId("1");
affectsClause8.setRouteId("RouteY");
alert8.getAllAffects().add(affectsClause8);
alert8 = _service.createOrUpdateServiceAlert(alert8);
ServiceAlertRecord alert9 = new ServiceAlertRecord();
alert9.setAgencyId("1");
alert9.setServiceAlertId("I");
ServiceAlertsSituationAffectsClause affectsClause9 = new ServiceAlertsSituationAffectsClause();
affectsClause9.setAgencyId("1");
affectsClause9.setRouteId("RouteX");
affectsClause9.setDirectionId("0");
alert9.getAllAffects().add(affectsClause9);
alert9 = _service.createOrUpdateServiceAlert(alert9);
RouteEntryImpl route = route("RouteX");
routeCollection("RouteX", route);
StopEntryImpl stop = stop("10020", 47.0, -122.0);
TripEntryImpl trip = trip("TripA");
trip.setRoute(route);
trip.setDirectionId("1");
stopTime(0, stop, trip, time(8, 53), 0);
BlockEntryImpl block = block("block");
BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("a"), lsids()), trip);
BlockInstance blockInstance = new BlockInstance(blockConfig, System.currentTimeMillis());
List<ServiceAlertRecord> alerts = _service.getServiceAlertsForStopCall(System.currentTimeMillis(), blockInstance, blockConfig.getStopTimes().get(0), new AgencyAndId("1", "1111"));
assertEquals(4, alerts.size());
assertTrue(alerts.contains(alert1));
assertTrue(alerts.contains(alert2));
assertTrue(alerts.contains(alert3));
assertTrue(alerts.contains(alert4));
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockTripInstanceLibraryTest method test.
@Test
public void test() {
BlockEntryImpl block = UnitTestingSupport.block("block");
TripEntryImpl tripA = UnitTestingSupport.trip("tripA");
TripEntryImpl tripB = UnitTestingSupport.trip("tripB");
UnitTestingSupport.stopTime(0, null, tripA, 0, 0);
UnitTestingSupport.stopTime(0, null, tripB, 0, 0);
ServiceIdActivation serviceIds = UnitTestingSupport.serviceIds("sid");
BlockConfigurationEntry blockConfig = UnitTestingSupport.blockConfiguration(block, serviceIds, tripA, tripB);
BlockInstance blockInstanceA = new BlockInstance(blockConfig, 123L);
BlockTripInstance blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstanceA, UnitTestingSupport.aid("tripA"));
assertSame(tripA, blockTripInstance.getBlockTrip().getTrip());
assertEquals(123L, blockTripInstance.getServiceDate());
blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstanceA, UnitTestingSupport.aid("tripB"));
assertSame(tripB, blockTripInstance.getBlockTrip().getTrip());
assertEquals(123L, blockTripInstance.getServiceDate());
blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstanceA, UnitTestingSupport.aid("tripC"));
assertNull(blockTripInstance);
}
Aggregations