Search in sources :

Example 46 with BlockStopTimeEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.

the class GenerateNarrativesTask method getAllOrientationsForStop.

private Collection<PointAndOrientation> getAllOrientationsForStop(NarrativeProviderImpl provider, StopEntry stop) {
    List<BlockStopTimeIndex> stopTimeIndices = _blockIndexService.getStopTimeIndicesForStop(stop);
    List<PointAndOrientation> pos = new ArrayList<PointAndOrientation>();
    Map<ShapeIdAndDistance, PointAndOrientation> orientationsByKey = new HashMap<ShapeIdAndDistance, PointAndOrientation>();
    for (BlockStopTimeIndex stopTimeIndex : stopTimeIndices) {
        for (BlockStopTimeEntry blockStopTime : stopTimeIndex.getStopTimes()) {
            StopTimeEntry stopTime = blockStopTime.getStopTime();
            TripEntry trip = stopTime.getTrip();
            AgencyAndId shapeId = trip.getShapeId();
            if (shapeId == null)
                continue;
            ShapePoints shapePoints = provider.getShapePointsForId(shapeId);
            if (shapePoints == null)
                continue;
            int shapePointIndex = stopTime.getShapePointIndex();
            if (shapePointIndex == -1)
                continue;
            ShapeIdAndDistance key = new ShapeIdAndDistance(shapeId, stopTime.getShapeDistTraveled());
            PointAndOrientation orientation = orientationsByKey.get(key);
            if (orientation == null) {
                int indexFrom = Math.max(0, shapePointIndex - 5);
                int indexTo = Math.min(shapePoints.getSize(), shapePointIndex + 5);
                ShapePointIndex shapePointIndexMethod = new DistanceTraveledShapePointIndex(stopTime.getShapeDistTraveled(), indexFrom, indexTo);
                orientation = shapePointIndexMethod.getPointAndOrientation(shapePoints);
                if (orientation == null)
                    continue;
                orientationsByKey.put(key, orientation);
            }
            pos.add(orientation);
        }
    }
    return orientationsByKey.values();
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) DistanceTraveledShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) PointAndOrientation(org.onebusaway.transit_data_federation.impl.shapes.PointAndOrientation) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) ShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.ShapePointIndex) DistanceTraveledShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 47 with BlockStopTimeEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.

the class BlockStopSequenceIndex method computeServiceInterval.

/**
 **
 * Private Methods
 ***
 */
private ServiceInterval computeServiceInterval(BlockSequenceIndex index, int stopIndex) {
    List<BlockSequence> sequences = _index.getSequences();
    BlockStopTimeEntry fromBst = sequences.get(0).getStopTimes().get(stopIndex);
    BlockStopTimeEntry toBst = sequences.get(sequences.size() - 1).getStopTimes().get(stopIndex);
    StopTimeEntry fromSt = fromBst.getStopTime();
    StopTimeEntry toSt = toBst.getStopTime();
    return new ServiceInterval(fromSt.getArrivalTime(), fromSt.getDepartureTime(), toSt.getArrivalTime(), toSt.getDepartureTime());
}
Also used : BlockSequence(org.onebusaway.transit_data_federation.impl.blocks.BlockSequence) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) ServiceInterval(org.onebusaway.gtfs.model.calendar.ServiceInterval) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 48 with BlockStopTimeEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.

the class BlockStopSequenceIndex method toString.

@Override
public String toString() {
    List<BlockSequence> sequences = _index.getSequences();
    BlockSequence sequence = sequences.get(0);
    List<BlockStopTimeEntry> stopTimes = sequence.getStopTimes();
    BlockStopTimeEntry bst = stopTimes.get(_offset);
    return bst.toString();
}
Also used : BlockSequence(org.onebusaway.transit_data_federation.impl.blocks.BlockSequence) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 49 with BlockStopTimeEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.

the class StopTimeServiceImpl method getFrequenciesForStopAndServiceIdsAndTimeRange.

