Search in sources :

Example 1 with CurrentVehicleEstimateBean

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

the class CurrentVehicleEstimationServiceImpl method tryDirectMatchAgainstVehicleId.

/**
 **
 * Private Methods
 ***
 */
private boolean tryDirectMatchAgainstVehicleId(CurrentVehicleEstimateQueryBean query, List<Record> records, List<CurrentVehicleEstimateBean> beans) {
    if (query.getVehicleId() == null)
        return false;
    Record record = records.get(records.size() - 1);
    AgencyAndId vehicleId = AgencyAndIdLibrary.convertFromString(query.getVehicleId());
    BlockLocation location = _blockLocationService.getLocationForVehicleAndTime(vehicleId, new TargetTime(record.getTimestamp()));
    if (location == null)
        return false;
    double d = SphericalGeometryLibrary.distance(record.getLocation(), location.getLocation());
    double p = _realTimeLocationDeviationModel.probability(d);
    if (p < _shortCutProbability)
        return false;
    CurrentVehicleEstimateBean bean = new CurrentVehicleEstimateBean();
    bean.setProbability(p);
    bean.setTripStatus(_tripStatusBeanService.getBlockLocationAsStatusBean(location, query.getTime()));
    beans.add(bean);
    return true;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) CurrentVehicleEstimateBean(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateBean) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime)

Example 2 with CurrentVehicleEstimateBean

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

the class EstimateCurrentVehicleAction method index.

public DefaultHttpHeaders index() throws IOException, ServiceException {
    if (!isVersion(V2))
        return setUnknownVersionResponse();
    if (hasErrors())
        return setValidationErrorsResponse();
    fillInQuery();
    if (hasErrors())
        return setValidationErrorsResponse();
    BeanFactoryV2 factory = getBeanFactoryV2();
    ListBean<CurrentVehicleEstimateBean> estimates = _service.getCurrentVehicleEstimates(_query);
    return setOkResponse(factory.getCurrentVehicleEstimates(estimates));
}
Also used : CurrentVehicleEstimateBean(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateBean) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Example 3 with CurrentVehicleEstimateBean

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

the class CurrentVehicleEstimationServiceImpl method getCurrentVehicleEstimates.

@Override
public ListBean<CurrentVehicleEstimateBean> getCurrentVehicleEstimates(CurrentVehicleEstimateQueryBean query) {
    long minT = SystemTime.currentTimeMillis() - _maxWindow * 60 * 1000;
    minT = 0;
    List<Record> records = getRecords(query.getRecords(), minT);
    if (records.isEmpty())
        return new ListBean<CurrentVehicleEstimateBean>();
    List<CurrentVehicleEstimateBean> beans = new ArrayList<CurrentVehicleEstimateBean>();
    if (tryDirectMatchAgainstVehicleId(query, records, beans))
        return new ListBean<CurrentVehicleEstimateBean>(beans, true);
    Map<Date, Record> recordsByTime = getRecordsByTimestamp(records);
    List<Date> timestamps = new ArrayList<Date>(recordsByTime.keySet());
    Collections.sort(timestamps);
    if (tryDirectMatchAgainstBlockId(query, records, recordsByTime, timestamps, query.getMinProbability(), beans))
        return new ListBean<CurrentVehicleEstimateBean>(beans, true);
    Set<BlockSequenceIndex> allIndices = getBlockSequenceIndicesForRecords(recordsByTime);
    for (BlockSequenceIndex index : allIndices) {
        Map<BlockInstance, List<List<BlockLocation>>> allLocations = _blockStatusService.getBlocksForIndex(index, timestamps);
        for (Map.Entry<BlockInstance, List<List<BlockLocation>>> entry : allLocations.entrySet()) {
            BlockInstance blockInstance = entry.getKey();
            List<List<BlockLocation>> realTimeLocations = entry.getValue();
            computeEstimatesForBlockInstance(records, recordsByTime, blockInstance, realTimeLocations, query.getMinProbability(), beans);
        }
    }
    Collections.sort(beans);
    return new ListBean<CurrentVehicleEstimateBean>(beans, false);
}
Also used : BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) Date(java.util.Date) CurrentVehicleEstimateBean(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateBean) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with CurrentVehicleEstimateBean

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

the class CurrentVehicleEstimationServiceImpl method addResult.

private void addResult(BlockLocation location, double cumulativeP, String debug, double minProbabilityForConsideration, List<CurrentVehicleEstimateBean> beans) {
    if (cumulativeP >= minProbabilityForConsideration) {
        CurrentVehicleEstimateBean bean = new CurrentVehicleEstimateBean();
        bean.setProbability(cumulativeP);
        TripStatusBean status = _tripStatusBeanService.getBlockLocationAsStatusBean(location, location.getTime());
        bean.setTripStatus(status);
        bean.setDebug(debug);
        beans.add(bean);
    }
}
Also used : CurrentVehicleEstimateBean(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean)

Aggregations

CurrentVehicleEstimateBean (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateBean)4 Record (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)2 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)2 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)2 DoubleArrayList (cern.colt.list.DoubleArrayList)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 BeanFactoryV2 (org.onebusaway.api.model.transit.BeanFactoryV2)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 ListBean (org.onebusaway.transit_data.model.ListBean)1 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)1 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)1 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)1 BlockSequenceIndex (org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex)1