use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method getStopTimeInstancesByBlockInstance.
private Map<BlockInstance, List<StopTimeInstance>> getStopTimeInstancesByBlockInstance(List<StopTimeInstance> stopTimes) {
Map<BlockInstance, List<StopTimeInstance>> r = new FactoryMap<BlockInstance, List<StopTimeInstance>>(new ArrayList<StopTimeInstance>());
for (StopTimeInstance stopTime : stopTimes) {
BlockStopTimeEntry blockStopTime = stopTime.getStopTime();
BlockTripEntry blockTrip = blockStopTime.getTrip();
BlockConfigurationEntry blockConfiguration = blockTrip.getBlockConfiguration();
long serviceDate = stopTime.getServiceDate();
BlockInstance blockInstance = new BlockInstance(blockConfiguration, serviceDate, stopTime.getFrequency());
r.get(blockInstance).add(stopTime);
}
return r;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class RouteServiceImpl method getRouteCollectionIdsForStop.
@Override
@Cacheable
public Set<AgencyAndId> getRouteCollectionIdsForStop(AgencyAndId stopId) {
StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopId);
if (stopEntry == null)
throw new InternalErrorServiceException("no such stop: id=" + stopId);
Set<AgencyAndId> routeCollectionIds = new HashSet<AgencyAndId>();
List<BlockStopTimeIndex> indices = _blockIndexService.getStopTimeIndicesForStop(stopEntry);
for (BlockStopTimeIndex blockStopTimeIndex : indices) {
for (BlockTripEntry blockTrip : blockStopTimeIndex.getTrips()) {
TripEntry trip = blockTrip.getTrip();
routeCollectionIds.add(trip.getRouteCollection().getId());
}
}
List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry);
for (FrequencyBlockStopTimeIndex blockStopTimeIndex : frequencyIndices) {
for (BlockTripEntry blockTrip : blockStopTimeIndex.getTrips()) {
TripEntry trip = blockTrip.getTrip();
routeCollectionIds.add(trip.getRouteCollection().getId());
}
}
return routeCollectionIds;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class BlockConfigurationEntriesFactoryTest method test.
@Test
public void test() {
StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
StopEntryImpl stopB = stop("stopB", 47.1, -122.1);
TripEntryImpl tripA = trip("tripA", "sA", 300.0);
StopTimeEntryImpl st0 = stopTime(0, stopA, tripA, time(9, 00), time(9, 05), 100.0);
StopTimeEntryImpl st1 = stopTime(1, stopB, tripA, time(9, 30), time(9, 35), 200.0);
TripEntryImpl tripB = trip("tripB", "sA", 300.0);
StopTimeEntryImpl st2 = stopTime(2, stopA, tripB, time(10, 00), time(10, 05), 100.0);
StopTimeEntryImpl st3 = stopTime(3, stopB, tripB, time(10, 30), time(10, 35), 200.0);
TripEntryImpl tripC = trip("tripC", "sB", 300.0);
StopTimeEntryImpl st4 = stopTime(4, stopA, tripC, time(11, 00), time(11, 05), 100.0);
StopTimeEntryImpl st5 = stopTime(5, stopB, tripC, time(11, 30), time(11, 35), 200.0);
TripEntryImpl tripD = trip("tripD", "sB", 300.0);
StopTimeEntryImpl st6 = stopTime(6, stopA, tripD, time(12, 00), time(12, 05), 100.0);
StopTimeEntryImpl st7 = stopTime(7, stopB, tripD, time(12, 30), time(12, 35), 200.0);
/**
**
* Actual Test
***
*/
BlockEntryImpl block = new BlockEntryImpl();
List<TripEntryImpl> tripsInBlock = Arrays.asList(tripA, tripB, tripC, tripD);
_factory.processBlockConfigurations(block, tripsInBlock);
List<BlockConfigurationEntry> configurations = block.getConfigurations();
assertEquals(3, configurations.size());
/**
**
* Order of the configurations matter. See
* {@link BlockEntry#getConfigurations()} for details.
***
*/
/**
**
* Configuration A & B
***
*/
BlockConfigurationEntry entry = configurations.get(0);
assertSame(block, entry.getBlock());
assertEquals(serviceIds(lsids("sA", "sB"), lsids()), entry.getServiceIds());
assertEquals(1200.0, entry.getTotalBlockDistance(), 0.0);
assertNull(entry.getFrequencies());
List<BlockTripEntry> trips = entry.getTrips();
assertEquals(4, trips.size());
BlockTripEntry trip = trips.get(0);
assertEquals(0, trip.getAccumulatedStopTimeIndex());
assertEquals(0, trip.getAccumulatedSlackTime());
assertEquals(0.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripA, trip.getTrip());
assertNull(trip.getPreviousTrip());
assertSame(trips.get(1), trip.getNextTrip());
trip = trips.get(1);
assertEquals(2, trip.getAccumulatedStopTimeIndex());
assertEquals(10 * 60, trip.getAccumulatedSlackTime());
assertEquals(300.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripB, trip.getTrip());
assertSame(trips.get(0), trip.getPreviousTrip());
assertSame(trips.get(2), trip.getNextTrip());
trip = trips.get(2);
assertEquals(4, trip.getAccumulatedStopTimeIndex());
assertEquals(20 * 60, trip.getAccumulatedSlackTime());
assertEquals(600.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripC, trip.getTrip());
assertSame(trips.get(1), trip.getPreviousTrip());
assertSame(trips.get(3), trip.getNextTrip());
trip = trips.get(3);
assertEquals(6, trip.getAccumulatedStopTimeIndex());
assertEquals(30 * 60, trip.getAccumulatedSlackTime());
assertEquals(900.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripD, trip.getTrip());
assertSame(trips.get(2), trip.getPreviousTrip());
assertNull(trip.getNextTrip());
List<BlockStopTimeEntry> stopTimes = entry.getStopTimes();
assertEquals(8, stopTimes.size());
BlockStopTimeEntry bst = stopTimes.get(0);
assertEquals(0, bst.getAccumulatedSlackTime());
assertEquals(0, bst.getBlockSequence());
assertEquals(100.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st0, bst.getStopTime());
assertSame(trips.get(0), bst.getTrip());
bst = stopTimes.get(1);
assertEquals(5 * 60, bst.getAccumulatedSlackTime());
assertEquals(1, bst.getBlockSequence());
assertEquals(200.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st1, bst.getStopTime());
assertSame(trips.get(0), bst.getTrip());
bst = stopTimes.get(2);
assertEquals(10 * 60, bst.getAccumulatedSlackTime());
assertEquals(2, bst.getBlockSequence());
assertEquals(400.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st2, bst.getStopTime());
assertSame(trips.get(1), bst.getTrip());
bst = stopTimes.get(3);
assertEquals(15 * 60, bst.getAccumulatedSlackTime());
assertEquals(3, bst.getBlockSequence());
assertEquals(500.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st3, bst.getStopTime());
assertSame(trips.get(1), bst.getTrip());
bst = stopTimes.get(4);
assertEquals(20 * 60, bst.getAccumulatedSlackTime());
assertEquals(4, bst.getBlockSequence());
assertEquals(700.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st4, bst.getStopTime());
assertSame(trips.get(2), bst.getTrip());
bst = stopTimes.get(5);
assertEquals(25 * 60, bst.getAccumulatedSlackTime());
assertEquals(5, bst.getBlockSequence());
assertEquals(800.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st5, bst.getStopTime());
assertSame(trips.get(2), bst.getTrip());
bst = stopTimes.get(6);
assertEquals(30 * 60, bst.getAccumulatedSlackTime());
assertEquals(6, bst.getBlockSequence());
assertEquals(1000.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st6, bst.getStopTime());
assertSame(trips.get(3), bst.getTrip());
bst = stopTimes.get(7);
assertEquals(35 * 60, bst.getAccumulatedSlackTime());
assertEquals(7, bst.getBlockSequence());
assertEquals(1100.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st7, bst.getStopTime());
assertSame(trips.get(3), bst.getTrip());
/**
**
* Configuration A
***
*/
entry = configurations.get(1);
assertSame(block, entry.getBlock());
assertEquals(serviceIds(lsids("sA"), lsids("sB")), entry.getServiceIds());
assertEquals(600.0, entry.getTotalBlockDistance(), 0.0);
assertNull(entry.getFrequencies());
trips = entry.getTrips();
assertEquals(2, trips.size());
trip = trips.get(0);
assertEquals(0, trip.getAccumulatedStopTimeIndex());
assertEquals(0, trip.getAccumulatedSlackTime());
assertEquals(0.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripA, trip.getTrip());
assertNull(trip.getPreviousTrip());
assertSame(trips.get(1), trip.getNextTrip());
trip = trips.get(1);
assertEquals(2, trip.getAccumulatedStopTimeIndex());
assertEquals(10 * 60, trip.getAccumulatedSlackTime());
assertEquals(300.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripB, trip.getTrip());
assertSame(trips.get(0), trip.getPreviousTrip());
assertNull(trip.getNextTrip());
stopTimes = entry.getStopTimes();
assertEquals(4, stopTimes.size());
bst = stopTimes.get(0);
assertEquals(0, bst.getAccumulatedSlackTime());
assertEquals(0, bst.getBlockSequence());
assertEquals(100.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st0, bst.getStopTime());
assertSame(trips.get(0), bst.getTrip());
bst = stopTimes.get(1);
assertEquals(5 * 60, bst.getAccumulatedSlackTime());
assertEquals(1, bst.getBlockSequence());
assertEquals(200.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st1, bst.getStopTime());
assertSame(trips.get(0), bst.getTrip());
bst = stopTimes.get(2);
assertEquals(10 * 60, bst.getAccumulatedSlackTime());
assertEquals(2, bst.getBlockSequence());
assertEquals(400.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st2, bst.getStopTime());
assertSame(trips.get(1), bst.getTrip());
bst = stopTimes.get(3);
assertEquals(15 * 60, bst.getAccumulatedSlackTime());
assertEquals(3, bst.getBlockSequence());
assertEquals(500.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st3, bst.getStopTime());
assertSame(trips.get(1), bst.getTrip());
/**
**
* Configuration B
***
*/
entry = configurations.get(2);
assertSame(block, entry.getBlock());
assertEquals(serviceIds(lsids("sB"), lsids("sA")), entry.getServiceIds());
assertEquals(600.0, entry.getTotalBlockDistance(), 0.0);
assertNull(entry.getFrequencies());
trips = entry.getTrips();
assertEquals(2, trips.size());
trip = trips.get(0);
assertEquals(0, trip.getAccumulatedStopTimeIndex());
assertEquals(0, trip.getAccumulatedSlackTime());
assertEquals(0.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripC, trip.getTrip());
assertNull(trip.getPreviousTrip());
assertSame(trips.get(1), trip.getNextTrip());
trip = trips.get(1);
assertEquals(2, trip.getAccumulatedStopTimeIndex());
assertEquals(10 * 60, trip.getAccumulatedSlackTime());
assertEquals(300.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripD, trip.getTrip());
assertSame(trips.get(0), trip.getPreviousTrip());
assertNull(trip.getNextTrip());
stopTimes = entry.getStopTimes();
assertEquals(4, stopTimes.size());
bst = stopTimes.get(0);
assertEquals(0, bst.getAccumulatedSlackTime());
assertEquals(0, bst.getBlockSequence());
assertEquals(100.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st4, bst.getStopTime());
assertSame(trips.get(0), bst.getTrip());
bst = stopTimes.get(1);
assertEquals(5 * 60, bst.getAccumulatedSlackTime());
assertEquals(1, bst.getBlockSequence());
assertEquals(200.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st5, bst.getStopTime());
assertSame(trips.get(0), bst.getTrip());
bst = stopTimes.get(2);
assertEquals(10 * 60, bst.getAccumulatedSlackTime());
assertEquals(2, bst.getBlockSequence());
assertEquals(400.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st6, bst.getStopTime());
assertSame(trips.get(1), bst.getTrip());
bst = stopTimes.get(3);
assertEquals(15 * 60, bst.getAccumulatedSlackTime());
assertEquals(3, bst.getBlockSequence());
assertEquals(500.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st7, bst.getStopTime());
assertSame(trips.get(1), bst.getTrip());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class ScheduledServiceServiceImpl method routeHasUpcomingScheduledService.
@Override
public Boolean routeHasUpcomingScheduledService(String agencyId, long time, String routeId, String directionId) {
long serviceStart = time - SCHEDULE_WINDOW_BEFORE;
long serviceEnd = time + SCHEDULE_WINDOW_AFTER;
AgencyAndId routeAndId;
if (routeId != null && routeId.contains("_"))
routeAndId = AgencyAndIdLibrary.convertFromString(routeId);
else
routeAndId = new AgencyAndId(agencyId, routeId);
List<BlockInstance> instances = _blockCalendarService.getActiveBlocksForRouteInTimeRange(routeAndId, serviceStart, serviceEnd);
if (instances.isEmpty()) {
return false;
}
for (BlockInstance instance : instances) {
List<BlockTripEntry> tripsInBlock = instance.getBlock().getTrips();
if (tripsInBlock.isEmpty()) {
continue;
}
for (BlockTripEntry blockTripEntry : tripsInBlock) {
TripEntry tripEntry = blockTripEntry.getTrip();
if (tripEntry.getRoute().getId().toString().equals(routeId)) {
if (tripEntry.getDirectionId() == null || tripEntry.getDirectionId().equals(directionId)) {
return true;
}
}
}
}
return false;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class ScheduledServiceServiceImpl method stopHasUpcomingScheduledService.
@Override
public Boolean stopHasUpcomingScheduledService(String stopAgencyId, long time, String stopId, String routeId, String directionId) {
AgencyAndId stopAndId = null;
if (stopId != null && stopId.contains("_"))
stopAndId = AgencyAndIdLibrary.convertFromString(stopId);
else if (stopId != null)
stopAndId = new AgencyAndId(stopAgencyId, stopId);
StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopAndId);
if (stopEntry == null) {
return null;
}
Date serviceStart = new Date(time - SCHEDULE_WINDOW_BEFORE);
Date serviceEnd = new Date(time + SCHEDULE_WINDOW_AFTER);
List<StopTimeInstance> stis = _stopTimeService.getStopTimeInstancesInTimeRange(stopEntry, serviceStart, serviceEnd, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED);
if (stis.isEmpty()) {
return false;
}
for (StopTimeInstance stopTime : stis) {
BlockTripEntry blockTripEntry = stopTime.getTrip();
TripEntry tripEntry = blockTripEntry.getTrip();
if (tripEntry.getRoute().getId().toString().equals(routeId)) {
if (tripEntry.getDirectionId() == null || tripEntry.getDirectionId().equals(directionId)) {
return true;
}
}
}
return false;
}
Aggregations