use of org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record 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.CurrentVehicleEstimateQueryBean.Record in project onebusaway-application-modules by camsys.
the class CurrentVehicleEstimationServiceImpl method updateProbabilitiesWithScheduleDeviations.
private void updateProbabilitiesWithScheduleDeviations(List<Record> records, List<ScheduledBlockLocation> blockLocations, DoubleArrayList ps) {
if (records.size() != blockLocations.size())
throw new IllegalStateException();
if (records.size() != ps.size())
throw new IllegalStateException();
for (int i = 1; i < records.size(); i++) {
Record prevRecord = records.get(i - 1);
Record nextRecord = records.get(i);
long recordDeltaT = (nextRecord.getTimestamp() - prevRecord.getTimestamp());
if (recordDeltaT <= 0)
continue;
int maxTravelBackwardsTime = computeMaxTravelBackwardsTime(recordDeltaT);
ScheduledBlockLocation prevLocation = blockLocations.get(i - 1);
ScheduledBlockLocation nextLocation = blockLocations.get(i);
int locationDeltaT = nextLocation.getScheduledTime() - prevLocation.getScheduledTime();
if (locationDeltaT < 0 && Math.abs(locationDeltaT) > maxTravelBackwardsTime)
ps.set(i, 0.0);
}
}
use of org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record in project onebusaway-application-modules by camsys.
the class CurrentVehicleEstimationServiceImpl method computeCumulativeProbabilityForRealTimeBlockLocations.
private void computeCumulativeProbabilityForRealTimeBlockLocations(Map<Date, Record> recordsByTime, List<BlockLocation> locations, double minProbabilityForConsideration, List<CurrentVehicleEstimateBean> beans) {
DoubleArrayList ps = new DoubleArrayList();
for (BlockLocation location : locations) {
Date t = new Date(location.getTime());
Record record = recordsByTime.get(t);
CoordinatePoint userLocation = record.getLocation();
CoordinatePoint vehicleLocation = location.getLocation();
double d = SphericalGeometryLibrary.distance(userLocation, vehicleLocation);
double p = _realTimeLocationDeviationModel.probability(d);
ps.add(p);
}
BlockLocation last = locations.get(locations.size() - 1);
double mu = Descriptive.mean(ps);
String debug = asString(ps);
addResult(last, mu, debug, minProbabilityForConsideration, beans);
}
use of org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record in project onebusaway-application-modules by camsys.
the class SimulateScheduledVehicleLocationsController method index.
@RequestMapping()
public ModelAndView index(@RequestParam() String blockId, @RequestParam() long serviceDate, @RequestParam(defaultValue = "0") int scheduleDeviation, @RequestParam(defaultValue = "0.0") double noise) {
AgencyAndId bid = AgencyAndIdLibrary.convertFromString(blockId);
BlockInstance blockInstance = _blockCalendarService.getBlockInstance(bid, serviceDate);
CurrentVehicleEstimateQueryBean bean = new CurrentVehicleEstimateQueryBean();
long time = SystemTime.currentTimeMillis();
List<Record> records = new ArrayList<Record>();
for (int i = 0; i < 5 * 60; i += 30) {
int scheduleTime = (int) ((time - blockInstance.getServiceDate()) / 1000 - scheduleDeviation - i);
ScheduledBlockLocation location = _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(blockInstance.getBlock(), scheduleTime);
if (location != null) {
CoordinatePoint p = applyNoiseToLocation(location.getLocation(), noise);
Record r = new Record();
r.setLocation(location.getLocation());
r.setTimestamp(time - i * 1000);
r.setLocation(p);
r.setAccuracy(noise);
records.add(r);
}
}
bean.setRecords(records);
ModelAndView mv = new ModelAndView("simulate-vehicle-locations.jspx");
mv.addObject("time", time);
mv.addObject("query", bean);
return mv;
}
use of org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record in project onebusaway-application-modules by camsys.
the class SimulateVehicleLocationsController method index.
@RequestMapping()
public ModelAndView index(@RequestParam() String vehicleId, @RequestParam(defaultValue = "0.0") double noise) {
AgencyAndId vid = AgencyAndIdLibrary.convertFromString(vehicleId);
CurrentVehicleEstimateQueryBean bean = new CurrentVehicleEstimateQueryBean();
long time = SystemTime.currentTimeMillis();
List<Record> records = new ArrayList<Record>();
for (int i = 0; i < 5 * 60; i += 30) {
TargetTime tt = new TargetTime(time - i * 1000);
BlockLocation location = _blockLocationService.getLocationForVehicleAndTime(vid, tt);
if (location != null) {
CoordinatePoint p = applyNoiseToLocation(location.getLocation(), noise);
Record r = new Record();
r.setLocation(location.getLocation());
r.setTimestamp(tt.getTargetTime());
r.setLocation(p);
r.setAccuracy(noise);
records.add(r);
}
}
bean.setRecords(records);
ModelAndView mv = new ModelAndView("simulate-vehicle-locations.jspx");
mv.addObject("time", time);
mv.addObject("query", bean);
return mv;
}
Aggregations