Search in sources :

Example 11 with Record

use of org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record in project onebusaway-application-modules by camsys.

the class CurrentVehicleEstimationServiceImpl method computeCumulativeProbabilityForScheduledBlockLocations.

private void computeCumulativeProbabilityForScheduledBlockLocations(List<Record> records, BlockInstance blockInstance, double minProbabilityForConsideration, List<CurrentVehicleEstimateBean> beans) {
    DoubleArrayList ps = new DoubleArrayList();
    List<ScheduledBlockLocation> blockLocations = new ArrayList<ScheduledBlockLocation>();
    Record firstRecord = records.get(0);
    ScheduledBlockLocation firstLocation = _blockGeospatialService.getBestScheduledBlockLocationForLocation(blockInstance, firstRecord.getLocation(), firstRecord.getTimestamp(), 0, Double.POSITIVE_INFINITY);
    blockLocations.add(firstLocation);
    ps.add(updateScheduledBlockLocationProbability(blockInstance, firstRecord, firstLocation));
    Record lastRecord = records.get(records.size() - 1);
    ScheduledBlockLocation lastLocation = _blockGeospatialService.getBestScheduledBlockLocationForLocation(blockInstance, lastRecord.getLocation(), lastRecord.getTimestamp(), 0, Double.POSITIVE_INFINITY);
    ps.add(updateScheduledBlockLocationProbability(blockInstance, lastRecord, lastLocation));
    if (Descriptive.mean(ps) < minProbabilityForConsideration)
        return;
    /**
     * If the vehicle is traveling backwards in time, we kill the prediction
     */
    int maxTravelBackwardsTime = computeMaxTravelBackwardsTime(lastRecord.getTimestamp() - firstRecord.getTimestamp());
    if (lastLocation.getScheduledTime() < firstLocation.getScheduledTime() - maxTravelBackwardsTime)
        return;
    double minDistanceAlongBlock = Math.min(firstLocation.getDistanceAlongBlock(), lastLocation.getDistanceAlongBlock()) - 500;
    double maxDistanceAlongBlock = Math.max(firstLocation.getDistanceAlongBlock(), lastLocation.getDistanceAlongBlock()) + 500;
    for (int i = 1; i < records.size() - 1; i++) {
        Record record = records.get(i);
        ScheduledBlockLocation location = _blockGeospatialService.getBestScheduledBlockLocationForLocation(blockInstance, record.getLocation(), record.getTimestamp(), minDistanceAlongBlock, maxDistanceAlongBlock);
        blockLocations.add(location);
        ps.add(updateScheduledBlockLocationProbability(blockInstance, record, location));
        if (Descriptive.mean(ps) < minProbabilityForConsideration)
            return;
    }
    blockLocations.add(lastLocation);
    updateProbabilitiesWithScheduleDeviations(records, blockLocations, ps);
    BlockLocation location = _blockLocationService.getLocationForBlockInstanceAndScheduledBlockLocation(blockInstance, lastLocation, lastRecord.getTimestamp());
    double mu = Descriptive.mean(ps);
    String debug = asString(ps);
    addResult(location, mu, debug, minProbabilityForConsideration, beans);
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) DoubleArrayList(cern.colt.list.DoubleArrayList) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Aggregations

Record (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)11 ArrayList (java.util.ArrayList)6 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)6 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)6 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)5 DoubleArrayList (cern.colt.list.DoubleArrayList)4 Date (java.util.Date)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 CurrentVehicleEstimateQueryBean (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean)3 HashMap (java.util.HashMap)2 CurrentVehicleEstimateBean (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateBean)2 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)2 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)2 BlockSequenceIndex (org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 List (java.util.List)1 Map (java.util.Map)1 Max (org.onebusaway.collections.Max)1 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)1