Search in sources :

Example 1 with CurrentVehicleEstimateQueryBean

use of org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean 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 2 with CurrentVehicleEstimateQueryBean

use of org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean 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

ArrayList (java.util.ArrayList)2 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 CurrentVehicleEstimateQueryBean (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean)2 Record (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)1 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)1 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)1 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)1