Skip to content

Commit 136a302

Browse files
committed
Add spent fuel to summary report
1 parent 57941c8 commit 136a302

File tree

7 files changed

+63
-20
lines changed

7 files changed

+63
-20
lines changed

src/org/traccar/reports/ReportUtils.java

+5-17
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,12 @@ public static String calculateFuel(Position firstPosition, Position lastPosition
9090

9191
if (firstPosition.getAttributes().get(Position.KEY_FUEL_LEVEL) != null
9292
&& lastPosition.getAttributes().get(Position.KEY_FUEL_LEVEL) != null) {
93-
try {
94-
switch (firstPosition.getProtocol()) {
95-
case "meitrack":
96-
case "galileo":
97-
case "noran":
98-
BigDecimal v = new BigDecimal(
99-
firstPosition.getAttributes().get(Position.KEY_FUEL_LEVEL).toString());
100-
v = v.subtract(new BigDecimal(
101-
lastPosition.getAttributes().get(Position.KEY_FUEL_LEVEL).toString()));
102-
return v.setScale(2, RoundingMode.HALF_EVEN).toString() + " %";
103-
default:
104-
break;
105-
}
106-
} catch (Exception error) {
107-
Log.warning(error);
108-
}
93+
94+
BigDecimal value = new BigDecimal(firstPosition.getDouble(Position.KEY_FUEL_LEVEL)
95+
- lastPosition.getDouble(Position.KEY_FUEL_LEVEL));
96+
return value.setScale(1, RoundingMode.HALF_EVEN).toString();
10997
}
110-
return "-";
98+
return null;
11199
}
112100

113101
public static org.jxls.common.Context initializeContext(long userId) {

src/org/traccar/reports/Summary.java

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private static SummaryReport calculateSummaryResult(long deviceId, Date from, Da
6161
.lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true);
6262
result.setDistance(ReportUtils.calculateDistance(firstPosition, previousPosition, !ignoreOdometer));
6363
result.setAverageSpeed(speedSum / positions.size());
64+
result.setSpentFuel(ReportUtils.calculateFuel(firstPosition, previousPosition));
6465
}
6566
return result;
6667
}

