use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class ScheduledBlockLocationServiceImpl method getLocationAlongShape.
private PointAndOrientation getLocationAlongShape(BlockTripEntry activeBlockTrip, double distanceAlongBlock, int shapePointIndexFrom, int shapePointIndexTo) {
TripEntry activeTrip = activeBlockTrip.getTrip();
AgencyAndId shapeId = activeTrip.getShapeId();
if (shapeId == null)
return null;
ShapePoints shapePoints = _shapePointService.getShapePointsForShapeId(shapeId);
if (shapePoints == null || shapePoints.isEmpty())
return null;
/**
* We allow callers of this method to specify an arbitrarily high
* shapePointIndexTo, knowing we'll bound it by the max number of points
*/
shapePointIndexFrom = Math.min(shapePointIndexFrom, shapePoints.getSize());
shapePointIndexTo = Math.min(shapePointIndexTo, shapePoints.getSize());
double distanceAlongTrip = distanceAlongBlock - activeBlockTrip.getDistanceAlongBlock();
ShapePointIndex shapePointIndexMethod = new DistanceTraveledShapePointIndex(distanceAlongTrip, shapePointIndexFrom, shapePointIndexTo);
return shapePointIndexMethod.getPointAndOrientation(shapePoints);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImpl method areBlockTripsContinuous.
private boolean areBlockTripsContinuous(BlockTripEntry prevBlockTrip, BlockTripEntry nextBlockTrip) {
List<BlockStopTimeEntry> prevStopTimes = prevBlockTrip.getStopTimes();
List<BlockStopTimeEntry> nextStopTimes = nextBlockTrip.getStopTimes();
BlockStopTimeEntry from = prevStopTimes.get(prevStopTimes.size() - 1);
BlockStopTimeEntry to = nextStopTimes.get(0);
int slack = to.getAccumulatedSlackTime() - (from.getAccumulatedSlackTime() + from.getStopTime().getSlackTime());
int schedTime = to.getStopTime().getArrivalTime() - from.getStopTime().getDepartureTime();
/**
* If the slack time is too much, the trips are not continuous
*/
if (slack >= _maxSlackBetweenConsecutiveTrips)
return false;
/**
* If the sched time is too much, the trips are not continuous
*/
if (schedTime >= _maxScheduledTimeBetweenConsecutiveTrips)
return false;
TripEntry prevTrip = prevBlockTrip.getTrip();
TripEntry nextTrip = nextBlockTrip.getTrip();
AgencyAndId lineIdA = prevTrip.getRouteCollection().getId();
AgencyAndId lineIdB = nextTrip.getRouteCollection().getId();
String directionA = prevTrip.getDirectionId();
String directionB = nextTrip.getDirectionId();
/**
* If the route has not changed, but the direction has, the trips are not
* continuous
*/
if (lineIdA.equals(lineIdB) && (directionA == null || !directionA.equals(directionB)))
return false;
double prevOrientation = computeDirectionOfTravel(prevStopTimes);
double nextOrientation = computeDirectionOfTravel(nextStopTimes);
double delta = GeometryLibrary.getAngleDifference(prevOrientation, nextOrientation);
return true;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class TransitDataServiceTemplateImpl method createArrivalAndDepartureQuery.
protected ArrivalAndDepartureQuery createArrivalAndDepartureQuery(ArrivalAndDepartureForStopQueryBean query) {
ArrivalAndDepartureQuery adQuery = new ArrivalAndDepartureQuery();
AgencyAndId stopId = AgencyAndIdLibrary.convertFromString(query.getStopId());
StopEntry stop = _transitGraphDao.getStopEntryForId(stopId, true);
AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(query.getTripId());
TripEntry trip = _transitGraphDao.getTripEntryForId(tripId);
if (trip == null)
throw new NoSuchTripServiceException(query.getTripId());
adQuery.setStop(stop);
adQuery.setStopSequence(query.getStopSequence());
adQuery.setTrip(trip);
adQuery.setServiceDate(query.getServiceDate());
adQuery.setVehicleId(AgencyAndIdLibrary.convertFromString(query.getVehicleId()));
adQuery.setTime(query.getTime());
return adQuery;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class BlockLocationHistoryTask method run.
@Override
public void run() {
if (_source == null) {
_log.info("No BlockLocationHistoryTask data source specified. Skipping this optional task");
}
int tripIndex = 0;
Iterable<TripEntry> allTrips = _transitGraphDao.getAllTrips();
boolean skipTo = _skipToTrip != null;
for (TripEntry trip : allTrips) {
if (tripIndex % 20 == 0)
_log.info("tripsProcessed=" + tripIndex);
tripIndex++;
if (_skipToTrip != null && trip.getId().equals(_skipToTrip)) {
skipTo = false;
} else if (!skipTo) {
try {
processTrip(trip);
} catch (Throwable ex) {
_log.warn("error processing trip " + trip.getId(), ex);
}
}
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class UserReportingServiceImpl method getRecordAsBean.
private TripProblemReportBean getRecordAsBean(TripProblemReportRecord record) {
AgencyAndId stopId = record.getStopId();
AgencyAndId tripId = record.getTripId();
TripProblemReportBean bean = new TripProblemReportBean();
bean.setCode(record.getCode());
bean.setId(record.getId());
bean.setServiceDate(record.getServiceDate());
bean.setStatus(record.getStatus());
bean.setLabel(record.getLabel());
bean.setStopId(AgencyAndIdLibrary.convertToString(stopId));
bean.setTime(record.getTime());
bean.setTripId(AgencyAndIdLibrary.convertToString(tripId));
bean.setUserComment(record.getUserComment());
bean.setUserLat(record.getUserLat());
bean.setUserLon(record.getUserLon());
bean.setUserLocationAccuracy(record.getUserLocationAccuracy());
bean.setUserOnVehicle(record.isUserOnVehicle());
bean.setUserVehicleNumber(record.getUserVehicleNumber());
bean.setPredicted(record.isPredicted());
bean.setVehicleId(AgencyAndIdLibrary.convertToString(record.getVehicleId()));
bean.setDistanceAlongBlock(record.getDistanceAlongBlock());
bean.setScheduleDeviation(record.getScheduleDeviation());
bean.setVehicleLat(record.getVehicleLat());
bean.setVehicleLon(record.getVehicleLon());
if (stopId != null) {
try {
bean.setStop(_stopBeanService.getStopForId(stopId));
} catch (NoSuchStopServiceException ex) {
}
}
if (tripId != null) {
bean.setTrip(_tripBeanService.getTripForId(tripId));
}
if (tripId != null && stopId != null) {
TripEntry trip = _graph.getTripEntryForId(tripId);
StopEntry stop = _graph.getStopEntryForId(stopId);
if (trip != null && stop != null) {
AgencyAndId vehicleId = record.getMatchedVehicleId();
if (vehicleId == null)
vehicleId = record.getVehicleId();
ArrivalAndDepartureQuery query = new ArrivalAndDepartureQuery();
query.setStop(stop);
query.setStopSequence(-1);
query.setTrip(trip);
query.setServiceDate(record.getServiceDate());
query.setVehicleId(vehicleId);
query.setTime(record.getTime());
ArrivalAndDepartureInstance instance = _arrivalAndDepartureService.getArrivalAndDepartureForStop(query);
if (instance != null) {
StopTimeInstance sti = instance.getStopTimeInstance();
StopTimeInstanceBean stopTimeBean = _stopTimeBeanService.getStopTimeInstanceAsBean(sti);
bean.setStopTime(stopTimeBean);
}
}
}
return bean;
}
Aggregations