fleetmap-reports 1.0.769 → 1.0.771
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -55,6 +55,12 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
|
55
55
|
new Map()
|
|
56
56
|
)
|
|
57
57
|
|
|
58
|
+
route.forEach(p => { p.startDate = p.fixTime.substring(0, 10) })
|
|
59
|
+
const groupedRouteByDay = route.reduce(
|
|
60
|
+
(entryMap, e) => entryMap.set(e.startDate, [...entryMap.get(e.startDate) || [], e]),
|
|
61
|
+
new Map()
|
|
62
|
+
)
|
|
63
|
+
|
|
58
64
|
const days = []
|
|
59
65
|
const keys = Array.from(groupedTripsByDay.keys())
|
|
60
66
|
|
|
@@ -63,7 +69,7 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
|
63
69
|
const dayTrips = groupedTripsByDay.get(day)
|
|
64
70
|
const dayRefueling = groupedRefuelingsByDay.get(day)
|
|
65
71
|
const distance = dayTrips.reduce((a, b) => a + b.distance, 0)
|
|
66
|
-
const spentFuel = calculateConsumption(userData, d, day, odooAvgConsumption, { trips: dayTrips, route })
|
|
72
|
+
const spentFuel = calculateConsumption(userData, d, day, odooAvgConsumption, { trips: dayTrips, route: groupedRouteByDay.get(day) })
|
|
67
73
|
|
|
68
74
|
const dataRow = {
|
|
69
75
|
date: day,
|
|
@@ -124,6 +130,11 @@ function calculateConsumption (userData, d, day, avgConsumption, data) {
|
|
|
124
130
|
if (useOdooFuelData(d, data.route)) {
|
|
125
131
|
return (avgConsumption.byKms * (data.trips.reduce((a, b) => a + b.distance, 0) / 1000) / 100)
|
|
126
132
|
}
|
|
133
|
+
|
|
134
|
+
if (data.route.length > 1 && data.route[0].attributes.fuelUsed) {
|
|
135
|
+
return data.route[data.route.length - 1].attributes.fuelUsed - data.route[0].attributes.fuelUsed
|
|
136
|
+
}
|
|
137
|
+
|
|
127
138
|
return automaticReports.calculateSpentFuel(data.trips.reduce((a, b) => a + b.spentFuel, 0), d)
|
|
128
139
|
}
|
|
129
140
|
|
|
@@ -145,8 +145,11 @@ function getDeviceData (allInOne, d) {
|
|
|
145
145
|
economicDistance
|
|
146
146
|
}
|
|
147
147
|
} else {
|
|
148
|
+
const drivingTime = deviceTrips.reduce((a, b) => a + b.duration, 0)
|
|
149
|
+
const drivingDistance = deviceTrips.reduce((a, b) => a + b.distance, 0)
|
|
150
|
+
|
|
148
151
|
return {
|
|
149
|
-
drivingTime:
|
|
152
|
+
drivingTime: drivingTime,
|
|
150
153
|
idleTime: 0,
|
|
151
154
|
cruiseControlTime: 0,
|
|
152
155
|
economicTime: 0,
|
|
@@ -157,7 +160,7 @@ function getDeviceData (allInOne, d) {
|
|
|
157
160
|
idleConsumption: 0,
|
|
158
161
|
cruiseControlConsumption: 0,
|
|
159
162
|
economicConsumption: 0,
|
|
160
|
-
drivingDistance:
|
|
163
|
+
drivingDistance: drivingDistance,
|
|
161
164
|
cruiseControlDistance: 0,
|
|
162
165
|
economicDistance: 0
|
|
163
166
|
}
|
package/src/tests/index.test.js
CHANGED
|
@@ -194,8 +194,7 @@ describe('Test_Reports', function () {
|
|
|
194
194
|
userData)
|
|
195
195
|
assert.equal(data.length, 1)
|
|
196
196
|
const device = data[0].devices.find(d => d.device.id === 69114)
|
|
197
|
-
|
|
198
|
-
assert.equal(device.days.reduce((a, b) => a + b.spentFuel, 0), 153.7)
|
|
197
|
+
assert.equal(device.days.reduce((a, b) => a + b.spentFuel, 0), 168.91999999999985)
|
|
199
198
|
}, 30000)
|
|
200
199
|
// eslint-disable-next-line no-undef
|
|
201
200
|
it('Zone Report', async () => {
|
package/src/tests/trips.test.js
CHANGED
|
@@ -135,6 +135,6 @@ describe('trips', function () {
|
|
|
135
135
|
|
|
136
136
|
assert.equal(data.length, 1)
|
|
137
137
|
const device = data[0].devices.find(d => d.device.id === 69114)
|
|
138
|
-
assert.equal(device.trips.reduce((a, b) => a + b.
|
|
138
|
+
assert.equal(device.trips.reduce((a, b) => a + b.fuelConsumption, 0), 167.69999999999987) // Total Trips
|
|
139
139
|
}, 30000)
|
|
140
140
|
})
|
package/src/trip-report.js
CHANGED
|
@@ -167,14 +167,14 @@ function processDevices (from, to, devices, data, userData, traccar) {
|
|
|
167
167
|
trip.endPOIName = nearestPOIs[0].p.name
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
const stop = getStop(new Date(trip.startTime), stops)
|
|
171
|
+
|
|
170
172
|
if ((deviceRoute[0].protocol === 'teltonika' && deviceRoute.some(r => r.attributes.fuel)) ||
|
|
171
173
|
automaticReports.deviceWithFuelInfo(d)) {
|
|
172
|
-
trip.fuelConsumption = trip.spentFuel
|
|
174
|
+
trip.fuelConsumption = trip.spentFuel + (stop ? stop.spentFuel : 0)
|
|
173
175
|
trip.avgFuelConsumption = trip.totalKms > 0 ? trip.fuelConsumption * 100 / trip.totalKms : 0
|
|
174
176
|
}
|
|
175
177
|
|
|
176
|
-
const stop = getStop(new Date(trip.startTime), stops)
|
|
177
|
-
|
|
178
178
|
if (stop && !trip.endTimeIsOut) {
|
|
179
179
|
trip.stopDuration = calculateStopDuration(stop)
|
|
180
180
|
trip.stopEngineHours = trip.idleTime + stop.engineHours
|