use of org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex in project onebusaway-application-modules by camsys.
the class GenerateNarrativesTaskTest method testGenerateStopNarrativesWithCalculatedDirection.
@Test
public void testGenerateStopNarrativesWithCalculatedDirection() {
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));
AgencyAndId shapeId = aid("shapeA");
ShapePointsFactory factory = new ShapePointsFactory();
factory.addPoint(47.661225, -122.3009201);
factory.addPoint(47.664375, -122.3008986);
ShapePoints shapePoints = factory.create();
_provider.setShapePointsForId(shapeId, shapePoints);
TripEntryImpl trip = trip("trip");
trip.setShapeId(shapeId);
StopTimeEntryImpl stopTime = stopTime(0, stopEntry, trip, 0, 0.0);
stopTime.setShapePointIndex(0);
BlockStopTimeEntry blockStopTime = Mockito.mock(BlockStopTimeEntry.class);
Mockito.when(blockStopTime.getStopTime()).thenReturn(stopTime);
BlockStopTimeIndex index = Mockito.mock(BlockStopTimeIndex.class);
Mockito.when(index.getStopTimes()).thenReturn(Arrays.asList(blockStopTime));
List<BlockStopTimeIndex> indices = Arrays.asList(index);
Mockito.when(_blockIndexService.getStopTimeIndicesForStop(stopEntry)).thenReturn(indices);
_task.generateStopNarratives(_provider);
StopNarrative narrative = _provider.getNarrativeForStopId(stopEntry.getId());
assertEquals("N", narrative.getDirection());
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex in project onebusaway-application-modules by camsys.
the class ScheduledServiceServiceImpl method stopHasRevenueServiceOnRoute.
@Override
public Boolean stopHasRevenueServiceOnRoute(String agencyId, 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(agencyId, stopId);
StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopAndId);
List<BlockStopTimeIndex> stopTimeIndicesForStop = _blockIndexService.getStopTimeIndicesForStop(stopEntry);
for (BlockStopTimeIndex bsti : stopTimeIndicesForStop) {
List<BlockStopTimeEntry> stopTimes = bsti.getStopTimes();
for (BlockStopTimeEntry bste : stopTimes) {
StopTimeEntry stopTime = bste.getStopTime();
TripEntry theTrip = stopTime.getTrip();
if (routeId != null && !theTrip.getRoute().getId().toString().equals(routeId)) {
continue;
}
if (directionId != null && theTrip.getDirectionId() != null) {
if (!theTrip.getDirectionId().equals(directionId)) {
continue;
}
}
/*
* If at least one stoptime on one trip (subject to the
* route and direction filters above) permits unrestricted
* pick-up or drop-off at this stop (type=0), then it is
* considered a 'revenue' stop.
*/
if (stopTime.getDropOffType() == 0 || stopTime.getPickupType() == 0) {
return true;
}
}
}
return false;
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex 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();
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex in project onebusaway-application-modules by camsys.
the class StopScheduleServiceImpl method getAllServiceIdsForStop.
private Set<ServiceIdActivation> getAllServiceIdsForStop(StopEntry stop, boolean includePrivateService) {
Set<ServiceIdActivation> allServiceIds = new HashSet<ServiceIdActivation>();
List<BlockStopTimeIndex> indices = _blockIndexService.getStopTimeIndicesForStop(stop);
for (BlockStopTimeIndex index : indices) allServiceIds.add(index.getServiceIds());
List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stop);
for (FrequencyBlockStopTimeIndex index : frequencyIndices) allServiceIds.add(index.getServiceIds());
for (Iterator<ServiceIdActivation> it = allServiceIds.iterator(); it.hasNext(); ) {
ServiceIdActivation activation = it.next();
LocalizedServiceId lsid = activation.getActiveServiceIds().get(0);
String agencyId = lsid.getId().getAgencyId();
AgencyBean bean = _agencyBeanService.getAgencyForId(agencyId);
if (bean.isPrivateService() && !includePrivateService)
it.remove();
}
return allServiceIds;
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method getCalendarForStop.
@Cacheable
public StopCalendarDaysBean getCalendarForStop(AgencyAndId stopId) {
TimeZone timeZone = _agencyService.getTimeZoneForAgencyId(stopId.getAgencyId());
StopEntry stopEntry = _graph.getStopEntryForId(stopId);
Set<ServiceIdActivation> serviceIds = new HashSet<ServiceIdActivation>();
for (BlockStopTimeIndex index : _blockIndexService.getStopTimeIndicesForStop(stopEntry)) serviceIds.add(index.getServiceIds());
for (FrequencyBlockStopTimeIndex index : _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry)) serviceIds.add(index.getServiceIds());
SortedMap<ServiceDate, Set<ServiceIdActivation>> serviceIdsByDate = getServiceIdsByDate(serviceIds);
Counter<Set<ServiceIdActivation>> counts = new Counter<Set<ServiceIdActivation>>();
for (Set<ServiceIdActivation> ids : serviceIdsByDate.values()) counts.increment(ids);
int total = counts.size();
Map<Set<ServiceIdActivation>, Integer> idsToGroup = new HashMap<Set<ServiceIdActivation>, Integer>();
for (Set<ServiceIdActivation> ids : counts.getSortedKeys()) idsToGroup.put(ids, total--);
List<StopCalendarDayBean> beans = new ArrayList<StopCalendarDayBean>(serviceIdsByDate.size());
for (Map.Entry<ServiceDate, Set<ServiceIdActivation>> entry : serviceIdsByDate.entrySet()) {
StopCalendarDayBean bean = new StopCalendarDayBean();
ServiceDate serviceDate = entry.getKey();
Date date = serviceDate.getAsDate(timeZone);
bean.setDate(date);
Integer indexId = idsToGroup.get(entry.getValue());
bean.setGroup(indexId);
beans.add(bean);
}
return new StopCalendarDaysBean(timeZone.getID(), beans);
}
Aggregations