Search in sources :

Example 36 with TimepointPredictionRecord

use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.

the class BlockLocationServiceImpl method getVehicleLocationRecordAsBlockLocationRecord.

private List<BlockLocationRecord> getVehicleLocationRecordAsBlockLocationRecord(BlockInstance blockInstance, VehicleLocationRecord record, ScheduledBlockLocation scheduledBlockLocation) {
    BlockLocationRecord.Builder builder = BlockLocationRecord.builder();
    if (scheduledBlockLocation != null) {
        BlockTripEntry activeTrip = scheduledBlockLocation.getActiveTrip();
        builder.setTripId(activeTrip.getTrip().getId());
        builder.setBlockId(activeTrip.getBlockConfiguration().getBlock().getId());
        // store the vehicleType for later retrieval
        builder.setVehicleType(EVehicleType.toEnum(activeTrip.getTrip().getRoute().getType()));
        double distanceAlongBlock = scheduledBlockLocation.getDistanceAlongBlock();
        builder.setDistanceAlongBlock(distanceAlongBlock);
        double distanceAlongTrip = distanceAlongBlock - activeTrip.getDistanceAlongBlock();
        builder.setDistanceAlongTrip(distanceAlongTrip);
    }
    if (record.getBlockId() != null)
        builder.setBlockId(record.getBlockId());
    if (record.getTripId() != null)
        builder.setTripId(record.getTripId());
    builder.setTime(record.getTimeOfRecord());
    builder.setServiceDate(record.getServiceDate());
    if (record.isScheduleDeviationSet())
        builder.setScheduleDeviation(record.getScheduleDeviation());
    if (record.isDistanceAlongBlockSet()) {
        double distanceAlongBlock = record.getDistanceAlongBlock();
        builder.setDistanceAlongBlock(distanceAlongBlock);
        AgencyAndId tripId = record.getTripId();
        if (tripId != null) {
            BlockConfigurationEntry block = blockInstance.getBlock();
            for (BlockTripEntry blockTrip : block.getTrips()) {
                TripEntry trip = blockTrip.getTrip();
                if (trip.getId().equals(tripId)) {
                    double distanceAlongTrip = distanceAlongBlock - blockTrip.getDistanceAlongBlock();
                    builder.setDistanceAlongTrip(distanceAlongTrip);
                }
            }
        }
    }
    if (record.isCurrentLocationSet()) {
        builder.setLocationLat(record.getCurrentLocationLat());
        builder.setLocationLon(record.getCurrentLocationLon());
    }
    if (record.isCurrentOrientationSet())
        builder.setOrientation(record.getCurrentOrientation());
    builder.setPhase(record.getPhase());
    builder.setStatus(record.getStatus());
    builder.setVehicleId(record.getVehicleId());
    List<TimepointPredictionRecord> predictions = record.getTimepointPredictions();
    if (predictions == null || predictions.isEmpty())
        return Arrays.asList(builder.create());
    List<BlockLocationRecord> results = new ArrayList<BlockLocationRecord>();
    for (TimepointPredictionRecord tpr : predictions) {
        builder.setTimepointId(tpr.getTimepointId());
        builder.setTimepointScheduledTime(tpr.getTimepointScheduledTime());
        builder.setTimepointPredictedArrivalTime(tpr.getTimepointPredictedArrivalTime());
        builder.setTimepointPredictedDepartureTime(tpr.getTimepointPredictedDepartureTime());
        results.add(builder.create());
    }
    return results;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Aggregations

TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)36 Test (org.junit.Test)20 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)17 ArrayList (java.util.ArrayList)10 Date (java.util.Date)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)6 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)6 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)5 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)4 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)4 TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)4 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)4 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)4 StopTimeEvent (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent)3 HashMap (java.util.HashMap)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 TripBean (org.onebusaway.transit_data.model.trips.TripBean)3 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)3 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)3