use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class MonitoredResult method addLatLon.
public void addLatLon(float latitude, float longitude) {
CoordinatePoint cp = new CoordinatePoint(latitude, longitude);
_allCoordinates.add(cp);
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class DistanceTraveledShapePointIndex method getPoint.
@Override
public CoordinatePoint getPoint(ShapePoints points) {
int n = points.getSize();
if (n == 0)
throw new IndexOutOfBoundsException();
int index = getIndex(points);
double[] lats = points.getLats();
double[] lons = points.getLons();
double[] dist = points.getDistTraveled();
if (index == 0)
return new CoordinatePoint(lats[0], lons[0]);
if (index == n)
return new CoordinatePoint(lats[n - 1], lons[n - 1]);
if (dist[index] == dist[index - 1])
return new CoordinatePoint(lats[n - 1], lons[n - 1]);
double ratio = (_shapeDistanceTraveled - dist[index - 1]) / (dist[index] - dist[index - 1]);
double lat = ratio * (lats[index] - lats[index - 1]) + lats[index - 1];
double lon = ratio * (lons[index] - lons[index - 1]) + lons[index - 1];
return new CoordinatePoint(lat, lon);
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class ShapePointsFactory method addPoint.
public void addPoint(double lat, double lon) {
CoordinatePoint point = new CoordinatePoint(lat, lon);
_points.add(point);
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class BlockLocationRecordCollectionTest method test01.
@Test
public void test01() {
BlockEntryImpl block = block("blockA");
TripEntryImpl trip = trip("tripA", "serviceId");
stopTime(0, null, trip, time(9, 00), 0);
BlockConfigurationEntry blockConfig = linkBlockTrips(block, trip);
BlockInstance blockInstance = new BlockInstance(blockConfig, System.currentTimeMillis());
SortedMap<Long, BlockLocationRecord> records = new TreeMap<Long, BlockLocationRecord>();
CoordinatePoint p1 = new CoordinatePoint(47.0, -122.0);
CoordinatePoint p2 = new CoordinatePoint(47.1, -122.1);
CoordinatePoint p3 = new CoordinatePoint(47.2, -122.2);
EVehiclePhase inProgress = EVehiclePhase.IN_PROGRESS;
EVehiclePhase layover = EVehiclePhase.LAYOVER_DURING;
addRecord(records, record(t(4, 10), 10.0, 100.0, p1, 0.0, inProgress, "ok"));
addRecord(records, record(t(8, 20), 18.0, 200.0, p2, 90.0, layover, "not ok"));
addRecord(records, record(t(12, 30), 15.0, 300.0, p3, 45.0, inProgress, "ok"));
BlockLocationRecordCollection entry = new BlockLocationRecordCollection(t(3, 20), t(13, 20), records);
assertEquals(t(3, 20), entry.getFromTime());
assertEquals(t(13, 20), entry.getToTime());
assertEquals(10, entry.getScheduleDeviationForTargetTime(t(3, 20)), 0.0);
assertEquals(10, entry.getScheduleDeviationForTargetTime(t(4, 10)), 0.0);
assertEquals(12, entry.getScheduleDeviationForTargetTime(t(5, 12)), 0.0);
assertEquals(14, entry.getScheduleDeviationForTargetTime(t(6, 15)), 0.0);
assertEquals(16, entry.getScheduleDeviationForTargetTime(t(7, 18)), 0.0);
assertEquals(18, entry.getScheduleDeviationForTargetTime(t(8, 20)), 0.0);
assertEquals(17, entry.getScheduleDeviationForTargetTime(t(10, 0)), 0.0);
assertEquals(15, entry.getScheduleDeviationForTargetTime(t(12, 30)), 0.0);
assertEquals(15, entry.getScheduleDeviationForTargetTime(t(13, 20)), 0.0);
assertEquals(80, entry.getDistanceAlongBlockForTargetTime(t(3, 20)), 0.0);
assertEquals(100, entry.getDistanceAlongBlockForTargetTime(t(4, 10)), 0.0);
assertEquals(124.8, entry.getDistanceAlongBlockForTargetTime(t(5, 12)), 0.0);
assertEquals(150, entry.getDistanceAlongBlockForTargetTime(t(6, 15)), 0.0);
assertEquals(175.2, entry.getDistanceAlongBlockForTargetTime(t(7, 18)), 0.0);
assertEquals(200, entry.getDistanceAlongBlockForTargetTime(t(8, 20)), 0.0);
assertEquals(240, entry.getDistanceAlongBlockForTargetTime(t(10, 0)), 0.0);
assertEquals(300, entry.getDistanceAlongBlockForTargetTime(t(12, 30)), 0.0);
assertEquals(320, entry.getDistanceAlongBlockForTargetTime(t(13, 20)), 0.0);
assertNull(entry.getLastLocationForTargetTime(t(3, 20)));
assertNull(entry.getLastLocationForTargetTime(t(4, 9)));
assertEquals(p1, entry.getLastLocationForTargetTime(t(4, 10)));
assertEquals(p1, entry.getLastLocationForTargetTime(t(5, 12)));
assertEquals(p1, entry.getLastLocationForTargetTime(t(8, 19)));
assertEquals(p2, entry.getLastLocationForTargetTime(t(8, 20)));
assertEquals(p2, entry.getLastLocationForTargetTime(t(10, 0)));
assertEquals(p2, entry.getLastLocationForTargetTime(t(12, 29)));
assertEquals(p3, entry.getLastLocationForTargetTime(t(12, 30)));
assertEquals(p3, entry.getLastLocationForTargetTime(t(16, 40)));
assertTrue(Double.isNaN(entry.getLastOrientationForTargetTime(t(3, 20))));
assertTrue(Double.isNaN(entry.getLastOrientationForTargetTime(t(4, 9))));
assertEquals(0.0, entry.getLastOrientationForTargetTime(t(4, 10)), 0.0);
assertEquals(0.0, entry.getLastOrientationForTargetTime(t(5, 12)), 0.0);
assertEquals(0.0, entry.getLastOrientationForTargetTime(t(8, 19)), 0.0);
assertEquals(90.0, entry.getLastOrientationForTargetTime(t(8, 20)), 0.0);
assertEquals(90.0, entry.getLastOrientationForTargetTime(t(10, 0)), 0.0);
assertEquals(90.0, entry.getLastOrientationForTargetTime(t(12, 29)), 0.0);
assertEquals(45.0, entry.getLastOrientationForTargetTime(t(12, 30)), 0.0);
assertEquals(45.0, entry.getLastOrientationForTargetTime(t(16, 40)), 0.0);
assertNull(entry.getPhaseForTargetTime(t(3, 20)));
assertNull(entry.getPhaseForTargetTime(t(4, 9)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(4, 10)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(5, 12)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(8, 19)));
assertEquals(layover, entry.getPhaseForTargetTime(t(8, 20)));
assertEquals(layover, entry.getPhaseForTargetTime(t(10, 0)));
assertEquals(layover, entry.getPhaseForTargetTime(t(12, 29)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(12, 30)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(16, 40)));
assertNull(entry.getStatusForTargetTime(t(3, 20)));
assertNull(entry.getStatusForTargetTime(t(4, 9)));
assertEquals("ok", entry.getStatusForTargetTime(t(4, 10)));
assertEquals("ok", entry.getStatusForTargetTime(t(5, 12)));
assertEquals("ok", entry.getStatusForTargetTime(t(8, 19)));
assertEquals("not ok", entry.getStatusForTargetTime(t(8, 20)));
assertEquals("not ok", entry.getStatusForTargetTime(t(10, 0)));
assertEquals("not ok", entry.getStatusForTargetTime(t(12, 29)));
assertEquals("ok", entry.getStatusForTargetTime(t(12, 30)));
assertEquals("ok", entry.getStatusForTargetTime(t(16, 40)));
CoordinatePoint p4 = new CoordinatePoint(47.15, -122.15);
entry = entry.addRecord(blockInstance, record(t(10, 0), 20, 220, p4, 270.0, layover, "not ok"), t(5, 0));
assertEquals(t(6, 40), entry.getFromTime());
assertEquals(t(11, 40), entry.getToTime());
assertEquals(18, entry.getScheduleDeviationForTargetTime(t(6, 40)), 0.0);
assertEquals(18, entry.getScheduleDeviationForTargetTime(t(8, 20)), 0.0);
assertEquals(19, entry.getScheduleDeviationForTargetTime(t(9, 10)), 0.0);
assertEquals(20, entry.getScheduleDeviationForTargetTime(t(10, 00)), 0.0);
assertEquals(20, entry.getScheduleDeviationForTargetTime(t(10, 50)), 0.0);
assertEquals(20, entry.getScheduleDeviationForTargetTime(t(11, 40)), 0.0);
assertEquals(180, entry.getDistanceAlongBlockForTargetTime(t(6, 40)), 0.0);
assertEquals(200, entry.getDistanceAlongBlockForTargetTime(t(8, 20)), 0.0);
assertEquals(210, entry.getDistanceAlongBlockForTargetTime(t(9, 10)), 0.0);
assertEquals(220, entry.getDistanceAlongBlockForTargetTime(t(10, 00)), 0.0);
assertEquals(230, entry.getDistanceAlongBlockForTargetTime(t(10, 50)), 0.0);
assertEquals(240, entry.getDistanceAlongBlockForTargetTime(t(11, 40)), 0.0);
assertNull(entry.getLastLocationForTargetTime(t(6, 40)));
assertEquals(p2, entry.getLastLocationForTargetTime(t(8, 20)));
assertEquals(p2, entry.getLastLocationForTargetTime(t(9, 10)));
assertEquals(p4, entry.getLastLocationForTargetTime(t(10, 00)));
assertEquals(p4, entry.getLastLocationForTargetTime(t(10, 50)));
assertTrue(Double.isNaN(entry.getLastOrientationForTargetTime(t(6, 40))));
assertEquals(90.0, entry.getLastOrientationForTargetTime(t(8, 20)), 0.0);
assertEquals(90.0, entry.getLastOrientationForTargetTime(t(9, 10)), 0.0);
assertEquals(270.0, entry.getLastOrientationForTargetTime(t(10, 00)), 0.0);
assertEquals(270.0, entry.getLastOrientationForTargetTime(t(10, 50)), 0.0);
assertNull(entry.getPhaseForTargetTime(t(6, 40)));
assertEquals(layover, entry.getPhaseForTargetTime(t(8, 20)));
assertEquals(layover, entry.getPhaseForTargetTime(t(9, 10)));
assertEquals(layover, entry.getPhaseForTargetTime(t(10, 00)));
assertEquals(layover, entry.getPhaseForTargetTime(t(10, 50)));
assertNull(entry.getStatusForTargetTime(t(6, 40)));
assertEquals("not ok", entry.getStatusForTargetTime(t(8, 20)));
assertEquals("not ok", entry.getStatusForTargetTime(t(9, 10)));
assertEquals("not ok", entry.getStatusForTargetTime(t(10, 00)));
assertEquals("not ok", entry.getStatusForTargetTime(t(10, 50)));
CoordinatePoint p5 = new CoordinatePoint(47.4, -122.4);
entry = entry.addRecord(blockInstance, record(t(16, 40), 14, 500, p5, 180.0, inProgress, "ok"), t(6, 40));
assertEquals(t(10, 00), entry.getFromTime());
assertEquals(t(16, 40), entry.getToTime());
assertEquals(20, entry.getScheduleDeviationForTargetTime(t(9, 10)), 0.0);
assertEquals(17, entry.getScheduleDeviationForTargetTime(t(13, 20)), 0.0);
assertEquals(14, entry.getScheduleDeviationForTargetTime(t(16, 40)), 0.0);
assertEquals(220, entry.getDistanceAlongBlockForTargetTime(t(10, 00)), 0.0);
assertEquals(360, entry.getDistanceAlongBlockForTargetTime(t(13, 20)), 0.0);
assertEquals(500, entry.getDistanceAlongBlockForTargetTime(t(16, 40)), 0.0);
assertEquals(640, entry.getDistanceAlongBlockForTargetTime(t(20, 00)), 0.0);
assertNull(entry.getLastLocationForTargetTime(t(6, 40)));
assertEquals(p4, entry.getLastLocationForTargetTime(t(10, 00)));
assertEquals(p4, entry.getLastLocationForTargetTime(t(13, 20)));
assertEquals(p5, entry.getLastLocationForTargetTime(t(16, 40)));
assertEquals(p5, entry.getLastLocationForTargetTime(t(20, 00)));
assertTrue(Double.isNaN(entry.getLastOrientationForTargetTime(t(6, 40))));
assertEquals(270.0, entry.getLastOrientationForTargetTime(t(10, 00)), 0.0);
assertEquals(270.0, entry.getLastOrientationForTargetTime(t(13, 20)), 0.0);
assertEquals(180.0, entry.getLastOrientationForTargetTime(t(16, 40)), 0.0);
assertEquals(180.0, entry.getLastOrientationForTargetTime(t(20, 00)), 0.0);
assertNull(entry.getPhaseForTargetTime(t(6, 40)));
assertEquals(layover, entry.getPhaseForTargetTime(t(10, 00)));
assertEquals(layover, entry.getPhaseForTargetTime(t(13, 20)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(16, 40)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(20, 00)));
assertNull(entry.getStatusForTargetTime(t(6, 40)));
assertEquals("not ok", entry.getStatusForTargetTime(t(10, 00)));
assertEquals("not ok", entry.getStatusForTargetTime(t(13, 20)));
assertEquals("ok", entry.getStatusForTargetTime(t(16, 40)));
assertEquals("ok", entry.getStatusForTargetTime(t(20, 00)));
}
use of org.onebusaway.geospatial.model.CoordinatePoint 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());
}
Aggregations