Search in sources :

Example 16 with TripEntry

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);
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) DistanceTraveledShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.ShapePointIndex) DistanceTraveledShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex)

Example 17 with TripEntry

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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 18 with TripEntry

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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) NoSuchTripServiceException(org.onebusaway.exceptions.NoSuchTripServiceException) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)

Example 19 with TripEntry

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);
            }
        }
    }
}
Also used : TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)

Example 20 with TripEntry

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;
}
Also used : StopTimeInstanceBean(org.onebusaway.transit_data.model.StopTimeInstanceBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) ArrivalAndDepartureQuery(org.onebusaway.transit_data_federation.services.ArrivalAndDepartureQuery) NoSuchStopServiceException(org.onebusaway.exceptions.NoSuchStopServiceException) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) TripProblemReportBean(org.onebusaway.transit_data.model.problems.TripProblemReportBean)

Aggregations

TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)73 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)46 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)39 ArrayList (java.util.ArrayList)20 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)18 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)15 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)14 HashSet (java.util.HashSet)13 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)10 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)10 List (java.util.List)9 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)9 Date (java.util.Date)7 Test (org.junit.Test)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)7 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)7 Cacheable (org.onebusaway.container.cache.Cacheable)6 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)6 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)6