Search in sources :

Example 36 with BlockInstance

use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.

the class UserReportingServiceImpl method reportProblemWithTrip.

@Override
public void reportProblemWithTrip(TripProblemReportBean problem) {
    AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(problem.getTripId());
    TripEntry trip = _graph.getTripEntryForId(tripId);
    if (trip == null)
        return;
    BlockEntry block = trip.getBlock();
    TripProblemReportRecord record = new TripProblemReportRecord();
    record.setCode(problem.getCode());
    record.setServiceDate(problem.getServiceDate());
    String vehicleId = problem.getVehicleId();
    if (vehicleId != null)
        record.setVehicleId(AgencyAndIdLibrary.convertFromString(vehicleId));
    String stopId = problem.getStopId();
    if (stopId != null)
        record.setStopId(AgencyAndIdLibrary.convertFromString(stopId));
    record.setTime(problem.getTime());
    record.setTripId(tripId);
    record.setBlockId(block.getId());
    record.setUserComment(problem.getUserComment());
    if (problem.getUserLat() != null && !Double.isNaN(problem.getUserLat()))
        record.setUserLat(problem.getUserLat());
    if (problem.getUserLon() != null && !Double.isNaN(problem.getUserLon()))
        record.setUserLon(problem.getUserLon());
    if (problem.getUserLocationAccuracy() != null && !Double.isNaN(problem.getUserLocationAccuracy()))
        record.setUserLocationAccuracy(problem.getUserLocationAccuracy());
    record.setUserOnVehicle(problem.isUserOnVehicle());
    record.setUserVehicleNumber(problem.getUserVehicleNumber());
    Map<BlockInstance, List<BlockLocation>> locationsByInstance = _blockStatusService.getBlocks(block.getId(), problem.getServiceDate(), record.getVehicleId(), problem.getTime());
    BlockInstance blockInstance = getBestBlockInstance(locationsByInstance.keySet());
    if (blockInstance != null) {
        List<BlockLocation> blockLocations = locationsByInstance.get(blockInstance);
        BlockLocation blockLocation = getBestLocation(blockLocations, problem);
        if (blockLocation != null) {
            record.setPredicted(blockLocation.isPredicted());
            if (blockLocation.isDistanceAlongBlockSet())
                record.setDistanceAlongBlock(blockLocation.getDistanceAlongBlock());
            if (blockLocation.isScheduleDeviationSet())
                record.setScheduleDeviation(blockLocation.getScheduleDeviation());
            CoordinatePoint p = blockLocation.getLocation();
            if (p != null) {
                record.setVehicleLat(p.getLat());
                record.setVehicleLon(p.getLon());
            }
            record.setMatchedVehicleId(blockLocation.getVehicleId());
        }
    }
    record.setStatus(problem.getStatus());
    _userReportingDao.saveOrUpdate(record);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) ArrayList(java.util.ArrayList) List(java.util.List) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation)

Example 37 with BlockInstance

use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.

the class ScheduledServiceServiceImpl method routeHasUpcomingScheduledService.

