diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-08-20 13:13:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-20 13:13:09 +0300 |
commit | 6c6b62351aadd68928b9bd3e39e2bf96d78695e8 (patch) | |
tree | 8d9f5617aada94e3c8784c0bee6a201fbced54b3 /src/org/traccar/reports/ReportUtils.java | |
parent | 6b6d28695600fee509ee37a7225dd6518879ac9c (diff) | |
parent | 804c56a76dc8406e4ff072289a4a9f97322dfe83 (diff) | |
download | trackermap-server-6c6b62351aadd68928b9bd3e39e2bf96d78695e8.tar.gz trackermap-server-6c6b62351aadd68928b9bd3e39e2bf96d78695e8.tar.bz2 trackermap-server-6c6b62351aadd68928b9bd3e39e2bf96d78695e8.zip |
Merge pull request #2228 from Abyss777/reports_trips
Implement trips reports
Diffstat (limited to 'src/org/traccar/reports/ReportUtils.java')
-rw-r--r-- | src/org/traccar/reports/ReportUtils.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java index 9f6d34860..34f04ac87 100644 --- a/src/org/traccar/reports/ReportUtils.java +++ b/src/org/traccar/reports/ReportUtils.java @@ -16,10 +16,14 @@ */ package org.traccar.reports; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.ArrayList; import java.util.Collection; import org.traccar.Context; +import org.traccar.helper.Log; +import org.traccar.model.Position; public final class ReportUtils { @@ -35,4 +39,45 @@ public final class ReportUtils { return result; } + public static double calculateDistance(Position firstPosition, Position lastPosition) { + return calculateDistance(firstPosition, lastPosition, true); + } + + public static double calculateDistance(Position firstPosition, Position lastPosition, boolean useOdometer) { + double distance = 0.0; + if (useOdometer && firstPosition.getAttributes().containsKey(Position.KEY_ODOMETER) + && lastPosition.getAttributes().containsKey(Position.KEY_ODOMETER)) { + distance = (((Number) lastPosition.getAttributes().get(Position.KEY_ODOMETER)).doubleValue() + - ((Number) firstPosition.getAttributes().get(Position.KEY_ODOMETER)).doubleValue()) + * 1000; + } else if (firstPosition.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE) + && lastPosition.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE)) { + distance = ((Number) lastPosition.getAttributes().get(Position.KEY_TOTAL_DISTANCE)).doubleValue() + - ((Number) firstPosition.getAttributes().get(Position.KEY_TOTAL_DISTANCE)).doubleValue(); + } + return distance; + } + + public static String calculateFuel(Position firstPosition, Position lastPosition) { + + if (firstPosition.getAttributes().get(Position.KEY_FUEL) != null + && lastPosition.getAttributes().get(Position.KEY_FUEL) != null) { + try { + switch (firstPosition.getProtocol()) { + case "meitrack": + case "galileo": + case "noran": + return new BigDecimal(firstPosition.getAttributes().get(Position.KEY_FUEL).toString()) + .subtract(new BigDecimal(lastPosition.getAttributes().get(Position.KEY_FUEL).toString())) + .setScale(2, RoundingMode.HALF_EVEN).toString() + " %"; + default: + break; + } + } catch (Exception error) { + Log.warning(error); + } + } + return "-"; + } + } |