private List<Integer> getFrequenciesForStopAndServiceIdsAndTimeRange(FrequencyStopTripIndex index, Date serviceDate, Date from, Date to, List<StopTimeInstance> stopTimeInstances, EFrequencyStopTimeBehavior frequencyBehavior) {
    int relativeFrom = effectiveTime(serviceDate, from);
    int relativeTo = effectiveTime(serviceDate, to);
    int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.FREQUENCY_END_TIME_INSTANCE);
    int toIndex = GenericBinarySearch.search(index, index.size(), relativeTo, IndexAdapters.FREQUENCY_START_TIME_INSTANCE);
    List<FrequencyBlockStopTimeEntry> frequencyStopTimes = index.getFrequencyStopTimes();
    List<Integer> offsetsIntoIndex = new ArrayList<Integer>();
    for (int in = fromIndex; in < toIndex; in++) {
        FrequencyBlockStopTimeEntry entry = frequencyStopTimes.get(in);
        BlockStopTimeEntry bst = entry.getStopTime();
        FrequencyEntry frequency = entry.getFrequency();
        InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
        switch(frequencyBehavior) {
            case INCLUDE_UNSPECIFIED:
                {
                    stopTimeInstances.add(new StopTimeInstance(bst, state));
                    offsetsIntoIndex.add(in);
                    break;
                }
            case INCLUDE_INTERPOLATED:
                {
                    int stopTimeOffset = entry.getStopTimeOffset();
                    int tFrom = Math.max(relativeFrom, frequency.getStartTime());
                    int tTo = Math.min(relativeTo, frequency.getEndTime());
                    tFrom = snapToFrequencyStopTime(frequency, tFrom, stopTimeOffset, true);
                    tTo = snapToFrequencyStopTime(frequency, tTo, stopTimeOffset, false);
                    for (int t = tFrom; t <= tTo; t += frequency.getHeadwaySecs()) {
                        int frequencyOffset = t - bst.getStopTime().getDepartureTime();
                        stopTimeInstances.add(new StopTimeInstance(bst, state, frequencyOffset));
                        offsetsIntoIndex.add(in);
                    }
                    break;
                }
        }
    }
    return offsetsIntoIndex;
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)

Example 50 with BlockStopTimeEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.

the class BlockConfigurationEntryImplTest method test.

