aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-08-12 15:57:52 +0500
committerAbyss777 <abyss@fox5.ru>2016-08-12 15:57:52 +0500
commit89af2b67e7b7d3404204658f44d1fa48626ae6de (patch)
treeaf10918af92adee939575b02de675c4936c1c57d /src
parent1fd120a7fb74134a8ed7e12e685137f77a872567 (diff)
downloadtrackermap-server-89af2b67e7b7d3404204658f44d1fa48626ae6de.tar.gz
trackermap-server-89af2b67e7b7d3404204658f44d1fa48626ae6de.tar.bz2
trackermap-server-89af2b67e7b7d3404204658f44d1fa48626ae6de.zip
Calculate summary distance with help of "odometer" or "distance" attribute
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/reports/Summary.java17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java
index 68733ded6..870d3ea29 100644
--- a/src/org/traccar/reports/Summary.java
+++ b/src/org/traccar/reports/Summary.java
@@ -26,7 +26,6 @@ import javax.json.Json;
import javax.json.JsonArrayBuilder;
import org.traccar.Context;
-import org.traccar.helper.DistanceCalculator;
import org.traccar.model.Position;
import org.traccar.reports.model.SummaryReport;
import org.traccar.web.CsvBuilder;
@@ -43,12 +42,14 @@ public final class Summary {
result.setDeviceName(Context.getDeviceManager().getDeviceById(deviceId).getName());
Collection<Position> positions = Context.getDataManager().getPositions(deviceId, from, to);
if (positions != null && !positions.isEmpty()) {
+ Position firstPosition = null;
Position previousPosition = null;
double speedSum = 0;
for (Position position : positions) {
+ if (firstPosition == null) {
+ firstPosition = position;
+ }
if (previousPosition != null) {
- result.addDistance(DistanceCalculator.distance(previousPosition.getLatitude(),
- previousPosition.getLongitude(), position.getLatitude(), position.getLongitude()));
if (position.getAttributes().get(Position.KEY_IGNITION) != null
&& Boolean.parseBoolean(position.getAttributes().get(Position.KEY_IGNITION).toString())
&& previousPosition.getAttributes().get(Position.KEY_IGNITION) != null
@@ -62,6 +63,16 @@ public final class Summary {
speedSum += position.getSpeed();
result.setMaxSpeed(position.getSpeed());
}
+ if (firstPosition.getAttributes().containsKey(Position.KEY_ODOMETER)
+ && previousPosition.getAttributes().containsKey(Position.KEY_ODOMETER)) {
+ result.setDistance(((Double) previousPosition.getAttributes().get(Position.KEY_ODOMETER)
+ - (Double) firstPosition.getAttributes().get(Position.KEY_ODOMETER)) * 1000);
+ } else if (firstPosition.getAttributes().containsKey(Position.KEY_DISTANCE)
+ && previousPosition.getAttributes().containsKey(Position.KEY_DISTANCE)) {
+ result.setDistance((Double) previousPosition.getAttributes().get(Position.KEY_DISTANCE)
+ - (Double) firstPosition.getAttributes().get(Position.KEY_DISTANCE));
+ }
+
result.setAverageSpeed(speedSum / positions.size());
result.setDistance(new BigDecimal(result.getDistance()).setScale(2, RoundingMode.HALF_UP).doubleValue());
}