use of org.traccar.model.Position in project traccar by traccar.
the class ReportUtilsTest method testDetectStopsStartedFromTrip.
@Test
public void testDetectStopsStartedFromTrip() throws ParseException {
Collection<Position> data = Arrays.asList(position("2016-01-01 00:00:00.000", 2, 0), position("2016-01-01 00:01:00.000", 1, 0), position("2016-01-01 00:02:00.000", 0, 0), position("2016-01-01 00:03:00.000", 0, 0), position("2016-01-01 00:04:00.000", 0, 0), position("2016-01-01 00:05:00.000", 0, 0));
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false, false, 0.01);
Collection<StopReport> result = ReportUtils.detectTripsAndStops(data, tripsConfig, false, StopReport.class);
assertNotNull(result);
assertFalse(result.isEmpty());
StopReport itemStop = result.iterator().next();
assertEquals(date("2016-01-01 00:02:00.000"), itemStop.getStartTime());
assertEquals(date("2016-01-01 00:05:00.000"), itemStop.getEndTime());
assertEquals(180000, itemStop.getDuration());
}
use of org.traccar.model.Position in project traccar by traccar.
the class ReportUtilsTest method testCalculateSpentFuel.
@Test
public void testCalculateSpentFuel() {
Position startPosition = new Position();
Position endPosition = new Position();
assertEquals(ReportUtils.calculateFuel(startPosition, endPosition), 0.0, 0.01);
startPosition.set(Position.KEY_FUEL_LEVEL, 0.7);
endPosition.set(Position.KEY_FUEL_LEVEL, 0.5);
assertEquals(ReportUtils.calculateFuel(startPosition, endPosition), 0.2, 0.01);
}
use of org.traccar.model.Position in project traccar by traccar.
the class ReportUtilsTest method testDetectStopsOnly.
@Test
public void testDetectStopsOnly() throws ParseException {
Collection<Position> data = Arrays.asList(position("2016-01-01 00:00:00.000", 0, 0), position("2016-01-01 00:01:00.000", 0, 0), position("2016-01-01 00:02:00.000", 1, 0), position("2016-01-01 00:03:00.000", 0, 0), position("2016-01-01 00:04:00.000", 1, 0), position("2016-01-01 00:05:00.000", 0, 0));
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false, false, 0.01);
Collection<StopReport> result = ReportUtils.detectTripsAndStops(data, tripsConfig, false, StopReport.class);
assertNotNull(result);
assertFalse(result.isEmpty());
StopReport itemStop = result.iterator().next();
assertEquals(date("2016-01-01 00:00:00.000"), itemStop.getStartTime());
assertEquals(date("2016-01-01 00:05:00.000"), itemStop.getEndTime());
assertEquals(300000, itemStop.getDuration());
}
use of org.traccar.model.Position in project traccar by traccar.
the class ReportUtilsTest method testDetectStopsMoving.
@Test
public void testDetectStopsMoving() throws ParseException {
Collection<Position> data = Arrays.asList(position("2016-01-01 00:00:00.000", 5, 0), position("2016-01-01 00:01:00.000", 5, 0), position("2016-01-01 00:02:00.000", 3, 0), position("2016-01-01 00:03:00.000", 5, 0), position("2016-01-01 00:04:00.000", 5, 0), position("2016-01-01 00:05:00.000", 5, 0));
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false, false, 0.01);
Collection<StopReport> result = ReportUtils.detectTripsAndStops(data, tripsConfig, false, StopReport.class);
assertNotNull(result);
assertTrue(result.isEmpty());
}
use of org.traccar.model.Position in project traccar by traccar.
the class DistanceHandler method handlePosition.
@Override
protected Position handlePosition(Position position) {
double distance = 0.0;
if (position.getAttributes().containsKey(Position.KEY_DISTANCE)) {
distance = position.getDouble(Position.KEY_DISTANCE);
}
double totalDistance = 0.0;
Position last = getLastPosition(position.getDeviceId());
if (last != null) {
totalDistance = last.getDouble(Position.KEY_TOTAL_DISTANCE);
if (!position.getAttributes().containsKey(Position.KEY_DISTANCE)) {
distance = DistanceCalculator.distance(position.getLatitude(), position.getLongitude(), last.getLatitude(), last.getLongitude());
distance = BigDecimal.valueOf(distance).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
}
if (filter && last.getValid() && last.getLatitude() != 0 && last.getLongitude() != 0) {
boolean satisfiesMin = coordinatesMinError == 0 || distance > coordinatesMinError;
boolean satisfiesMax = coordinatesMaxError == 0 || distance < coordinatesMaxError || position.getValid();
if (!satisfiesMin || !satisfiesMax) {
position.setLatitude(last.getLatitude());
position.setLongitude(last.getLongitude());
distance = 0;
}
}
}
position.set(Position.KEY_DISTANCE, distance);
totalDistance = BigDecimal.valueOf(totalDistance + distance).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
position.set(Position.KEY_TOTAL_DISTANCE, totalDistance);
return position;
}
Aggregations