Search in sources :

Example 1 with Record

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;
}
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 Record

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);
    }
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 3 with Record

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);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) 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) Date(java.util.Date)

Example 4 with Record

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;
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) CurrentVehicleEstimateQueryBean(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Record

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;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) CurrentVehicleEstimateQueryBean(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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