Search in sources :

Example 71 with Position

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());
}
Also used : Position(org.traccar.model.Position) TripsConfig(org.traccar.reports.model.TripsConfig) StopReport(org.traccar.reports.model.StopReport) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Example 72 with Position

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);
}
Also used : Position(org.traccar.model.Position) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Example 73 with Position

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());
}
Also used : Position(org.traccar.model.Position) TripsConfig(org.traccar.reports.model.TripsConfig) StopReport(org.traccar.reports.model.StopReport) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Example 74 with Position

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());
}
Also used : Position(org.traccar.model.Position) TripsConfig(org.traccar.reports.model.TripsConfig) StopReport(org.traccar.reports.model.StopReport) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Example 75 with Position

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;
}
Also used : Position(org.traccar.model.Position)

Aggregations

Position (org.traccar.model.Position)831 DeviceSession (org.traccar.DeviceSession)505 Parser (org.traccar.helper.Parser)319 DateBuilder (org.traccar.helper.DateBuilder)179 Date (java.util.Date)154 Network (org.traccar.model.Network)143 LinkedList (java.util.LinkedList)112 ByteBuf (io.netty.buffer.ByteBuf)105 Event (org.traccar.model.Event)75 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)69 NetworkMessage (org.traccar.NetworkMessage)67 Test (org.junit.Test)56 WifiAccessPoint (org.traccar.model.WifiAccessPoint)54 BaseTest (org.traccar.BaseTest)40 SimpleDateFormat (java.text.SimpleDateFormat)38 Device (org.traccar.model.Device)29 DateFormat (java.text.DateFormat)27 DeviceState (org.traccar.model.DeviceState)27 List (java.util.List)25 TripsConfig (org.traccar.reports.model.TripsConfig)25