Package org.onebusaway.transit_data_federation.services.blocks

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


  }

  @Test
  public void test07() {

    ScheduledBlockLocation position = _service.getScheduledBlockLocationFromScheduledTime(
        _blockConfig, time(10, 20));

    assertEquals(_tripB, position.getActiveTrip());
    assertEquals(_stopTimeC, position.getClosestStop());
    assertEquals(0, position.getClosestStopTimeOffset());
    assertEquals(_stopTimeB, position.getPreviousStop());
    assertEquals(_stopTimeC, position.getNextStop());
    assertEquals(0, position.getNextStopTimeOffset());
    assertEquals(1200, position.getDistanceAlongBlock(), 0.0);
    assertEquals(_stopC.getStopLat(), position.getLocation().getLat(), 1e-6);
    assertEquals(_stopC.getStopLon(), position.getLocation().getLon(), 1e-6);
    assertEquals(0.0, position.getOrientation(), 0.1);
    assertTrue(position.isInService());
    assertEquals(2, position.getStopTimeIndex());
  }
View Full Code Here


  }

  @Test
  public void test08() {

    ScheduledBlockLocation position = _service.getScheduledBlockLocationFromScheduledTime(
        _blockConfig, time(10, 25));

    assertNull(position);

    position = _service.getScheduledBlockLocationFromDistanceAlongBlock(
        _blockConfig, 1500);

    assertEquals(_tripB, position.getActiveTrip());
    assertEquals(_stopTimeC, position.getClosestStop());
    assertEquals(-225, position.getClosestStopTimeOffset());
    assertNull(position.getPreviousStop());
    assertNull(position.getNextStop());
    assertEquals(0, position.getNextStopTimeOffset());
    assertEquals(1500, position.getDistanceAlongBlock(), 0.0);
    assertEquals(47.663667674849385, position.getLocation().getLat(), 1e-6);
    assertEquals(-122.37355470657349, position.getLocation().getLon(), 1e-6);
    assertEquals(0.0, position.getOrientation(), 0.1);
    assertFalse(position.isInService());
    assertEquals(3, position.getStopTimeIndex());
  }
View Full Code Here

  }

  @Test
  public void test09() {

    ScheduledBlockLocation position = _service.getScheduledBlockLocationFromDistanceAlongBlock(
        _blockConfig, 2500);

    assertNull(position);
  }
View Full Code Here

  }

  @Test
  public void testHint00() {

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

    ScheduledBlockLocation next = _service.getScheduledBlockLocationFromScheduledTime(
        position, time(9, 55));
    assertEquals(time(9, 55), next.getScheduledTime());
    assertEquals(0, next.getDistanceAlongBlock(), 0.0);
    assertEquals(0, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(9, 58));
    assertEquals(time(9, 58), next.getScheduledTime());
    assertEquals(80, next.getDistanceAlongBlock(), 0.0);
    assertEquals(0, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 00));
    assertEquals(time(10, 00), next.getScheduledTime());
    assertEquals(200, next.getDistanceAlongBlock(), 0.0);
    assertEquals(0, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 05));
    assertEquals(time(10, 05), next.getScheduledTime());
    assertEquals(500, next.getDistanceAlongBlock(), 0.0);
    assertEquals(1, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 10));
    assertEquals(time(10, 10), next.getScheduledTime());
    assertEquals(800, next.getDistanceAlongBlock(), 0.0);
    assertEquals(1, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 17));
    assertEquals(time(10, 17), next.getScheduledTime());
    assertEquals(960, next.getDistanceAlongBlock(), 0.0);
    assertEquals(2, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 20));
    assertEquals(time(10, 20), next.getScheduledTime());
    assertEquals(1200, next.getDistanceAlongBlock(), 0.0);
    assertEquals(2, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 25));
    assertNull(next);
