aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/reports
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-09-21 17:53:50 -0700
committerAnton Tananaev <anton@traccar.org>2022-09-21 17:53:58 -0700
commit388799edf2adc9c3070a83e72f074e523629574f (patch)
tree35809a83791475cece4f053457cafddc9d226b71 /src/main/java/org/traccar/reports
parentd5b1385596f79da2514ea7cccf27e9bdeebcacae (diff)
downloadtrackermap-server-388799edf2adc9c3070a83e72f074e523629574f.tar.gz
trackermap-server-388799edf2adc9c3070a83e72f074e523629574f.tar.bz2
trackermap-server-388799edf2adc9c3070a83e72f074e523629574f.zip
Refactor motion handling
Diffstat (limited to 'src/main/java/org/traccar/reports')
-rw-r--r--src/main/java/org/traccar/reports/common/ReportUtils.java53
1 files changed, 26 insertions, 27 deletions
diff --git a/src/main/java/org/traccar/reports/common/ReportUtils.java b/src/main/java/org/traccar/reports/common/ReportUtils.java
index 7fff46f66..2bca00df7 100644
--- a/src/main/java/org/traccar/reports/common/ReportUtils.java
+++ b/src/main/java/org/traccar/reports/common/ReportUtils.java
@@ -37,7 +37,6 @@ import org.traccar.helper.model.UserUtil;
import org.traccar.model.BaseModel;
import org.traccar.model.Device;
import org.traccar.model.Driver;
-import org.traccar.model.Event;
import org.traccar.model.Group;
import org.traccar.model.Position;
import org.traccar.model.User;
@@ -65,7 +64,6 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -353,38 +351,39 @@ public class ReportUtils {
if (!positions.isEmpty()) {
boolean trips = reportClass.equals(TripReportItem.class);
MotionEventHandler motionHandler = new MotionEventHandler(null, null, tripsConfig);
+
DeviceState deviceState = new DeviceState();
deviceState.setMotionState(isMoving(positions, 0, tripsConfig));
- int startEventIndex = trips == deviceState.getMotionState() ? 0 : -1;
+
+ boolean detected = trips == deviceState.getMotionState();
+ int startEventIndex = detected ? 0 : -1;
int startNoEventIndex = -1;
for (int i = 0; i < positions.size(); i++) {
- Map<Event, Position> event = motionHandler.updateMotionState(deviceState, positions.get(i),
- isMoving(positions, i, tripsConfig));
- if (startEventIndex == -1
- && (trips != deviceState.getMotionState() && deviceState.getMotionPosition() != null
- || trips == deviceState.getMotionState() && event != null)) {
- startEventIndex = i;
- startNoEventIndex = -1;
- } else if (trips != deviceState.getMotionState() && startEventIndex != -1
- && deviceState.getMotionPosition() == null && event == null) {
- startEventIndex = -1;
+ boolean motion = isMoving(positions, i, tripsConfig);
+ if (deviceState.getMotionState() != motion) {
+ if (motion == trips) {
+ startEventIndex = detected ? startEventIndex : i;
+ startNoEventIndex = -1;
+ } else {
+ startNoEventIndex = i;
+ }
}
- if (startNoEventIndex == -1
- && (trips == deviceState.getMotionState() && deviceState.getMotionPosition() != null
- || trips != deviceState.getMotionState() && event != null)) {
- startNoEventIndex = i;
- } else if (startNoEventIndex != -1 && deviceState.getMotionPosition() == null && event == null) {
- startNoEventIndex = -1;
- }
- if (startEventIndex != -1 && startNoEventIndex != -1 && event != null
- && trips != deviceState.getMotionState()) {
- result.add(calculateTripOrStop(
- device, positions, startEventIndex, startNoEventIndex, ignoreOdometer, reportClass));
- startEventIndex = -1;
+
+ if (motionHandler.updateMotionState(deviceState, positions.get(i), motion) != null) {
+ if (motion == trips) {
+ detected = true;
+ startNoEventIndex = -1;
+ } else if (startEventIndex >= 0 && startNoEventIndex >= 0) {
+ result.add(calculateTripOrStop(
+ device, positions, startEventIndex, startNoEventIndex, ignoreOdometer, reportClass));
+ detected = false;
+ startEventIndex = -1;
+ startNoEventIndex = -1;
+ }
}
}
- if (startEventIndex != -1 && (startNoEventIndex != -1 || !trips)) {
- int endIndex = startNoEventIndex != -1 ? startNoEventIndex : positions.size() - 1;
+ if (startEventIndex >= 0 && startEventIndex < positions.size() - 1) {
+ int endIndex = startNoEventIndex >= 0 ? startNoEventIndex : positions.size() - 1;
result.add(calculateTripOrStop(
device, positions, startEventIndex, endIndex, ignoreOdometer, reportClass));
}