use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class BlockStopTimeIndex method create.
public static BlockStopTimeIndex create(BlockTripIndex blockTripIndex, int blockSequence) {
List<BlockTripEntry> tripsList = blockTripIndex.getTrips();
int n = tripsList.size();
List<BlockConfigurationEntry> blockConfigs = new ArrayList<BlockConfigurationEntry>(n);
for (BlockTripEntry trip : tripsList) blockConfigs.add(trip.getBlockConfiguration());
int[] stopIndices = new int[n];
Arrays.fill(stopIndices, blockSequence);
ServiceInterval serviceInterval = computeServiceInterval(blockTripIndex, blockSequence);
return new BlockStopTimeIndex(blockConfigs, stopIndices, serviceInterval);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class FrequencyBlockTripIndexData method createIndex.
public FrequencyBlockTripIndex createIndex(TransitGraphDao dao) {
ArrayList<BlockTripEntry> trips = new ArrayList<BlockTripEntry>();
for (int i = 0; i < _trips.size(); i++) {
BlockTripReference tripReference = _trips.get(i);
BlockTripEntry blockTrip = ReferencesLibrary.getReferenceAsTrip(tripReference, dao);
trips.add(blockTrip);
}
trips.trimToSize();
return new FrequencyBlockTripIndex(trips, _frequencies, _serviceIntervalBlock);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class StopSequenceCollectionServiceImpl method computeContinuations.
/**
* For each given StopSequence, we wish to compute the set of StopSequences
* that continue the given StopSequence. We say one StopSequence continues
* another if the two stops sequences have the same route and direction id and
* each trip in the first StopSequence is immediately followed by a Trip from
* the second StopSequence, as defined by a block id.
*
* @param sequenceStats
* @param sequencesByGroupId
*/
private void computeContinuations(Map<StopSequence, PatternStats> sequenceStats, Map<String, List<StopSequence>> sequencesByGroupId) {
Map<BlockTripEntry, StopSequence> stopSequencesByTrip = new HashMap<BlockTripEntry, StopSequence>();
Map<StopSequence, String> stopSequenceGroupIds = new HashMap<StopSequence, String>();
for (Map.Entry<String, List<StopSequence>> entry : sequencesByGroupId.entrySet()) {
String id = entry.getKey();
for (StopSequence sequence : entry.getValue()) stopSequenceGroupIds.put(sequence, id);
}
for (StopSequence sequence : sequenceStats.keySet()) {
String groupId = stopSequenceGroupIds.get(sequence);
for (BlockTripEntry trip : sequence.getTrips()) {
BlockTripEntry prevTrip = trip.getPreviousTrip();
if (prevTrip == null)
continue;
StopSequence prevSequence = stopSequencesByTrip.get(prevTrip);
// No continuations if incoming is not part of the sequence collection
if (prevSequence == null)
continue;
// No continuation if it's the same stop sequence
if (prevSequence.equals(sequence))
continue;
// No contination if the the block group ids don't match
String prevGroupId = stopSequenceGroupIds.get(prevSequence);
if (!groupId.equals(prevGroupId))
continue;
StopEntry prevStop = prevSequence.getStops().get(prevSequence.getStops().size() - 1);
StopEntry nextStop = sequence.getStops().get(0);
double d = SphericalGeometryLibrary.distance(prevStop.getStopLat(), prevStop.getStopLon(), nextStop.getStopLat(), nextStop.getStopLon());
if (d < 5280 / 4) {
/*
* System.out.println("distance=" + d + " from=" + prevStop.getId() +
* " to=" + nextStop.getId() + " ssFrom=" + prevSequence.getId() +
* " ssTo=" + stopSequence.getId());
*/
PatternStats stats = sequenceStats.get(prevSequence);
stats.continuations.add(sequence);
}
}
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class StopSequencesServiceImpl method getStopSequencesForTrips.
@Override
public List<StopSequence> getStopSequencesForTrips(List<BlockTripEntry> trips) {
Map<StopSequenceKey, List<BlockTripEntry>> tripsByStopSequenceKey = new FactoryMap<StopSequenceKey, List<BlockTripEntry>>(new ArrayList<BlockTripEntry>());
for (BlockTripEntry blockTrip : trips) {
TripEntry trip = blockTrip.getTrip();
String directionId = trip.getDirectionId();
if (directionId == null)
directionId = NO_DIRECTION_ID;
AgencyAndId shapeId = trip.getShapeId();
if (shapeId == null || !shapeId.hasValues())
shapeId = NO_SHAPE_ID;
List<StopEntry> stops = getStopTimesAsStops(trip.getStopTimes());
StopSequenceKey key = new StopSequenceKey(stops, directionId, shapeId);
tripsByStopSequenceKey.get(key).add(blockTrip);
}
List<StopSequence> sequences = new ArrayList<StopSequence>();
for (Map.Entry<StopSequenceKey, List<BlockTripEntry>> entry : tripsByStopSequenceKey.entrySet()) {
StopSequenceKey key = entry.getKey();
StopSequence ss = new StopSequence();
ss.setId(sequences.size());
ss.setRoute(null);
ss.setStops(key.getStops());
if (!key.getDirectionId().equals(NO_DIRECTION_ID))
ss.setDirectionId(key.getDirectionId());
if (!key.getShapeId().equals(NO_SHAPE_ID))
ss.setShapeId(key.getShapeId());
ss.setTrips(entry.getValue());
ss.setTripCount(entry.getValue().size());
sequences.add(ss);
}
return sequences;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry 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());
}
Aggregations