fleetmap-reports 2.0.119 → 2.0.121
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
package/src/kms-report.js
CHANGED
|
@@ -79,17 +79,19 @@ async function createKmsReportByDevice (from, to, userData, traccarInstance) {
|
|
|
79
79
|
const sliced = automaticReports.sliceArray(allDevices,
|
|
80
80
|
20)
|
|
81
81
|
for (const devices of sliced) {
|
|
82
|
-
const needRoute = !userData.allWeek
|
|
82
|
+
const needRoute = userData.groupByDay || !userData.allWeek
|
|
83
83
|
const {
|
|
84
84
|
trips,
|
|
85
|
-
route
|
|
86
|
-
|
|
85
|
+
route,
|
|
86
|
+
summary
|
|
87
|
+
} = await traccar.getAllInOne(traccarInstance, from, to, devices, needRoute, true, false, !userData.groupByDay, deviceCount, allDevices.length, 10, 2)
|
|
87
88
|
|
|
88
89
|
// Process report data
|
|
89
90
|
if (trips.length) {
|
|
90
91
|
allData.devices = allData.devices.concat(await processDevices(from, to, devices, {
|
|
91
92
|
trips,
|
|
92
|
-
route
|
|
93
|
+
route,
|
|
94
|
+
summary
|
|
93
95
|
}, userData, traccarInstance))
|
|
94
96
|
}
|
|
95
97
|
deviceCount += devices.length
|
|
@@ -228,7 +230,6 @@ async function processDevices (from, to, devices, data, userData, traccarInstanc
|
|
|
228
230
|
|
|
229
231
|
if (userData.groupByDay) {
|
|
230
232
|
if (trips.length > 0) {
|
|
231
|
-
const trips = deviceTrips.filter(t => userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
|
|
232
233
|
const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
|
|
233
234
|
const days = await Promise.all(dates.map(async date => {
|
|
234
235
|
const { tripsByDay } = await getDataByDay(d, date, { trips }, userData, traccarInstance)
|
|
@@ -246,13 +247,10 @@ async function processDevices (from, to, devices, data, userData, traccarInstanc
|
|
|
246
247
|
})
|
|
247
248
|
}
|
|
248
249
|
} else {
|
|
250
|
+
const summary = data.summary.find(s => s.deviceId === d.id)
|
|
249
251
|
devicesResult.push({
|
|
250
252
|
device: d,
|
|
251
|
-
summary
|
|
252
|
-
startOdometer: trips.length ? trips[0].startOdometer : 0,
|
|
253
|
-
endOdometer: trips.length ? trips[trips.length - 1].endOdometer : 0,
|
|
254
|
-
distance: getKms(trips)
|
|
255
|
-
}
|
|
253
|
+
summary
|
|
256
254
|
})
|
|
257
255
|
}
|
|
258
256
|
}
|
|
@@ -144,7 +144,7 @@ function getDeviceData (allInOne, d) {
|
|
|
144
144
|
const deviceStops = allInOne.stops.filter(t => t.deviceId === d.id)
|
|
145
145
|
|
|
146
146
|
const drivingTime = deviceTrips.reduce((a, b) => a + b.duration, 0)
|
|
147
|
-
const drivingConsumption = calculateConsumption(d, { trips: deviceTrips, stops: [], route: deviceRoute, summary: deviceSummary }
|
|
147
|
+
const drivingConsumption = calculateConsumption(d, { trips: deviceTrips, stops: [], route: deviceRoute, summary: deviceSummary })
|
|
148
148
|
const drivingDistance = deviceSummary ? deviceSummary.distance / 1000 : 0
|
|
149
149
|
const idleTime = deviceTrips.reduce((a, b) => a + (b.idleTime ? b.idleTime : 0), 0) + deviceStops.reduce((a, b) => a + b.engineHours, 0)
|
|
150
150
|
const idleConsumption = deviceSummary && deviceSummary.spentFuel > drivingConsumption ? deviceSummary.spentFuel - drivingConsumption : 0
|
package/src/util/fuel.js
CHANGED
|
@@ -25,13 +25,14 @@ function getRefuelingLiters (d, position, diff) {
|
|
|
25
25
|
return Math.round(diff * d.attributes.fuel_tank_capacity / 100)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function calculateConsumption (d, data
|
|
28
|
+
function calculateConsumption (d, data) {
|
|
29
29
|
let fuelConsumption = 0
|
|
30
30
|
const withFuelUsed = data.route && data.route.find(p => p.attributes.fuelUsed)
|
|
31
31
|
if (data.summary) {
|
|
32
32
|
fuelConsumption = calculateSpentFuel(data.summary.spentFuel, d, withFuelUsed)
|
|
33
|
-
}
|
|
34
|
-
|
|
33
|
+
}
|
|
34
|
+
if (fuelConsumption <= 0 && data.trips && data.stops) {
|
|
35
|
+
const spentFuel = data.trips.reduce((a, b) => a + (b.spentFuel > 0 ? b.spentFuel : 0), 0) + data.stops.reduce((a, b) => a + (b.spentFuel > 0 ? b.spentFuel : 0), 0)
|
|
35
36
|
fuelConsumption = calculateSpentFuel(spentFuel, d, withFuelUsed)
|
|
36
37
|
} else if (data.route && data.route.length > 1 && data.route[0].attributes.fuelUsed) {
|
|
37
38
|
fuelConsumption = data.route[data.route.length - 1].attributes.fuelUsed - data.route[0].attributes.fuelUsed
|