Package org.onebusaway.transit_data_federation.services.blocks

Examples of org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation


      double distanceAlongBlock = index.distanceAlongShape;

      if (distanceAlongBlock > block.getTotalBlockDistance())
        distanceAlongBlock = block.getTotalBlockDistance();

      ScheduledBlockLocation blockLocation = _scheduledBlockLocationService.getScheduledBlockLocationFromDistanceAlongBlock(
          block, distanceAlongBlock);

      if (blockLocation != null) {
        int scheduledTime = blockLocation.getScheduledTime();
        long scheduleTimestamp = blockInstance.getServiceDate() + scheduledTime
            * 1000;

        double delta = Math.abs(scheduleTimestamp - timestamp);
        best.add(delta, blockLocation);
View Full Code Here


    BlockInstance instance = getVehicleLocationRecordAsBlockInstance(record);

    if (instance != null) {

      ScheduledBlockLocation scheduledBlockLocation = getScheduledBlockLocationForVehicleLocationRecord(
          record, instance);

      if (!record.isScheduleDeviationSet()) {
        int deviation = (int) ((record.getTimeOfRecord() - record.getServiceDate()) / 1000 - scheduledBlockLocation.getScheduledTime());
        record.setScheduleDeviation(deviation);
      }

      ScheduleDeviationSamples samples = _realTimeHistoryService.sampleScheduleDeviationsForVehicle(
          instance, record, scheduledBlockLocation);
View Full Code Here

  private ScheduledBlockLocation getScheduledBlockLocationForVehicleLocationCacheRecord(
      BlockInstance blockInstance, VehicleLocationCacheElement cacheElement,
      long targetTime) {

    VehicleLocationRecord record = cacheElement.getRecord();
    ScheduledBlockLocation scheduledBlockLocation = cacheElement.getScheduledBlockLocation();

    BlockConfigurationEntry blockConfig = blockInstance.getBlock();
    long serviceDate = blockInstance.getServiceDate();

    int scheduledTime = (int) ((targetTime - serviceDate) / 1000);

    /**
     * If location interpolation has been turned off, then we assume the vehicle
     * is at its last known location, so we return that if it's been stored with
     * the cache element.
     */
    if (!_locationInterpolation && scheduledBlockLocation != null) {
      return scheduledBlockLocation;
    }

    if (record.isScheduleDeviationSet()) {

      /**
       * Effective scheduled time is the point that a transit vehicle is at on
       * its schedule, with schedule deviation taken into account. So if it's
       * 100 minutes into the current service date and the bus is running 10
       * minutes late, it's actually at the 90 minute point in its scheduled
       * operation.
       */
      int effectiveScheduledTime = (int) (scheduledTime - record.getScheduleDeviation());

      if (scheduledBlockLocation != null
          && scheduledBlockLocation.getScheduledTime() <= effectiveScheduledTime) {

        return _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(
            scheduledBlockLocation, effectiveScheduledTime);
      }

      return _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(
          blockConfig, effectiveScheduledTime);
    }

    if (record.isDistanceAlongBlockSet()) {

      if ((_locationInterpolation || _distanceAlongBlockLocationInterpolation)
          && scheduledBlockLocation != null
          && scheduledBlockLocation.getDistanceAlongBlock() <= record.getDistanceAlongBlock()) {

        int ellapsedTime = (int) ((targetTime - record.getTimeOfRecord()) / 1000);

        if (ellapsedTime >= 0) {

          int effectiveScheduledTime = scheduledBlockLocation.getScheduledTime()
              + ellapsedTime;

          return _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(
              blockConfig, effectiveScheduledTime);
        }
View Full Code Here

        blockId, serviceDate);

    if (blockInstance == null)
      return null;

    ScheduledBlockLocation blockLocation = _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(
        blockInstance.getBlock(), scheduledTime);

    if (blockLocation == null)
      return null;
View Full Code Here

    DoubleArrayList ps = new DoubleArrayList();
    List<ScheduledBlockLocation> blockLocations = new ArrayList<ScheduledBlockLocation>();

    Record firstRecord = records.get(0);
    ScheduledBlockLocation firstLocation = _blockGeospatialService.getBestScheduledBlockLocationForLocation(
        blockInstance, firstRecord.getLocation(), firstRecord.getTimestamp(),
        0, Double.POSITIVE_INFINITY);
    blockLocations.add(firstLocation);

    ps.add(updateScheduledBlockLocationProbability(blockInstance, firstRecord,
        firstLocation));

    Record lastRecord = records.get(records.size() - 1);
    ScheduledBlockLocation lastLocation = _blockGeospatialService.getBestScheduledBlockLocationForLocation(
        blockInstance, lastRecord.getLocation(), lastRecord.getTimestamp(), 0,
        Double.POSITIVE_INFINITY);

    ps.add(updateScheduledBlockLocationProbability(blockInstance, lastRecord,
        lastLocation));

    if (Descriptive.mean(ps) < minProbabilityForConsideration)
      return;

    /**
     * If the vehicle is traveling backwards in time, we kill the prediction
     */
    int maxTravelBackwardsTime = computeMaxTravelBackwardsTime(lastRecord.getTimestamp()
        - firstRecord.getTimestamp());

    if (lastLocation.getScheduledTime() < firstLocation.getScheduledTime()
        - maxTravelBackwardsTime)
      return;

    double minDistanceAlongBlock = Math.min(
        firstLocation.getDistanceAlongBlock(),
        lastLocation.getDistanceAlongBlock()) - 500;
    double maxDistanceAlongBlock = Math.max(
        firstLocation.getDistanceAlongBlock(),
        lastLocation.getDistanceAlongBlock()) + 500;

    for (int i = 1; i < records.size() - 1; i++) {

      Record record = records.get(i);
      ScheduledBlockLocation location = _blockGeospatialService.getBestScheduledBlockLocationForLocation(
          blockInstance, record.getLocation(), record.getTimestamp(),
          minDistanceAlongBlock, maxDistanceAlongBlock);
      blockLocations.add(location);

      ps.add(updateScheduledBlockLocationProbability(blockInstance, record,
View Full Code Here

      if (recordDeltaT <= 0)
        continue;

      int maxTravelBackwardsTime = computeMaxTravelBackwardsTime(recordDeltaT);

      ScheduledBlockLocation prevLocation = blockLocations.get(i - 1);
      ScheduledBlockLocation nextLocation = blockLocations.get(i);
      int locationDeltaT = nextLocation.getScheduledTime()
          - prevLocation.getScheduledTime();

      if (locationDeltaT < 0
          && Math.abs(locationDeltaT) > maxTravelBackwardsTime)
        ps.set(i, 0.0);
View Full Code Here

      int effectiveScheduleTime = (int) (record.getTime() - blockInstance.getServiceDate() / 1000);
      int adjustedScheduleTime = effectiveScheduleTime
          - record.getScheduleDeviation();

      ScheduledBlockLocation location = _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(
          blockConfig, adjustedScheduleTime);

      if (location != null) {
        message.setDistanceAlongBlock(location.getDistanceAlongBlock());

        BlockTripEntry activeTrip = location.getActiveTrip();
        if (activeTrip != null) {
          message.setTripId(activeTrip.getTrip().getId());
          _currentResult.addMatchedTripId(activeTrip.getTrip().getId().toString());
        } else {
          _log.error("invalid trip for location=" + location);
          _currentResult.addUnmatchedTripId(blockId.toString()); // this isn't exactly right
        }
        // Are we at the start of the block?
        if (location.getDistanceAlongBlock() == 0) {

          VehicleLocationRecord lastRecord = _lastRecordByVehicleId.get(message.getVehicleId());
          boolean inMotion = true;
          if (lastRecord != null && lastRecord.isCurrentLocationSet()
              && message.isCurrentLocationSet()) {
View Full Code Here

    BlockLocation location = _service.getLocationForBlockInstance(
        blockInstance, target);

    assertNull(location);

    ScheduledBlockLocation p = new ScheduledBlockLocation();
    p.setActiveTrip(blockConfig.getTrips().get(0));
    p.setClosestStop(blockConfig.getStopTimes().get(0));
    p.setClosestStopTimeOffset(0);
    p.setDistanceAlongBlock(0);
    p.setLocation(new CoordinatePoint(stopA.getStopLat(), stopA.getStopLon()));
    p.setInService(true);

    Mockito.when(
        _blockLocationService.getScheduledBlockLocationFromScheduledTime(
            blockConfig, 1800)).thenReturn(p);
View Full Code Here

  }

  @Test
  public void test00a() {

    ScheduledBlockLocation position = _service.getScheduledBlockLocationFromScheduledTime(
        _blockConfig, time(9, 55));

    assertEquals(_tripA, position.getActiveTrip());
    assertEquals(_stopTimeA, position.getClosestStop());
    assertEquals(300, position.getClosestStopTimeOffset());
    assertNull(position.getPreviousStop());
    assertEquals(_stopTimeA, position.getNextStop());
    assertEquals(300, position.getNextStopTimeOffset());
    assertEquals(0.0, position.getDistanceAlongBlock(), 0.0);
    assertEquals(47.670170374084805, position.getLocation().getLat(), 1e-6);
    assertEquals(-122.3875880241394, position.getLocation().getLon(), 1e-6);
    assertEquals(270.8, position.getOrientation(), 0.1);
    assertEquals(time(9, 55), position.getScheduledTime());
    assertFalse(position.isInService());
    assertEquals(0, position.getStopTimeIndex());

    ScheduledBlockLocation next = _service.getScheduledBlockLocationFromScheduledTime(
        position, time(9, 57));
    assertEquals(time(9, 57), next.getScheduledTime());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 00));
    assertEquals(time(10, 00), next.getScheduledTime());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 10));
    assertEquals(time(10, 10), next.getScheduledTime());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 17));
    assertEquals(time(10, 17), next.getScheduledTime());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 20));
    assertEquals(time(10, 20), next.getScheduledTime());

    position = _service.getScheduledBlockLocationFromDistanceAlongBlock(
        _blockConfig, -100);
    assertNull(position);
View Full Code Here

  }

  @Test
  public void test00b() {

    ScheduledBlockLocation position = _service.getScheduledBlockLocationFromScheduledTime(
        _blockConfig, time(9, 59));

    assertEquals(_tripA, position.getActiveTrip());
    assertEquals(_stopTimeA, position.getClosestStop());
    assertEquals(60, position.getClosestStopTimeOffset());
    assertNull(position.getPreviousStop());
    assertEquals(_stopTimeA, position.getNextStop());
    assertEquals(60, position.getNextStopTimeOffset());
    assertEquals(140.0, position.getDistanceAlongBlock(), 0.0);
    assertEquals(47.668911387520204, position.getLocation().getLat(), 1e-6);
    assertEquals(-122.38756951346872, position.getLocation().getLon(), 1e-6);
    assertEquals(270.8, position.getOrientation(), 0.1);
    assertEquals(time(9, 59), position.getScheduledTime());
    assertTrue(position.isInService());
    assertEquals(0, position.getStopTimeIndex());

    position = _service.getScheduledBlockLocationFromDistanceAlongBlock(
        _blockConfig, 140.0);

    assertEquals(_tripA, position.getActiveTrip());
    assertEquals(_stopTimeA, position.getClosestStop());
    assertEquals(60, position.getClosestStopTimeOffset());
    assertNull(position.getPreviousStop());
    assertEquals(_stopTimeA, position.getNextStop());
    assertEquals(60, position.getNextStopTimeOffset());
    assertEquals(140.0, position.getDistanceAlongBlock(), 0.0);
    assertEquals(47.668911387520204, position.getLocation().getLat(), 1e-6);
    assertEquals(-122.38756951346872, position.getLocation().getLon(), 1e-6);
    assertEquals(270.8, position.getOrientation(), 0.1);
    assertEquals(time(9, 59), position.getScheduledTime());
    assertTrue(position.isInService());
    assertEquals(0, position.getStopTimeIndex());
  }
View Full Code Here

TOP

Related Classes of org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.