View Full Code Here

  }

  @Test
  public void testHint01() {

    ScheduledBlockLocation position = _service.getScheduledBlockLocationFromScheduledTime(
        _blockConfig, time(10, 05));

    try {
      _service.getScheduledBlockLocationFromScheduledTime(position, time(9, 58));
      fail();
    } catch (Throwable ex) {

    }

    ScheduledBlockLocation next = _service.getScheduledBlockLocationFromScheduledTime(
        position, time(10, 05));
    assertEquals(time(10, 05), next.getScheduledTime());
    assertEquals(500, next.getDistanceAlongBlock(), 0.0);
    assertEquals(1, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 10));
    assertEquals(time(10, 10), next.getScheduledTime());
    assertEquals(800, next.getDistanceAlongBlock(), 0.0);
    assertEquals(1, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 17));
    assertEquals(time(10, 17), next.getScheduledTime());
    assertEquals(960, next.getDistanceAlongBlock(), 0.0);
    assertEquals(2, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 20));
    assertEquals(time(10, 20), next.getScheduledTime());
    assertEquals(1200, next.getDistanceAlongBlock(), 0.0);
    assertEquals(2, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromScheduledTime(position,
        time(10, 25));
    assertNull(next);

    /****
     *
     ****/

    position = _service.getScheduledBlockLocationFromDistanceAlongBlock(
        _blockConfig, 500);

    try {
      _service.getScheduledBlockLocationFromDistanceAlongBlock(position, 400);
      fail();
    } catch (Throwable ex) {

    }

    next = _service.getScheduledBlockLocationFromDistanceAlongBlock(position,
        680);
    assertEquals(time(10, 8), next.getScheduledTime());
    assertEquals(680, next.getDistanceAlongBlock(), 0.0);
    assertEquals(1, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromDistanceAlongBlock(position,
        800);
    assertEquals(time(10, 10), next.getScheduledTime());
    assertEquals(800, next.getDistanceAlongBlock(), 0.0);
    assertEquals(1, next.getStopTimeIndex());

    next = _service.getScheduledBlockLocationFromDistanceAlongBlock(position,
        960);
    assertEquals(time(10, 17), next.getScheduledTime());
    assertEquals(960, next.getDistanceAlongBlock(), 0.0);
    assertEquals(2, next.getStopTimeIndex());
  }
View Full Code Here

  private ScheduledBlockLocation getScheduledBlockLocationWhenAtStopTime(
      BlockStopTimeEntry blockStopTime, BlockStopTimeEntry previousBlockStopTime,
      StopTimeEntry stopTime, int scheduleTime, int stopTimeIndex) {
    StopEntry stop = stopTime.getStop();

    ScheduledBlockLocation result = new ScheduledBlockLocation();

    int shapePointIndex = stopTime.getShapePointIndex();

    PointAndOrientation po = getLocationAlongShape(blockStopTime.getTrip(),
        blockStopTime.getDistanceAlongBlock(), shapePointIndex,
        shapePointIndex + 1);
    if (po != null) {
      result.setLocation(po.getPoint());
      result.setOrientation(po.getOrientation());
    } else {
      CoordinatePoint location = new CoordinatePoint(stop.getStopLat(),
          stop.getStopLon());
      result.setLocation(location);
      result.setOrientation(0);
    }

    result.setClosestStop(blockStopTime);
    result.setClosestStopTimeOffset(0);
    result.setNextStop(blockStopTime);
    result.setNextStopTimeOffset(0);
    result.setScheduledTime(scheduleTime);
    result.setDistanceAlongBlock(blockStopTime.getDistanceAlongBlock());
    result.setActiveTrip(blockStopTime.getTrip());
    result.setInService(true);
    result.setStopTimeIndex(stopTimeIndex);
   
    // If there is more than 1 stop, grab the previous stop
    if(blockStopTime.hasPreviousStop()){
      result.setPreviousStop(previousBlockStopTime);
   }
   
    return result;
  }
View Full Code Here

    BlockStopTimeEntry blockAfter = stopTimes.get(stopTimeIndex);

    StopTimeEntry before = blockBefore.getStopTime();
    StopTimeEntry after = blockAfter.getStopTime();

    ScheduledBlockLocation result = new ScheduledBlockLocation();
    result.setScheduledTime(scheduleTime);
    result.setInService(true);
    result.setStopTimeIndex(stopTimeIndex);

    int fromTime = before.getDepartureTime();
    int toTime = after.getArrivalTime();

    int fromTimeOffset = fromTime - scheduleTime;
    int toTimeOffset = toTime - scheduleTime;

    if (Math.abs(fromTimeOffset) < Math.abs(toTimeOffset)) {
      result.setClosestStop(blockBefore);
      result.setClosestStopTimeOffset(fromTimeOffset);
    } else {
      result.setClosestStop(blockAfter);
      result.setClosestStopTimeOffset(toTimeOffset);
    }
    result.setPreviousStop(blockBefore);
    result.setNextStop(blockAfter);
    result.setNextStopTimeOffset(toTimeOffset);

    double ratio = (scheduleTime - fromTime) / ((double) (toTime - fromTime));

    double fromDistance = blockBefore.getDistanceAlongBlock();
    double toDistance = blockAfter.getDistanceAlongBlock();

    double distanceAlongBlock = ratio * (toDistance - fromDistance)
        + fromDistance;
   
    result.setDistanceAlongBlock(distanceAlongBlock);

    int shapePointIndexFrom = -1;
    int shapePointIndexTo = -1;

    /**
     * Are we between trips? Where is the transition point?
     */
    if (!before.getTrip().equals(after.getTrip())) {

      if (distanceAlongBlock >= blockAfter.getTrip().getDistanceAlongBlock()) {
        result.setActiveTrip(blockAfter.getTrip());
        shapePointIndexFrom = 0;
        shapePointIndexTo = nextShapePointIndex(after);
      } else {
        result.setActiveTrip(blockBefore.getTrip());
        shapePointIndexFrom = before.getShapePointIndex();
        shapePointIndexTo = Integer.MAX_VALUE;
      }
    } else {
      result.setActiveTrip(blockBefore.getTrip());
      shapePointIndexFrom = before.getShapePointIndex();
      shapePointIndexTo = nextShapePointIndex(after);
    }

    BlockTripEntry activeTrip = result.getActiveTrip();

    PointAndOrientation po = getLocationAlongShape(activeTrip,
        distanceAlongBlock, shapePointIndexFrom, shapePointIndexTo);

    if (po != null) {
      result.setLocation(po.getPoint());
      result.setOrientation(po.getOrientation());
      return result;
    }

    StopEntry beforeStop = before.getStop();
    StopEntry afterStop = after.getStop();
    double latFrom = beforeStop.getStopLat();
    double lonFrom = beforeStop.getStopLon();
    double latTo = afterStop.getStopLat();
    double lonTo = afterStop.getStopLon();
    double lat = (latTo - latFrom) * ratio + latFrom;
    double lon = (lonTo - lonFrom) * ratio + lonFrom;

    CoordinatePoint location = new CoordinatePoint(lat, lon);
    result.setLocation(location);

    double orientation = SphericalGeometryLibrary.getOrientation(latFrom,
        lonFrom, latTo, lonTo);
    result.setOrientation(orientation);

    return result;
  }
