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;
}
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));
}
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);
}
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);
}
}
Aggregations