Search in sources :

Example 1 with StopTimeEntryImpl

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

the class StopTimeServiceImplTest method test02.

@Test
public void test02() {
    Date dayA = getTimeAsDay(date("2009-09-01 00:00"));
    Date dayB = getTimeAsDay(date("2009-09-02 00:00"));
    // 10:00am, 10:30am
    StopTimeEntryImpl stA = stopTime(0, _stop, trip("A", "sA"), time(10, 00), time(10, 30), 0);
    // 01:00am, 01:30am (both on next day)
    StopTimeEntryImpl stB = stopTime(1, _stop, trip("B", "sA"), time(25, 00), time(25, 30), 0);
    BlockConfigurationEntry bA = linkBlockTrips("bA", stA.getTrip());
    BlockConfigurationEntry bB = linkBlockTrips("bB", stB.getTrip());
    addFirstStopToBlockIndex(bA, bB);
    /**
     **
     *
     ***
     */
    Date from = date("2009-09-01 10:10");
    Date to = date("2009-09-01 10:40");
    List<StopTimeInstance> results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(1, results.size());
    StopTimeInstance sti = results.get(0);
    assertEquals(dayA.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-01 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-01 10:30").getTime(), sti.getDepartureTime());
    /**
     **
     *
     ***
     */
    from = date("2009-09-02 10:10");
    to = date("2009-09-02 10:40");
    results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(1, results.size());
    sti = results.get(0);
    assertEquals(dayB.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime());
    /**
     **
     *
     ***
     */
    from = date("2009-09-01 10:10");
    to = date("2009-09-02 10:40");
    results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(3, results.size());
    sti = results.get(0);
    assertEquals(dayA.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-01 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-01 10:30").getTime(), sti.getDepartureTime());
    sti = results.get(1);
    assertEquals(dayA.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-02 01:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-02 01:30").getTime(), sti.getDepartureTime());
    sti = results.get(2);
    assertEquals(dayB.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime());
    /**
     **
     *
     ***
     */
    from = date("2009-09-01 12:00");
    to = date("2009-09-02 12:00");
    results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(2, results.size());
    sti = results.get(0);
    assertEquals(dayA.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-02 01:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-02 01:30").getTime(), sti.getDepartureTime());
    sti = results.get(1);
    assertEquals(dayB.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime());
    /**
     **
     *
     ***
     */
    from = date("2009-09-02 12:00");
    to = date("2009-09-03 12:00");
    results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(1, results.size());
    sti = results.get(0);
    assertEquals(dayB.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-03 01:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-03 01:30").getTime(), sti.getDepartureTime());
}
Also used : StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Date(java.util.Date) Test(org.junit.Test)

Example 2 with StopTimeEntryImpl

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

the class StopTimeServiceImplTest method test03.

@Test
public void test03() {
    Date dayA = getTimeAsDay(date("2009-09-02 00:00"));
    Date dayB = getTimeAsDay(date("2009-09-03 00:00"));
    StopTimeEntryImpl stA = stopTime(0, _stop, trip("A", "sA"), time(10, 00), time(10, 30), 0);
    StopTimeEntryImpl stB = stopTime(1, _stop, trip("B", "sA"), time(25, 0), time(25, 30), 0);
    StopTimeEntryImpl stC = stopTime(2, _stop, trip("C", "sB"), time(10, 00), time(10, 30), 0);
    StopTimeEntryImpl stD = stopTime(3, _stop, trip("D", "sB"), time(25, 0), time(25, 30), 0);
    BlockConfigurationEntry bA = linkBlockTrips("bA", stA.getTrip());
    BlockConfigurationEntry bB = linkBlockTrips("bB", stB.getTrip());
    BlockConfigurationEntry bC = linkBlockTrips("bC", stC.getTrip());
    BlockConfigurationEntry bD = linkBlockTrips("bD", stD.getTrip());
    addFirstStopToBlockIndex(bA, bB);
    addFirstStopToBlockIndex(bC, bD);
    /**
     **
     *
     ***
     */
    Date from = date("2009-09-02 10:10");
    Date to = date("2009-09-02 10:40");
    List<StopTimeInstance> results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(1, results.size());
    StopTimeInstance sti = results.get(0);
    assertEquals(dayA.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime());
    /**
     **
     *
     ***
     */
    from = date("2009-09-03 10:10");
    to = date("2009-09-03 10:40");
    results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(1, results.size());
    sti = results.get(0);
    assertEquals(dayB.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-03 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-03 10:30").getTime(), sti.getDepartureTime());
    /**
     **
     *
     ***
     */
    from = date("2009-09-02 10:10");
    to = date("2009-09-03 10:40");
    results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(3, results.size());
    sti = results.get(0);
    assertEquals(dayA.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime());
    sti = results.get(1);
    assertEquals(dayA.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-03 01:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-03 01:30").getTime(), sti.getDepartureTime());
    sti = results.get(2);
    assertEquals(dayB.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-03 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-03 10:30").getTime(), sti.getDepartureTime());
    /**
     **
     *
     ***
     */
    from = date("2009-09-02 12:00");
    to = date("2009-09-03 12:00");
    results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(2, results.size());
    sti = results.get(0);
    assertEquals(dayA.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-03 01:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-03 01:30").getTime(), sti.getDepartureTime());
    sti = results.get(1);
    assertEquals(dayB.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-03 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-03 10:30").getTime(), sti.getDepartureTime());
    /**
     **
     *
     ***
     */
    from = date("2009-09-03 12:00");
    to = date("2009-09-04 12:00");
    results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(1, results.size());
    sti = results.get(0);
    assertEquals(dayB.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-04 01:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-04 01:30").getTime(), sti.getDepartureTime());
}
Also used : StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Date(java.util.Date) Test(org.junit.Test)

Example 3 with StopTimeEntryImpl

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

the class DistanceAlongShapeLibrary method constructError.

private void constructError(ShapePoints shapePoints, List<StopTimeEntryImpl> stopTimes, List<List<PointAndIndex>> possibleAssignments, UTMProjection projection) throws InvalidStopToShapeMappingException {
    StopTimeEntryImpl first = stopTimes.get(0);
    StopTimeEntryImpl last = stopTimes.get(stopTimes.size() - 1);
    _log.error("We were attempting to compute the distance along a particular trip for each stop time of that trip by " + "snapping them to the shape for that trip.  However, we could not find an assignment for each stop time " + "where the distance traveled along the shape for each stop time was strictly increasing (aka a stop time " + "seemed to travel backwards).  For more information on errors of this kind, see:\n" + "  https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
    TripEntryImpl trip = first.getTrip();
    _log.error("error constructing stop-time distances along shape for trip=" + trip.getId() + " shape=" + trip.getShapeId() + " firstStopTime=" + first.getId() + " lastStopTime=" + last.getId());
    StringBuilder b = new StringBuilder();
    int index = 0;
    b.append("# potential assignments:\n");
    b.append("# stopLat stopLon stopId\n");
    b.append("#   locationOnShapeLat locationOnShapeLon distanceAlongShape distanceFromShape shapePointIndex\n");
    b.append("#   ...\n");
    double prevMaxDistanceAlongShape = Double.NEGATIVE_INFINITY;
    for (List<PointAndIndex> possible : possibleAssignments) {
        StopTimeEntryImpl stopTime = stopTimes.get(index);
        StopEntryImpl stop = stopTime.getStop();
        b.append(stop.getStopLat());
        b.append(' ');
        b.append(stop.getStopLon());
        b.append(' ');
        b.append(index);
        b.append(' ');
        b.append(stop.getId());
        b.append('\n');
        double maxDistanceAlongShape = Double.NEGATIVE_INFINITY;
        double minDistanceAlongShape = Double.POSITIVE_INFINITY;
        for (PointAndIndex pindex : possible) {
            b.append("  ");
            b.append(projection.reverse(pindex.point));
            b.append(' ');
            b.append(_errorFormatter.format(pindex.distanceAlongShape));
            b.append(' ');
            b.append(_errorFormatter.format(pindex.distanceFromTarget));
            b.append(' ');
            b.append(pindex.index);
            b.append("\n");
            maxDistanceAlongShape = Math.max(maxDistanceAlongShape, pindex.distanceAlongShape);
            minDistanceAlongShape = Math.min(minDistanceAlongShape, pindex.distanceAlongShape);
        }
        if (minDistanceAlongShape < prevMaxDistanceAlongShape) {
            b.append("    ^ potential problem here ^\n");
        }
        prevMaxDistanceAlongShape = maxDistanceAlongShape;
        index++;
    }
    _log.error(b.toString());
    if (_shapeIdsWeHavePrinted.add(trip.getShapeId())) {
        b = new StringBuilder();
        index = 0;
        for (int i = 0; i < shapePoints.getSize(); i++) {
            b.append(shapePoints.getLatForIndex(i));
            b.append(' ');
            b.append(shapePoints.getLonForIndex(i));
            b.append(' ');
            b.append(shapePoints.getDistTraveledForIndex(i));
            b.append('\n');
        }
        _log.error("shape points:\n" + b.toString());
    }
    throw new InvalidStopToShapeMappingException(first.getTrip());
}
Also used : StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) PointAndIndex(org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) XYPoint(org.onebusaway.geospatial.model.XYPoint) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)

Example 4 with StopTimeEntryImpl

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

the class StopTimeEntriesFactory method ensureStopTimesHaveTimesSet.

private void ensureStopTimesHaveTimesSet(List<StopTime> stopTimes, List<StopTimeEntryImpl> stopTimeEntries) {
    double[] distanceTraveled = getDistanceTraveledForStopTimes(stopTimeEntries);
    int[] arrivalTimes = new int[stopTimes.size()];
    int[] departureTimes = new int[stopTimes.size()];
    interpolateArrivalAndDepartureTimes(stopTimes, distanceTraveled, arrivalTimes, departureTimes);
    int sequence = 0;
    int accumulatedSlackTime = 0;
    StopTimeEntryImpl prevStopTimeEntry = null;
    for (StopTimeEntryImpl stopTimeEntry : stopTimeEntries) {
        int arrivalTime = arrivalTimes[sequence];
        int departureTime = departureTimes[sequence];
        stopTimeEntry.setArrivalTime(arrivalTime);
        stopTimeEntry.setDepartureTime(departureTime);
        stopTimeEntry.setAccumulatedSlackTime(accumulatedSlackTime);
        accumulatedSlackTime += stopTimeEntry.getDepartureTime() - stopTimeEntry.getArrivalTime();
        if (prevStopTimeEntry != null) {
            int duration = stopTimeEntry.getArrivalTime() - prevStopTimeEntry.getDepartureTime();
            if (duration < 0) {
                _log.error("Invalid duration of " + duration + " for stopTime " + stopTimeEntry.getId() + " of " + stopTimeEntry.getArrivalTime() + " compared to previous stopTime departure " + prevStopTimeEntry.getId() + " of " + prevStopTimeEntry.getDepartureTime());
                throw new IllegalStateException();
            }
        }
        prevStopTimeEntry = stopTimeEntry;
        sequence++;
    }
}
Also used : StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 5 with StopTimeEntryImpl

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

the class GenerateNarrativesTaskTest method testGenerateStopNarrativesWithConflictingDirections.

@Test
public void testGenerateStopNarrativesWithConflictingDirections() {
    StopEntryImpl stopEntry = stop("stopA", 47.663146, -122.300928);
    Mockito.when(_transitGraphDao.getAllStops()).thenReturn(Arrays.asList((StopEntry) stopEntry));
    Stop stop = new Stop();
    stop.setId(stopEntry.getId());
    Mockito.when(_gtfsDao.getAllStops()).thenReturn(Arrays.asList(stop));
    /**
     * Two shapes heading in opposite directions
     */
    AgencyAndId shapeIdA = aid("shapeA");
    ShapePointsFactory factoryA = new ShapePointsFactory();
    factoryA.addPoint(47.661225, -122.3009201);
    factoryA.addPoint(47.664375, -122.3008986);
    ShapePoints shapePointsA = factoryA.create();
    _provider.setShapePointsForId(shapeIdA, shapePointsA);
    AgencyAndId shapeIdB = aid("shapeB");
    ShapePointsFactory factoryB = new ShapePointsFactory();
    factoryB.addPoint(47.664375, -122.3008986);
    factoryB.addPoint(47.661225, -122.3009201);
    ShapePoints shapePointsB = factoryB.create();
    _provider.setShapePointsForId(shapeIdB, shapePointsB);
    TripEntryImpl tripA = trip("tripA");
    tripA.setShapeId(shapeIdA);
    TripEntryImpl tripB = trip("tripB");
    tripB.setShapeId(shapeIdB);
    StopTimeEntryImpl stopTimeA = stopTime(0, stopEntry, tripA, 0, 0.0);
    stopTimeA.setShapePointIndex(0);
    StopTimeEntryImpl stopTimeB = stopTime(0, stopEntry, tripB, 0, 0.0);
    stopTimeB.setShapePointIndex(0);
    BlockStopTimeEntry blockStopTimeA = Mockito.mock(BlockStopTimeEntry.class);
    Mockito.when(blockStopTimeA.getStopTime()).thenReturn(stopTimeA);
    BlockStopTimeEntry blockStopTimeB = Mockito.mock(BlockStopTimeEntry.class);
    Mockito.when(blockStopTimeB.getStopTime()).thenReturn(stopTimeB);
    BlockStopTimeIndex index = Mockito.mock(BlockStopTimeIndex.class);
    Mockito.when(index.getStopTimes()).thenReturn(Arrays.asList(blockStopTimeA, blockStopTimeB));
    List<BlockStopTimeIndex> indices = Arrays.asList(index);
    Mockito.when(_blockIndexService.getStopTimeIndicesForStop(stopEntry)).thenReturn(indices);
    _task.generateStopNarratives(_provider);
    StopNarrative narrative = _provider.getNarrativeForStopId(stopEntry.getId());
    assertNull(narrative.getDirection());
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Aggregations

StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)32 Test (org.junit.Test)15 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)14 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)12 PointAndIndex (org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex)10 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)10 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)9 StopTime (org.onebusaway.gtfs.model.StopTime)7 ArrayList (java.util.ArrayList)6 XYPoint (org.onebusaway.geospatial.model.XYPoint)6 Stop (org.onebusaway.gtfs.model.Stop)6 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)6 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)5 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)5 Agency (org.onebusaway.gtfs.model.Agency)4 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 Trip (org.onebusaway.gtfs.model.Trip)4 DistanceAlongShapeLibrary (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary)4 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)4 Date (java.util.Date)3