@Override
public Boolean routeHasUpcomingScheduledService(String agencyId, long time, String routeId, String directionId) {
    long serviceStart = time - SCHEDULE_WINDOW_BEFORE;
    long serviceEnd = time + SCHEDULE_WINDOW_AFTER;
    AgencyAndId routeAndId;
    if (routeId != null && routeId.contains("_"))
        routeAndId = AgencyAndIdLibrary.convertFromString(routeId);
    else
        routeAndId = new AgencyAndId(agencyId, routeId);
    List<BlockInstance> instances = _blockCalendarService.getActiveBlocksForRouteInTimeRange(routeAndId, serviceStart, serviceEnd);
    if (instances.isEmpty()) {
        return false;
    }
    for (BlockInstance instance : instances) {
        List<BlockTripEntry> tripsInBlock = instance.getBlock().getTrips();
        if (tripsInBlock.isEmpty()) {
            continue;
        }
        for (BlockTripEntry blockTripEntry : tripsInBlock) {
            TripEntry tripEntry = blockTripEntry.getTrip();
            if (tripEntry.getRoute().getId().toString().equals(routeId)) {
                if (tripEntry.getDirectionId() == null || tripEntry.getDirectionId().equals(directionId)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)

Example 38 with BlockInstance

use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance 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 39 with BlockInstance

use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesBeanServiceImplTest method test.

@Test
public void test() {
    long t = dateAsLong("2010-10-05 16:30");
    long serviceDate = dateAsLong("2010-10-05 00:00");
    int minutesBefore = 5;
    int minutesAfter = 30;
    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.0, -122.0);
    Mockito.when(_transitGraphDao.getStopEntryForId(stopA.getId(), true)).thenReturn(stopA);
    Mockito.when(_transitGraphDao.getStopEntryForId(stopB.getId(), true)).thenReturn(stopB);
    /**
     **
     * Block A
     ***
     */
    BlockEntryImpl blockA = block("blockA");
    TripEntryImpl tripA = trip("tripA", "sA", 3000);
    stopTime(0, stopA, tripA, time(16, 30), time(16, 35), 1000);
    StopTimeEntryImpl stopTimeAB = stopTime(1, stopB, tripA, time(16, 40), time(16, 45), 2000);
    BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds(lsids("sA"), lsids()), tripA);
    BlockStopTimeEntry bstAA = blockConfigA.getStopTimes().get(0);
    BlockStopTimeEntry bstAB = blockConfigA.getStopTimes().get(1);
    /**
     **
     * Block B
     ***
     */
    BlockEntryImpl blockB = block("blockB");
    TripEntryImpl tripB = trip("tripB", "sA", 3000);
    stopTime(2, stopA, tripB, time(16, 40), time(16, 45), 1000);
    StopTimeEntryImpl stopTimeBB = stopTime(3, stopB, tripB, time(16, 50), time(16, 55), 2000);
    BlockConfigurationEntry blockConfigB = blockConfiguration(blockB, serviceIds(lsids("sA"), lsids()), tripB);
    BlockStopTimeEntry bstBA = blockConfigB.getStopTimes().get(0);
    BlockStopTimeEntry bstBB = blockConfigB.getStopTimes().get(1);
    /**
     **
     *
     ***
     */
    BlockInstance blockInstanceA = new BlockInstance(blockConfigA, serviceDate);
    long lastUpdateTime = dateAsLong("2010-10-05 16:15");
    BlockLocation blockLocationA = new BlockLocation();
    blockLocationA.setActiveTrip(bstAA.getTrip());
    blockLocationA.setBlockInstance(blockInstanceA);
    blockLocationA.setClosestStop(bstAA);
    blockLocationA.setDistanceAlongBlock(500);
    blockLocationA.setInService(true);
    blockLocationA.setLastUpdateTime(lastUpdateTime);
    blockLocationA.setNextStop(bstAA);
    blockLocationA.setPredicted(true);
    blockLocationA.setScheduledDistanceAlongBlock(600);
    blockLocationA.setScheduleDeviation(10 * 60);
    blockLocationA.setVehicleId(aid("vehicle"));
    /**
     **
     *
     ***
     */
    BlockInstance blockInstanceB = new BlockInstance(blockConfigB, serviceDate);
    BlockLocation blockLocationB = new BlockLocation();
    blockLocationB.setActiveTrip(bstBA.getTrip());
    blockLocationB.setBlockInstance(blockInstanceA);
    blockLocationB.setClosestStop(bstBA);
    blockLocationB.setDistanceAlongBlock(400);
    blockLocationB.setInService(true);
    blockLocationB.setNextStop(bstAA);
    blockLocationB.setPredicted(false);
    blockLocationB.setScheduledDistanceAlongBlock(400);
    /**
     **
     *
     ***
     */
    long stopTimeFrom = t - minutesBefore * 60 * 1000;
    long stopTimeTo = t + minutesAfter * 60 * 1000;
    StopTimeInstance sti1 = new StopTimeInstance(bstAB, blockInstanceA.getState());
    ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
    in1.setBlockLocation(blockLocationA);
    in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime() + 5 * 60 * 1000));
    in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
    StopTimeInstance sti2 = new StopTimeInstance(bstBB, blockInstanceB.getState());
    ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
    in2.setBlockLocation(blockLocationB);
    TargetTime target = new TargetTime(t, t);
    Mockito.when(_arrivalAndDepartureService.getArrivalsAndDeparturesForStopInTimeRange(stopB, target, stopTimeFrom, stopTimeTo)).thenReturn(Arrays.asList(in1, in2));
    /**
     **
     *
     ***
     */
    Builder stopTimeNarrative = StopTimeNarrative.builder();
    stopTimeNarrative.setStopHeadsign("Downtown");
    Mockito.when(_narrativeService.getStopTimeForEntry(stopTimeAB)).thenReturn(stopTimeNarrative.create());
    stopTimeNarrative = StopTimeNarrative.builder();
    stopTimeNarrative.setRouteShortName("XX");
    Mockito.when(_narrativeService.getStopTimeForEntry(stopTimeBB)).thenReturn(stopTimeNarrative.create());
    /**
     **
     *
     ***
     */
    StopBean stopABean = new StopBean();
    stopABean.setId("1_stopA");
    Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(stopABean);
    StopBean stopBBean = new StopBean();
    stopBBean.setId("1_stopB");
    Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(stopBBean);
    /**
     **
     *
     ***
     */
    TripBean tripABean = new TripBean();
    Mockito.when(_tripBeanService.getTripForId(aid("tripA"))).thenReturn(tripABean);
    TripBean tripBBean = new TripBean();
    Mockito.when(_tripBeanService.getTripForId(aid("tripB"))).thenReturn(tripBBean);
    /**
     **
     *
     ***
     */
    TripStatusBean tripStatusBeanA = new TripStatusBean();
    TripStatusBean tripStatusBeanB = new TripStatusBean();
    Mockito.when(_tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocationA, t)).thenReturn(tripStatusBeanA);
    Mockito.when(_tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocationB, t)).thenReturn(tripStatusBeanB);
    /**
     **
     *
     ***
     */
    ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
    query.setTime(t);
    query.setMinutesBefore(minutesBefore);
    query.setMinutesAfter(minutesAfter);
    query.setFrequencyMinutesBefore(minutesBefore);
    query.setFrequencyMinutesAfter(minutesAfter);
    List<ArrivalAndDepartureBean> arrivalsAndDepartures = _service.getArrivalsAndDeparturesByStopId(stopB.getId(), query);
    assertEquals(2, arrivalsAndDepartures.size());
    ArrivalAndDepartureBean bean = arrivalsAndDepartures.get(0);
    assertEquals(1500, bean.getDistanceFromStop(), 0.0);
    assertEquals(lastUpdateTime, bean.getLastUpdateTime().longValue());
    assertEquals(1, bean.getNumberOfStopsAway());
    assertEquals(dateAsLong("2010-10-05 16:45"), bean.getPredictedArrivalTime());
    assertEquals(dateAsLong("2010-10-05 16:45"), bean.getPredictedDepartureTime());
    assertNull(bean.getRouteShortName());
    assertEquals(dateAsLong("2010-10-05 16:40"), bean.getScheduledArrivalTime());
    assertEquals(dateAsLong("2010-10-05 16:45"), bean.getScheduledDepartureTime());
    assertEquals(serviceDate, bean.getServiceDate());
    assertEquals("default", bean.getStatus());
    assertSame(stopBBean, bean.getStop());
    assertSame(tripABean, bean.getTrip());
    assertSame(tripStatusBeanA, bean.getTripStatus());
    assertEquals("Downtown", bean.getTripHeadsign());
    assertEquals("1_vehicle", bean.getVehicleId());
    bean = arrivalsAndDepartures.get(1);
    assertEquals(1600, bean.getDistanceFromStop(), 0.0);
    assertNull(bean.getLastUpdateTime());
    assertEquals(1, bean.getNumberOfStopsAway());
    assertEquals(0L, bean.getPredictedArrivalTime());
    assertEquals(0L, bean.getPredictedDepartureTime());
    assertEquals("XX", bean.getRouteShortName());
    assertEquals(dateAsLong("2010-10-05 16:50"), bean.getScheduledArrivalTime());
    assertEquals(dateAsLong("2010-10-05 16:55"), bean.getScheduledDepartureTime());
    assertEquals(serviceDate, bean.getServiceDate());
    assertEquals("default", bean.getStatus());
    assertSame(stopBBean, bean.getStop());
    assertSame(tripBBean, bean.getTrip());
    assertSame(tripStatusBeanB, bean.getTripStatus());
    assertNull(bean.getTripHeadsign());
    assertNull(bean.getVehicleId());
}
Also used : StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) Builder(org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative.Builder) TripBean(org.onebusaway.transit_data.model.trips.TripBean) ArrivalsAndDeparturesQueryBean(org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) StopBean(org.onebusaway.transit_data.model.StopBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) 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) Test(org.junit.Test)