src/org/traccar/reports/model/BaseReport.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,31 @@
1919
public class BaseReport {
2020

2121
private long deviceId;
22+
2223
public long getDeviceId() {
2324
return deviceId;
2425
}
26+
2527
public void setDeviceId(long deviceId) {
2628
this.deviceId = deviceId;
2729
}
2830

2931
private String deviceName;
32+
3033
public String getDeviceName() {
3134
return deviceName;
3235
}
36+
3337
public void setDeviceName(String deviceName) {
3438
this.deviceName = deviceName;
3539
}
3640

37-
private double distance; // meters
41+
private double distance;
42+
3843
public double getDistance() {
3944
return distance;
4045
}
46+
4147
public void setDistance(double distance) {
4248
this.distance = distance;
4349
}
@@ -46,18 +52,22 @@ public void addDistance(double distance) {
4652
this.distance += distance;
4753
}
4854

49-
private double averageSpeed; // knots
55+
private double averageSpeed;
56+
5057
public double getAverageSpeed() {
5158
return averageSpeed;
5259
}
60+
5361
public void setAverageSpeed(Double averageSpeed) {
5462
this.averageSpeed = averageSpeed;
5563
}
5664

57-
private double maxSpeed; // knots
65+
private double maxSpeed;
66+
5867
public double getMaxSpeed() {
5968
return maxSpeed;
6069
}
70+
6171
public void setMaxSpeed(double maxSpeed) {
6272
if (maxSpeed > this.maxSpeed) {
6373
this.maxSpeed = maxSpeed;

src/org/traccar/reports/model/DeviceReport.java

+6
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,31 @@
2323
public class DeviceReport {
2424

2525
private String deviceName;
26+
2627
public String getDeviceName() {
2728
return deviceName;
2829
}
30+
2931
public void setDeviceName(String deviceName) {
3032
this.deviceName = deviceName;
3133
}
3234

3335
private String groupName = "";
36+
3437
public String getGroupName() {
3538
return groupName;
3639
}
40+
3741
public void setGroupName(String groupName) {
3842
this.groupName = groupName;
3943
}
4044

4145
private List<?> objects;
46+
4247
public Collection<?> getObjects() {
4348
return objects;
4449
}
50+
4551
public void setObjects(Collection<?> objects) {
4652
this.objects = new ArrayList<>(objects);
4753
}

src/org/traccar/reports/model/SummaryReport.java

+14
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,27 @@
1919
public class SummaryReport extends BaseReport {
2020

2121
private long engineHours; // milliseconds
22+
2223
public long getEngineHours() {
2324
return engineHours;
2425
}
26+
2527
public void setEngineHours(long engineHours) {
2628
this.engineHours = engineHours;
2729
}
30+
2831
public void addEngineHours(long engineHours) {
2932
this.engineHours += engineHours;
3033
}
34+
35+
private String spentFuel;
36+
37+
public String getSpentFuel() {
38+
return spentFuel;
39+
}
40+
41+
public void setSpentFuel(String spentFuel) {
42+
this.spentFuel = spentFuel;
43+
}
44+
3145
}

src/org/traccar/reports/model/TripReport.java

+24
Original file line numberDiff line numberDiff line change
@@ -21,61 +21,75 @@
2121
public class TripReport extends BaseReport {
2222

2323
private long startPositionId;
24+
2425
public long getStartPositionId() {
2526
return startPositionId;
2627
}
28+
2729
public void setStartPositionId(long startPositionId) {
2830
this.startPositionId = startPositionId;
2931
}
3032

3133
private long endPositionId;
34+
3235
public long getEndPositionId() {
3336
return endPositionId;
3437
}
38+
3539
public void setEndPositionId(long endPositionId) {
3640
this.endPositionId = endPositionId;
3741
}
3842

3943
private double startLat;
44+
4045
public double getStartLat() {
4146
return startLat;
4247
}
48+
4349
public void setStartLat(double startLat) {
4450
this.startLat = startLat;
4551
}
4652

4753
private double startLon;
54+
4855
public double getStartLon() {
4956
return startLon;
5057
}
58+
5159
public void setStartLon(double startLon) {
5260
this.startLon = startLon;
5361
}
5462

5563
private double endLat;
64+
5665
public double getEndLat() {
5766
return endLat;
5867
}
68+
5969
public void setEndLat(double endLat) {
6070
this.endLat = endLat;
6171
}
6272

6373
private double endLon;
74+
6475
public double getEndLon() {
6576
return endLon;
6677
}
78+
6779
public void setEndLon(double endLon) {
6880
this.endLon = endLon;
6981
}
7082

7183
private Date startTime;
84+
7285
public Date getStartTime() {
7386
if (startTime != null) {
7487
return new Date(startTime.getTime());
7588
} else {
7689
return null;
7790
}
7891
}
92+
7993
public void setStartTime(Date startTime) {
8094
if (startTime != null) {
8195
this.startTime = new Date(startTime.getTime());
@@ -85,21 +99,25 @@ public void setStartTime(Date startTime) {
8599
}
86100

87101
private String startAddress;
102+
88103
public String getStartAddress() {
89104
return startAddress;
90105
}
106+
91107
public void setStartAddress(String address) {
92108
this.startAddress = address;
93109
}
94110

95111
private Date endTime;
112+
96113
public Date getEndTime() {
97114
if (endTime != null) {
98115
return new Date(endTime.getTime());
99116
} else {
100117
return null;
101118
}
102119
}
120+
103121
public void setEndTime(Date endTime) {
104122
if (endTime != null) {
105123
this.endTime = new Date(endTime.getTime());
@@ -109,25 +127,31 @@ public void setEndTime(Date endTime) {
109127
}
110128

111129
private String endAddress;
130+
112131
public String getEndAddress() {
113132
return endAddress;
114133
}
134+
115135
public void setEndAddress(String address) {
116136
this.endAddress = address;
117137
}
118138

119139
private long duration;
140+
120141
public long getDuration() {
121142
return duration;
122143
}
144+
123145
public void setDuration(long duration) {
124146
this.duration = duration;
125147
}
126148

127149
private String spentFuel;
150+
128151
public String getSpentFuel() {
129152
return spentFuel;
130153
}
154+
131155
public void setSpentFuel(String spentFuel) {
132156
this.spentFuel = spentFuel;
133157
}

templates/export/summary.xlsx

-3.53 KB
Binary file not shown.

0 commit comments

Comments
 (0)