View Full Code Here

    if (!Double.isNaN(distanceAlongBlock))
      po = getLocationAlongShape(blockStopTime.getTrip(), distanceAlongBlock,
          0, nextShapePointIndex(stopTime));

    ScheduledBlockLocation result = new ScheduledBlockLocation();

    if (po != null) {
      result.setLocation(po.getPoint());
      result.setOrientation(po.getOrientation());
    }

    result.setClosestStop(blockStopTime);
    result.setClosestStopTimeOffset(stopTime.getArrivalTime() - scheduleTime);
    result.setPreviousStop(null);
    result.setNextStop(blockStopTime);
    result.setNextStopTimeOffset(stopTime.getArrivalTime() - scheduleTime);
    result.setScheduledTime(scheduleTime);
    result.setDistanceAlongBlock(distanceAlongBlock);
    result.setActiveTrip(blockStopTime.getTrip());
    result.setInService(inService);
    result.setStopTimeIndex(0);
    return result;
  }
View Full Code Here

       */
      shapePointIndexFrom = to.getShapePointIndex();
      shapePointIndexTo = Integer.MAX_VALUE;
    }

    ScheduledBlockLocation location = new ScheduledBlockLocation();
    location.setActiveTrip(activeTrip);
    location.setClosestStop(closestStop);
    location.setClosestStopTimeOffset(closestStop.getStopTime().getArrivalTime()
        - scheduledTime);
    location.setPreviousStop(previousStop);
    location.setNextStop(nextStop);
    if (nextStop != null)
      location.setNextStopTimeOffset(nextStop.getStopTime().getArrivalTime()
          - scheduledTime);
    location.setInService(nextStop != null);
    location.setStopTimeIndex(stopTimeIndex);
    location.setDistanceAlongBlock(distanceAlongBlock);
    location.setScheduledTime(scheduledTime);

    /**
     * In this case, distance along block and distance along trip are the same
     * because we are still in the first trip of the block
     */

    PointAndOrientation po = getLocationAlongShape(activeTrip,
        distanceAlongBlock, shapePointIndexFrom, shapePointIndexTo);

    if (po != null) {
      location.setLocation(po.getPoint());
      location.setOrientation(po.getOrientation());
    }

    return location;
  }
View Full Code Here

    for (int i = 0; i < 5 * 60; i += 30) {

      int scheduleTime = (int) ((time - blockInstance.getServiceDate()) / 1000
          - scheduleDeviation - i);

      ScheduledBlockLocation location = _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(
          blockInstance.getBlock(), scheduleTime);

      if (location != null) {

        CoordinatePoint p = applyNoiseToLocation(location.getLocation(), noise);

        Record r = new Record();
        r.setLocation(location.getLocation());
        r.setTimestamp(time - i * 1000);
        r.setLocation(p);
        r.setAccuracy(noise);
        records.add(r);
      }
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.