Search in sources :

Example 41 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class GtfsRealtimeTripLibraryTest method testCreateVehicleLocationRecordForUpdate_NoStopTimeUpdates.

@Test
public void testCreateVehicleLocationRecordForUpdate_NoStopTimeUpdates() {
    TripUpdate tripUpdate = TripUpdate.newBuilder().setTrip(TripDescriptor.newBuilder().setTripId("tripA")).setDelay(120).setTimestamp(123456789).build();
    TripEntryImpl tripA = trip("tripA");
    stopTime(0, stop("stopA", 0, 0), tripA, time(7, 30), 0.0);
    BlockEntryImpl blockA = block("blockA");
    BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA);
    BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
    Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceA));
    CombinedTripUpdatesAndVehiclePosition update = new CombinedTripUpdatesAndVehiclePosition();
    update.block = new BlockDescriptor();
    update.block.setBlockInstance(blockInstanceA);
    update.tripUpdates = Arrays.asList(tripUpdate);
    VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(update);
    assertEquals(123456789000L, record.getTimeOfRecord());
    assertEquals(120, record.getScheduleDeviation(), 0.0);
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Test(org.junit.Test)

Example 42 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class GtfsRealtimeTripLibraryTest method testCreateVehicleLocationRecordForUpdate_WithStopTimeUpdates.

@Test
public void testCreateVehicleLocationRecordForUpdate_WithStopTimeUpdates() {
    StopTimeUpdate.Builder stopTimeUpdate = StopTimeUpdate.newBuilder();
    stopTimeUpdate.setStopId("stopA");
    StopTimeEvent.Builder stopTimeEvent = StopTimeEvent.newBuilder();
    stopTimeEvent.setDelay(180);
    stopTimeUpdate.setDeparture(stopTimeEvent);
    TripUpdate tripUpdate = TripUpdate.newBuilder().setTrip(TripDescriptor.newBuilder().setTripId("tripA")).setDelay(120).setTimestamp(123456789).addStopTimeUpdate(stopTimeUpdate).build();
    TripEntryImpl tripA = trip("tripA");
    stopTime(0, stop("stopA", 0, 0), tripA, time(7, 30), 0.0);
    BlockEntryImpl blockA = block("blockA");
    BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA);
    BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
    Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceA));
    CombinedTripUpdatesAndVehiclePosition update = new CombinedTripUpdatesAndVehiclePosition();
    update.block = new BlockDescriptor();
    update.block.setBlockInstance(blockInstanceA);
    update.tripUpdates = Arrays.asList(tripUpdate);
    VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(update);
    TimepointPredictionRecord tpr = record.getTimepointPredictions().get(0);
    long departure = tpr.getTimepointPredictedDepartureTime();
    // 7:30 plus 3 min delay, + now we are in ms.
    assertEquals(departure, time(7, 33) * 1000);
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopTimeEvent(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Test(org.junit.Test)

Example 43 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class GtfsRealtimeTripLibraryTest method testTprInterpolation_2.

/**
 * Test that we do NOT create new timepoint prediction record when it
 * already exists.
 *
 * Current time = 7:25. Trip update delay = 2 minutes
 *          Schedule time    Real-time from feed  Timepoint predicted departure time
 * Stop A   7:30             7:33                 7:33 (and only one)
 */
@Test
public void testTprInterpolation_2() {
    _library.setCurrentTime(time(7, 25) * 1000);
    TripEntryImpl tripA = trip("tripA");
    stopTime(0, stop("stopA", 0, 0), tripA, time(7, 30), 0.0);
    BlockEntryImpl blockA = block("blockA");
    BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA);
    BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
    StopTimeUpdate.Builder stopTimeUpdate = stopTimeUpdateWithDepartureDelay("stopA", 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");
    assertEquals(stopADept, time(7, 33) * 1000);
    assertEquals(record.getTimepointPredictions().size(), 1);
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Test(org.junit.Test)

Example 44 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class UnitTestingSupport method linkBlockTrips.

public static BlockConfigurationEntry linkBlockTrips(BlockEntryImpl block, List<FrequencyEntry> frequencies, TripEntryImpl... trips) {
    List<TripEntry> tripEntries = new ArrayList<TripEntry>();
    Set<LocalizedServiceId> serviceIds = new TreeSet<LocalizedServiceId>();
    for (int i = 0; i < trips.length; i++) {
        TripEntryImpl trip = trips[i];
        trip.setBlock(block);
        tripEntries.add(trip);
        if (trip.getServiceId() != null)
            serviceIds.add(trip.getServiceId());
    }
    Builder builder = BlockConfigurationEntryImpl.builder();
    builder.setBlock(block);
    builder.setServiceIds(new ServiceIdActivation(new ArrayList<LocalizedServiceId>(serviceIds), new ArrayList<LocalizedServiceId>()));
    builder.setTrips(tripEntries);
    builder.setFrequencies(frequencies);
    builder.setTripGapDistances(new double[tripEntries.size()]);
    BlockConfigurationEntry configuration = builder.create();
    List<BlockConfigurationEntry> configurations = block.getConfigurations();
    if (configurations == null) {
        configurations = new ArrayList<BlockConfigurationEntry>();
        block.setConfigurations(configurations);
    }
    configurations.add(configuration);
    return configuration;
}
Also used : Builder(org.onebusaway.transit_data_federation.impl.transit_graph.BlockConfigurationEntryImpl.Builder) ArrayList(java.util.ArrayList) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) BlockTripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockTripEntryImpl) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) TreeSet(java.util.TreeSet) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 45 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class UnitTestingSupport method trip.

public static TripEntryImpl trip(String id, String serviceId) {
    TripEntryImpl trip = trip(id);
    trip.setServiceId(new LocalizedServiceId(aid(serviceId), timeZone()));
    return trip;
}
Also used : LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) BlockTripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockTripEntryImpl)

Aggregations

TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)58 Test (org.junit.Test)43 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)34 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)29 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)22 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)20 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)14 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)14 Trip (org.onebusaway.gtfs.model.Trip)10 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)10 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)10 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)9 ArrayList (java.util.ArrayList)9 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)8 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)8 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)7 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)7 Route (org.onebusaway.gtfs.model.Route)6 Stop (org.onebusaway.gtfs.model.Stop)6 StopTime (org.onebusaway.gtfs.model.StopTime)6