Example 40 with BlockInstance

use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.

the class BlockLocationRecordCollectionTest method test01.

@Test
public void test01() {
    BlockEntryImpl block = block("blockA");
    TripEntryImpl trip = trip("tripA", "serviceId");
    stopTime(0, null, trip, time(9, 00), 0);
    BlockConfigurationEntry blockConfig = linkBlockTrips(block, trip);
    BlockInstance blockInstance = new BlockInstance(blockConfig, System.currentTimeMillis());
    SortedMap<Long, BlockLocationRecord> records = new TreeMap<Long, BlockLocationRecord>();
    CoordinatePoint p1 = new CoordinatePoint(47.0, -122.0);
    CoordinatePoint p2 = new CoordinatePoint(47.1, -122.1);
    CoordinatePoint p3 = new CoordinatePoint(47.2, -122.2);
    EVehiclePhase inProgress = EVehiclePhase.IN_PROGRESS;
    EVehiclePhase layover = EVehiclePhase.LAYOVER_DURING;
    addRecord(records, record(t(4, 10), 10.0, 100.0, p1, 0.0, inProgress, "ok"));
    addRecord(records, record(t(8, 20), 18.0, 200.0, p2, 90.0, layover, "not ok"));
    addRecord(records, record(t(12, 30), 15.0, 300.0, p3, 45.0, inProgress, "ok"));
    BlockLocationRecordCollection entry = new BlockLocationRecordCollection(t(3, 20), t(13, 20), records);
    assertEquals(t(3, 20), entry.getFromTime());
    assertEquals(t(13, 20), entry.getToTime());
    assertEquals(10, entry.getScheduleDeviationForTargetTime(t(3, 20)), 0.0);
    assertEquals(10, entry.getScheduleDeviationForTargetTime(t(4, 10)), 0.0);
    assertEquals(12, entry.getScheduleDeviationForTargetTime(t(5, 12)), 0.0);
    assertEquals(14, entry.getScheduleDeviationForTargetTime(t(6, 15)), 0.0);
    assertEquals(16, entry.getScheduleDeviationForTargetTime(t(7, 18)), 0.0);
    assertEquals(18, entry.getScheduleDeviationForTargetTime(t(8, 20)), 0.0);
    assertEquals(17, entry.getScheduleDeviationForTargetTime(t(10, 0)), 0.0);
    assertEquals(15, entry.getScheduleDeviationForTargetTime(t(12, 30)), 0.0);
    assertEquals(15, entry.getScheduleDeviationForTargetTime(t(13, 20)), 0.0);
    assertEquals(80, entry.getDistanceAlongBlockForTargetTime(t(3, 20)), 0.0);
    assertEquals(100, entry.getDistanceAlongBlockForTargetTime(t(4, 10)), 0.0);
    assertEquals(124.8, entry.getDistanceAlongBlockForTargetTime(t(5, 12)), 0.0);
    assertEquals(150, entry.getDistanceAlongBlockForTargetTime(t(6, 15)), 0.0);
    assertEquals(175.2, entry.getDistanceAlongBlockForTargetTime(t(7, 18)), 0.0);
    assertEquals(200, entry.getDistanceAlongBlockForTargetTime(t(8, 20)), 0.0);
    assertEquals(240, entry.getDistanceAlongBlockForTargetTime(t(10, 0)), 0.0);
    assertEquals(300, entry.getDistanceAlongBlockForTargetTime(t(12, 30)), 0.0);
    assertEquals(320, entry.getDistanceAlongBlockForTargetTime(t(13, 20)), 0.0);
    assertNull(entry.getLastLocationForTargetTime(t(3, 20)));
    assertNull(entry.getLastLocationForTargetTime(t(4, 9)));
    assertEquals(p1, entry.getLastLocationForTargetTime(t(4, 10)));
    assertEquals(p1, entry.getLastLocationForTargetTime(t(5, 12)));
    assertEquals(p1, entry.getLastLocationForTargetTime(t(8, 19)));
    assertEquals(p2, entry.getLastLocationForTargetTime(t(8, 20)));
    assertEquals(p2, entry.getLastLocationForTargetTime(t(10, 0)));
    assertEquals(p2, entry.getLastLocationForTargetTime(t(12, 29)));
    assertEquals(p3, entry.getLastLocationForTargetTime(t(12, 30)));
    assertEquals(p3, entry.getLastLocationForTargetTime(t(16, 40)));
    assertTrue(Double.isNaN(entry.getLastOrientationForTargetTime(t(3, 20))));
    assertTrue(Double.isNaN(entry.getLastOrientationForTargetTime(t(4, 9))));
    assertEquals(0.0, entry.getLastOrientationForTargetTime(t(4, 10)), 0.0);
    assertEquals(0.0, entry.getLastOrientationForTargetTime(t(5, 12)), 0.0);
    assertEquals(0.0, entry.getLastOrientationForTargetTime(t(8, 19)), 0.0);
    assertEquals(90.0, entry.getLastOrientationForTargetTime(t(8, 20)), 0.0);
    assertEquals(90.0, entry.getLastOrientationForTargetTime(t(10, 0)), 0.0);
    assertEquals(90.0, entry.getLastOrientationForTargetTime(t(12, 29)), 0.0);
    assertEquals(45.0, entry.getLastOrientationForTargetTime(t(12, 30)), 0.0);
    assertEquals(45.0, entry.getLastOrientationForTargetTime(t(16, 40)), 0.0);
    assertNull(entry.getPhaseForTargetTime(t(3, 20)));
    assertNull(entry.getPhaseForTargetTime(t(4, 9)));
    assertEquals(inProgress, entry.getPhaseForTargetTime(t(4, 10)));
    assertEquals(inProgress, entry.getPhaseForTargetTime(t(5, 12)));
    assertEquals(inProgress, entry.getPhaseForTargetTime(t(8, 19)));
    assertEquals(layover, entry.getPhaseForTargetTime(t(8, 20)));
    assertEquals(layover, entry.getPhaseForTargetTime(t(10, 0)));
    assertEquals(layover, entry.getPhaseForTargetTime(t(12, 29)));
    assertEquals(inProgress, entry.getPhaseForTargetTime(t(12, 30)));
    assertEquals(inProgress, entry.getPhaseForTargetTime(t(16, 40)));
    assertNull(entry.getStatusForTargetTime(t(3, 20)));
    assertNull(entry.getStatusForTargetTime(t(4, 9)));
    assertEquals("ok", entry.getStatusForTargetTime(t(4, 10)));
    assertEquals("ok", entry.getStatusForTargetTime(t(5, 12)));
    assertEquals("ok", entry.getStatusForTargetTime(t(8, 19)));
    assertEquals("not ok", entry.getStatusForTargetTime(t(8, 20)));
    assertEquals("not ok", entry.getStatusForTargetTime(t(10, 0)));
    assertEquals("not ok", entry.getStatusForTargetTime(t(12, 29)));
    assertEquals("ok", entry.getStatusForTargetTime(t(12, 30)));
    assertEquals("ok", entry.getStatusForTargetTime(t(16, 40)));
    CoordinatePoint p4 = new CoordinatePoint(47.15, -122.15);
    entry = entry.addRecord(blockInstance, record(t(10, 0), 20, 220, p4, 270.0, layover, "not ok"), t(5, 0));
    assertEquals(t(6, 40), entry.getFromTime());
    assertEquals(t(11, 40), entry.getToTime());
    assertEquals(18, entry.getScheduleDeviationForTargetTime(t(6, 40)), 0.0);
    assertEquals(18, entry.getScheduleDeviationForTargetTime(t(8, 20)), 0.0);
    assertEquals(19, entry.getScheduleDeviationForTargetTime(t(9, 10)), 0.0);
    assertEquals(20, entry.getScheduleDeviationForTargetTime(t(10, 00)), 0.0);
    assertEquals(20, entry.getScheduleDeviationForTargetTime(t(10, 50)), 0.0);
    assertEquals(20, entry.getScheduleDeviationForTargetTime(t(11, 40)), 0.0);
    assertEquals(180, entry.getDistanceAlongBlockForTargetTime(t(6, 40)), 0.0);
    assertEquals(200, entry.getDistanceAlongBlockForTargetTime(t(8, 20)), 0.0);
    assertEquals(210, entry.getDistanceAlongBlockForTargetTime(t(9, 10)), 0.0);
    assertEquals(220, entry.getDistanceAlongBlockForTargetTime(t(10, 00)), 0.0);
    assertEquals(230, entry.getDistanceAlongBlockForTargetTime(t(10, 50)), 0.0);
    assertEquals(240, entry.getDistanceAlongBlockForTargetTime(t(11, 40)), 0.0);
    assertNull(entry.getLastLocationForTargetTime(t(6, 40)));
    assertEquals(p2, entry.getLastLocationForTargetTime(t(8, 20)));
    assertEquals(p2, entry.getLastLocationForTargetTime(t(9, 10)));
    assertEquals(p4, entry.getLastLocationForTargetTime(t(10, 00)));
    assertEquals(p4, entry.getLastLocationForTargetTime(t(10, 50)));
    assertTrue(Double.isNaN(entry.getLastOrientationForTargetTime(t(6, 40))));
    assertEquals(90.0, entry.getLastOrientationForTargetTime(t(8, 20)), 0.0);
    assertEquals(90.0, entry.getLastOrientationForTargetTime(t(9, 10)), 0.0);
    assertEquals(270.0, entry.getLastOrientationForTargetTime(t(10, 00)), 0.0);
    assertEquals(270.0, entry.getLastOrientationForTargetTime(t(10, 50)), 0.0);
    assertNull(entry.getPhaseForTargetTime(t(6, 40)));
    assertEquals(layover, entry.getPhaseForTargetTime(t(8, 20)));
    assertEquals(layover, entry.getPhaseForTargetTime(t(9, 10)));
    assertEquals(layover, entry.getPhaseForTargetTime(t(10, 00)));
    assertEquals(layover, entry.getPhaseForTargetTime(t(10, 50)));
    assertNull(entry.getStatusForTargetTime(t(6, 40)));
    assertEquals("not ok", entry.getStatusForTargetTime(t(8, 20)));
    assertEquals("not ok", entry.getStatusForTargetTime(t(9, 10)));
    assertEquals("not ok", entry.getStatusForTargetTime(t(10, 00)));
    assertEquals("not ok", entry.getStatusForTargetTime(t(10, 50)));
    CoordinatePoint p5 = new CoordinatePoint(47.4, -122.4);
    entry = entry.addRecord(blockInstance, record(t(16, 40), 14, 500, p5, 180.0, inProgress, "ok"), t(6, 40));
    assertEquals(t(10, 00), entry.getFromTime());
    assertEquals(t(16, 40), entry.getToTime());
    assertEquals(20, entry.getScheduleDeviationForTargetTime(t(9, 10)), 0.0);
    assertEquals(17, entry.getScheduleDeviationForTargetTime(t(13, 20)), 0.0);
    assertEquals(14, entry.getScheduleDeviationForTargetTime(t(16, 40)), 0.0);
    assertEquals(220, entry.getDistanceAlongBlockForTargetTime(t(10, 00)), 0.0);
    assertEquals(360, entry.getDistanceAlongBlockForTargetTime(t(13, 20)), 0.0);
    assertEquals(500, entry.getDistanceAlongBlockForTargetTime(t(16, 40)), 0.0);
    assertEquals(640, entry.getDistanceAlongBlockForTargetTime(t(20, 00)), 0.0);
    assertNull(entry.getLastLocationForTargetTime(t(6, 40)));
    assertEquals(p4, entry.getLastLocationForTargetTime(t(10, 00)));
    assertEquals(p4, entry.getLastLocationForTargetTime(t(13, 20)));
    assertEquals(p5, entry.getLastLocationForTargetTime(t(16, 40)));
    assertEquals(p5, entry.getLastLocationForTargetTime(t(20, 00)));
    assertTrue(Double.isNaN(entry.getLastOrientationForTargetTime(t(6, 40))));
    assertEquals(270.0, entry.getLastOrientationForTargetTime(t(10, 00)), 0.0);
    assertEquals(270.0, entry.getLastOrientationForTargetTime(t(13, 20)), 0.0);
    assertEquals(180.0, entry.getLastOrientationForTargetTime(t(16, 40)), 0.0);
    assertEquals(180.0, entry.getLastOrientationForTargetTime(t(20, 00)), 0.0);
    assertNull(entry.getPhaseForTargetTime(t(6, 40)));
    assertEquals(layover, entry.getPhaseForTargetTime(t(10, 00)));
    assertEquals(layover, entry.getPhaseForTargetTime(t(13, 20)));
    assertEquals(inProgress, entry.getPhaseForTargetTime(t(16, 40)));
    assertEquals(inProgress, entry.getPhaseForTargetTime(t(20, 00)));
    assertNull(entry.getStatusForTargetTime(t(6, 40)));
    assertEquals("not ok", entry.getStatusForTargetTime(t(10, 00)));
    assertEquals("not ok", entry.getStatusForTargetTime(t(13, 20)));
    assertEquals("ok", entry.getStatusForTargetTime(t(16, 40)));
    assertEquals("ok", entry.getStatusForTargetTime(t(20, 00)));
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) EVehiclePhase(org.onebusaway.realtime.api.EVehiclePhase) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) TreeMap(java.util.TreeMap) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Test(org.junit.Test)

Aggregations

BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)63 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)36 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)25 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)24 Test (org.junit.Test)20 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)20 ArrayList (java.util.ArrayList)19 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)19 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)16 Date (java.util.Date)15 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)12 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)12 List (java.util.List)11 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)11 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)10 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)10 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)10 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)9 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)9 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)9