Search in sources :

Example 26 with CoordinatePoint

use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.

the class SimulateScheduledVehicleLocationsController method applyNoiseToLocation.

private CoordinatePoint applyNoiseToLocation(CoordinatePoint location, double noise) {
    CoordinateBounds b = SphericalGeometryLibrary.bounds(location, noise);
    double latSpan = b.getMaxLat() - b.getMinLat();
    double lonSpan = b.getMaxLon() - b.getMinLon();
    double lat = b.getMinLat() + Math.random() * latSpan;
    double lon = b.getMinLon() + Math.random() * lonSpan;
    return new CoordinatePoint(lat, lon);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 27 with CoordinatePoint

use of org.onebusaway.geospatial.model.CoordinatePoint 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 28 with CoordinatePoint

use of org.onebusaway.geospatial.model.CoordinatePoint 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)

Example 29 with CoordinatePoint

use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.

the class SimulateVehicleLocationsController method applyNoiseToLocation.

private CoordinatePoint applyNoiseToLocation(CoordinatePoint location, double noise) {
    CoordinateBounds b = SphericalGeometryLibrary.bounds(location, noise);
    double latSpan = b.getMaxLat() - b.getMinLat();
    double lonSpan = b.getMaxLon() - b.getMinLon();
    double lat = b.getMinLat() + Math.random() * latSpan;
    double lon = b.getMinLon() + Math.random() * lonSpan;
    return new CoordinatePoint(lat, lon);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 30 with CoordinatePoint

use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.

the class UserReportingServiceImpl method reportProblemWithTrip.

@Override
public void reportProblemWithTrip(TripProblemReportBean problem) {
    AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(problem.getTripId());
    TripEntry trip = _graph.getTripEntryForId(tripId);
    if (trip == null)
        return;
    BlockEntry block = trip.getBlock();
    TripProblemReportRecord record = new TripProblemReportRecord();
    record.setCode(problem.getCode());
    record.setServiceDate(problem.getServiceDate());
    String vehicleId = problem.getVehicleId();
    if (vehicleId != null)
        record.setVehicleId(AgencyAndIdLibrary.convertFromString(vehicleId));
    String stopId = problem.getStopId();
    if (stopId != null)
        record.setStopId(AgencyAndIdLibrary.convertFromString(stopId));
    record.setTime(problem.getTime());
    record.setTripId(tripId);
    record.setBlockId(block.getId());
    record.setUserComment(problem.getUserComment());
    if (problem.getUserLat() != null && !Double.isNaN(problem.getUserLat()))
        record.setUserLat(problem.getUserLat());
    if (problem.getUserLon() != null && !Double.isNaN(problem.getUserLon()))
        record.setUserLon(problem.getUserLon());
    if (problem.getUserLocationAccuracy() != null && !Double.isNaN(problem.getUserLocationAccuracy()))
        record.setUserLocationAccuracy(problem.getUserLocationAccuracy());
    record.setUserOnVehicle(problem.isUserOnVehicle());
    record.setUserVehicleNumber(problem.getUserVehicleNumber());
    Map<BlockInstance, List<BlockLocation>> locationsByInstance = _blockStatusService.getBlocks(block.getId(), problem.getServiceDate(), record.getVehicleId(), problem.getTime());
    BlockInstance blockInstance = getBestBlockInstance(locationsByInstance.keySet());
    if (blockInstance != null) {
        List<BlockLocation> blockLocations = locationsByInstance.get(blockInstance);
        BlockLocation blockLocation = getBestLocation(blockLocations, problem);
        if (blockLocation != null) {
            record.setPredicted(blockLocation.isPredicted());
            if (blockLocation.isDistanceAlongBlockSet())
                record.setDistanceAlongBlock(blockLocation.getDistanceAlongBlock());
            if (blockLocation.isScheduleDeviationSet())
                record.setScheduleDeviation(blockLocation.getScheduleDeviation());
            CoordinatePoint p = blockLocation.getLocation();
            if (p != null) {
                record.setVehicleLat(p.getLat());
                record.setVehicleLon(p.getLon());
            }
            record.setMatchedVehicleId(blockLocation.getVehicleId());
        }
    }
    record.setStatus(problem.getStatus());
    _userReportingDao.saveOrUpdate(record);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) ArrayList(java.util.ArrayList) List(java.util.List) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation)

Aggregations

CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)57 ArrayList (java.util.ArrayList)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)12 Test (org.junit.Test)10 XYPoint (org.onebusaway.geospatial.model.XYPoint)10 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)9 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)7 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)7 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)7 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)6 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)6 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)5 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)4 VehicleLocationRecordBean (org.onebusaway.transit_data.model.realtime.VehicleLocationRecordBean)4 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)4 VehiclePosition (com.google.transit.realtime.GtfsRealtime.VehiclePosition)3 List (java.util.List)3 Min (org.onebusaway.collections.Min)3 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)3 Record (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)3