aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/reports
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/reports')
-rw-r--r--src/org/traccar/reports/ReportUtils.java14
-rw-r--r--src/org/traccar/reports/Summary.java11
2 files changed, 20 insertions, 5 deletions
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index 010c88b22..94cc7664f 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -263,10 +263,16 @@ public final class ReportUtils {
stop.setSpentFuel(calculateFuel(startStop, endStop));
long engineHours = 0;
- for (int i = startIndex + 1; i <= endIndex; i++) {
- if (positions.get(i).getBoolean(Position.KEY_IGNITION)
- && positions.get(i - 1).getBoolean(Position.KEY_IGNITION)) {
- engineHours += positions.get(i).getFixTime().getTime() - positions.get(i - 1).getFixTime().getTime();
+ if (startStop.getAttributes().containsKey(Position.KEY_HOURS)
+ && endStop.getAttributes().containsKey(Position.KEY_HOURS)) {
+ engineHours = endStop.getLong(Position.KEY_HOURS) - startStop.getLong(Position.KEY_HOURS);
+ } else if (Context.getConfig().getBoolean("engineHours.enable")) {
+ for (int i = startIndex + 1; i <= endIndex; i++) {
+ if (positions.get(i).getBoolean(Position.KEY_IGNITION)
+ && positions.get(i - 1).getBoolean(Position.KEY_IGNITION)) {
+ engineHours += positions.get(i).getFixTime().getTime()
+ - positions.get(i - 1).getFixTime().getTime();
+ }
}
}
stop.setEngineHours(engineHours);
diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java
index d789a0a9b..f57372e8d 100644
--- a/src/org/traccar/reports/Summary.java
+++ b/src/org/traccar/reports/Summary.java
@@ -44,11 +44,13 @@ public final class Summary {
Position firstPosition = null;
Position previousPosition = null;
double speedSum = 0;
+ boolean needCalculateEngineHours = Context.getConfig().getBoolean("engineHours.enable");
for (Position position : positions) {
if (firstPosition == null) {
firstPosition = position;
}
- if (previousPosition != null && position.getBoolean(Position.KEY_IGNITION)
+ if (needCalculateEngineHours && previousPosition != null
+ && position.getBoolean(Position.KEY_IGNITION)
&& previousPosition.getBoolean(Position.KEY_IGNITION)) {
result.addEngineHours(position.getFixTime().getTime()
- previousPosition.getFixTime().getTime());
@@ -63,6 +65,13 @@ public final class Summary {
result.setAverageSpeed(speedSum / positions.size());
result.setSpentFuel(ReportUtils.calculateFuel(firstPosition, previousPosition));
+ if (needCalculateEngineHours
+ && firstPosition.getAttributes().containsKey(Position.KEY_HOURS)
+ && previousPosition.getAttributes().containsKey(Position.KEY_HOURS)) {
+ result.setEngineHours(
+ previousPosition.getLong(Position.KEY_HOURS) - firstPosition.getLong(Position.KEY_HOURS));
+ }
+
if (!ignoreOdometer
&& firstPosition.getDouble(Position.KEY_ODOMETER) != 0
&& previousPosition.getDouble(Position.KEY_ODOMETER) != 0) {