Search in sources :

Example 6 with Record

use of org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record in project onebusaway-application-modules by camsys.

the class EstimateCurrentVehicleAction method fillInQuery.

private void fillInQuery() {
    List<CurrentVehicleEstimateQueryBean.Record> records = new ArrayList<CurrentVehicleEstimateQueryBean.Record>();
    Max<Record> max = new Max<Record>();
    for (String record : _data.split("\\|")) {
        String[] tokens = record.split(",");
        if (tokens.length != 4) {
            addFieldError("data", Messages.INVALID_FIELD_VALUE);
            return;
        }
        try {
            long t = Long.parseLong(tokens[0]);
            double lat = Double.parseDouble(tokens[1]);
            double lon = Double.parseDouble(tokens[2]);
            double accuracy = Double.parseDouble(tokens[3]);
            Record r = new Record();
            r.setTimestamp(t);
            r.setLocation(new CoordinatePoint(lat, lon));
            r.setAccuracy(accuracy);
            records.add(r);
            max.add(t, r);
        } catch (NumberFormatException ex) {
            addFieldError("data", Messages.INVALID_FIELD_VALUE);
            return;
        }
    }
    _query.setRecords(records);
    if (records.isEmpty()) {
        addFieldError("data", Messages.INVALID_FIELD_VALUE);
        return;
    }
    _query.setMostRecentLocation(max.getMaxElement().getLocation());
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Max(org.onebusaway.collections.Max) CurrentVehicleEstimateQueryBean(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean) ArrayList(java.util.ArrayList) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)

Example 7 with Record

use of org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record 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);
}
Also used : BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) Date(java.util.Date) CurrentVehicleEstimateBean(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateBean) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with Record

use of org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record in project onebusaway-application-modules by camsys.

the class CurrentVehicleEstimationServiceImpl method getRecords.

private List<Record> getRecords(List<Record> records, long minT) {
    List<Record> pruned = new ArrayList<Record>();
    for (Record record : records) {
        if (record.getTimestamp() < minT)
            continue;
        if (record.getAccuracy() > _maxAccuracy)
            continue;
        pruned.add(record);
    }
    Collections.sort(pruned);
    return pruned;
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)

Example 9 with Record

use of org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record in project onebusaway-application-modules by camsys.

the class CurrentVehicleEstimationServiceImpl method getBlockSequenceIndicesForRecords.

private Set<BlockSequenceIndex> getBlockSequenceIndicesForRecords(Map<Date, Record> recordsByTime) {
    Set<BlockSequenceIndex> allIndices = null;
    for (Record record : recordsByTime.values()) {
        CoordinateBounds bounds = SphericalGeometryLibrary.bounds(record.getLocation(), record.getAccuracy());
        Set<BlockSequenceIndex> indices = _blockGeospatialService.getBlockSequenceIndexPassingThroughBounds(bounds);
        if (allIndices == null)
            allIndices = indices;
        else
            allIndices.retainAll(indices);
    }
    return allIndices;
}
Also used : BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 10 with Record

use of org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record in project onebusaway-application-modules by camsys.

the class CurrentVehicleEstimationServiceImpl method getRecordsByTimestamp.

private Map<Date, Record> getRecordsByTimestamp(List<Record> records) {
    Map<Date, Record> recordsByTime = new HashMap<Date, Record>();
    for (Record record : records) {
        Date timestamp = new Date(record.getTimestamp());
        recordsByTime.put(timestamp, record);
    }
    return recordsByTime;
}
Also used : HashMap(java.util.HashMap) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) Date(java.util.Date)

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