@Test
public void test() {
    ServiceIdActivation serviceIds = serviceIds(lsids("sA"), lsids("sB"));
    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.1, -122.0);
    BlockEntryImpl block = block("blockA");
    TripEntryImpl tripA = trip("tripA", 1000);
    TripEntryImpl tripB = trip("tripB", 2000);
    TripEntryImpl tripC = trip("tripB", 1500);
    List<TripEntry> trips = Arrays.asList((TripEntry) tripA, tripB, tripC);
    StopTimeEntryImpl st1 = stopTime(1, stopA, tripA, time(6, 30), time(6, 35), 200);
    StopTimeEntryImpl st2 = stopTime(2, stopB, tripA, time(7, 00), time(7, 10), 800);
    StopTimeEntryImpl st3 = stopTime(3, stopB, tripB, time(7, 30), time(7, 35), 400);
    StopTimeEntryImpl st4 = stopTime(4, stopA, tripB, time(8, 00), time(8, 07), 1600);
    StopTimeEntryImpl st5 = stopTime(5, stopA, tripC, time(8, 30), time(8, 35), 300);
    StopTimeEntryImpl st6 = stopTime(6, stopB, tripC, time(9, 00), time(9, 02), 1200);
    Builder builder = BlockConfigurationEntryImpl.builder();
    builder.setBlock(block);
    builder.setTrips(trips);
    builder.setServiceIds(serviceIds);
    builder.setTripGapDistances(new double[] { 10.0, 20.0, 0.0 });
    BlockConfigurationEntry entry = builder.create();
    assertSame(block, entry.getBlock());
    assertSame(serviceIds, entry.getServiceIds());
    assertEquals(4530.0, entry.getTotalBlockDistance(), 0.0);
    /**
     **
     * Trips
     ***
     */
    List<BlockTripEntry> blockTrips = entry.getTrips();
    assertEquals(3, blockTrips.size());
    BlockTripEntry blockTrip = blockTrips.get(0);
    assertEquals(0, blockTrip.getSequence());
    assertEquals(0, blockTrip.getAccumulatedStopTimeIndex());
    assertEquals(0, blockTrip.getAccumulatedSlackTime());
    assertEquals(0.0, blockTrip.getDistanceAlongBlock(), 0.0);
    assertSame(blockTrips.get(1), blockTrip.getNextTrip());
    assertNull(blockTrip.getPreviousTrip());
    blockTrip = blockTrips.get(1);
    assertEquals(1, blockTrip.getSequence());
    assertEquals(2, blockTrip.getAccumulatedStopTimeIndex());
    assertEquals(15 * 60, blockTrip.getAccumulatedSlackTime());
    assertEquals(1010.0, blockTrip.getDistanceAlongBlock(), 0.0);
    assertSame(blockTrips.get(2), blockTrip.getNextTrip());
    assertSame(blockTrips.get(0), blockTrip.getPreviousTrip());
    blockTrip = blockTrips.get(2);
    assertEquals(2, blockTrip.getSequence());
    assertEquals(4, blockTrip.getAccumulatedStopTimeIndex());
    assertEquals(35 * 60, blockTrip.getAccumulatedSlackTime());
    assertEquals(3030.0, blockTrip.getDistanceAlongBlock(), 0.0);
    assertNull(blockTrip.getNextTrip());
    assertSame(blockTrips.get(1), blockTrip.getPreviousTrip());
    /**
     **
     * Stop Times
     ***
     */
    List<BlockStopTimeEntry> stopTimes = entry.getStopTimes();
    assertEquals(6, stopTimes.size());
    BlockStopTimeEntry bst = stopTimes.get(0);
    assertEquals(0, bst.getAccumulatedSlackTime());
    assertEquals(0, bst.getBlockSequence());
    assertEquals(200, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st1, bst.getStopTime());
    assertSame(blockTrips.get(0), bst.getTrip());
    bst = stopTimes.get(1);
    assertEquals(300, bst.getAccumulatedSlackTime());
    assertEquals(1, bst.getBlockSequence());
    assertEquals(800, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st2, bst.getStopTime());
    assertSame(blockTrips.get(0), bst.getTrip());
    bst = stopTimes.get(2);
    assertEquals(15 * 60, bst.getAccumulatedSlackTime());
    assertEquals(2, bst.getBlockSequence());
    assertEquals(1410, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st3, bst.getStopTime());
    assertSame(blockTrips.get(1), bst.getTrip());
    bst = stopTimes.get(3);
    assertEquals(20 * 60, bst.getAccumulatedSlackTime());
    assertEquals(3, bst.getBlockSequence());
    assertEquals(2610, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st4, bst.getStopTime());
    assertSame(blockTrips.get(1), bst.getTrip());
    bst = stopTimes.get(4);
    assertEquals(35 * 60, bst.getAccumulatedSlackTime());
    assertEquals(4, bst.getBlockSequence());
    assertEquals(3330, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st5, bst.getStopTime());
    assertSame(blockTrips.get(2), bst.getTrip());
    bst = stopTimes.get(5);
    assertEquals(40 * 60, bst.getAccumulatedSlackTime());
    assertEquals(5, bst.getBlockSequence());
    assertEquals(4230, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st6, bst.getStopTime());
    assertSame(blockTrips.get(2), bst.getTrip());
}
Also used : StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) Builder(org.onebusaway.transit_data_federation.impl.transit_graph.BlockConfigurationEntryImpl.Builder) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) 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)

Aggregations

BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)71 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)32 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)29 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)23 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)16 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)15 ArrayList (java.util.ArrayList)14 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)14 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)11 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)11 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)10 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)9 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)9 Date (java.util.Date)8 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)8 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)8 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)8 BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)7 FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)7