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());
}
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);
}
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;
}
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;
}
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;
}
Aggregations