fleetmap-reports 2.0.77 → 2.0.78
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 +1 -1
- package/src/fuelconsumption-report.js +10 -10
- package/src/tests/fuel.test.js +2 -2
- package/src/tests/kms.test.js +4 -4
- package/src/util/trips.js +8 -1
- package/src/util/utils.js +2 -2
package/package.json
CHANGED
|
@@ -136,12 +136,12 @@ function exportFuelConsumptionReportToExcel (userData, reportData) {
|
|
|
136
136
|
return {
|
|
137
137
|
name: d.device.name,
|
|
138
138
|
date: r.date.toLocaleDateString(),
|
|
139
|
-
kms: formatNumber(r.distance / 1000
|
|
140
|
-
consumption: r.spentFuel > 0 ? formatNumber(r.spentFuel
|
|
141
|
-
avg_consumption: formatNumber(lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms
|
|
139
|
+
kms: formatNumber(r.distance / 1000),
|
|
140
|
+
consumption: r.spentFuel > 0 ? formatNumber(r.spentFuel) : 0,
|
|
141
|
+
avg_consumption: formatNumber(lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms),
|
|
142
142
|
duration: convertMS(r.duration),
|
|
143
|
-
accumulated_kms: formatNumber((r.endOdometer / 100)
|
|
144
|
-
refueling: formatNumber(r.refueling
|
|
143
|
+
accumulated_kms: formatNumber((r.endOdometer / 100)),
|
|
144
|
+
refueling: formatNumber(r.refueling)
|
|
145
145
|
}
|
|
146
146
|
}))
|
|
147
147
|
// Totals
|
|
@@ -203,12 +203,12 @@ async function exportFuelConsumptionReportToPDF (userData, reportData) {
|
|
|
203
203
|
d.days.forEach(r =>
|
|
204
204
|
data.push([
|
|
205
205
|
r.date.toLocaleDateString(),
|
|
206
|
-
formatNumber(r.distance / 1000
|
|
207
|
-
r.spentFuel > 0 ? formatNumber(r.spentFuel
|
|
208
|
-
formatNumber(lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms
|
|
206
|
+
formatNumber(r.distance / 1000),
|
|
207
|
+
r.spentFuel > 0 ? formatNumber(r.spentFuel) : 0,
|
|
208
|
+
formatNumber(lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms),
|
|
209
209
|
convertMS(r.duration),
|
|
210
|
-
formatNumber((r.endOdometer / 1000)
|
|
211
|
-
formatNumber(r.refueling
|
|
210
|
+
formatNumber((r.endOdometer / 1000)),
|
|
211
|
+
formatNumber(r.refueling)
|
|
212
212
|
]))
|
|
213
213
|
|
|
214
214
|
const footValues = [
|
package/src/tests/fuel.test.js
CHANGED
|
@@ -20,8 +20,8 @@ describe('Test_Reports', function () {
|
|
|
20
20
|
}, 30000)
|
|
21
21
|
|
|
22
22
|
it('Fuel Consumption 1', async () => {
|
|
23
|
-
console.log('
|
|
24
|
-
const report = await getReports(
|
|
23
|
+
console.log('Fuel Consumption')
|
|
24
|
+
const report = await getReports(process.env.email, process.env.password)
|
|
25
25
|
const userData = await report.getUserData()
|
|
26
26
|
userData.devices = userData.devices.filter(d => d.id === 133608)
|
|
27
27
|
|
package/src/tests/kms.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-undef */
|
|
2
2
|
const { getReports } = require('./index')
|
|
3
3
|
const assert = require('assert')
|
|
4
|
-
const {
|
|
4
|
+
const { convertFromLocal } = require('../util/utils')
|
|
5
5
|
|
|
6
6
|
describe('Kms_Reports', function () {
|
|
7
7
|
// eslint-disable-next-line no-undef
|
|
@@ -65,10 +65,10 @@ describe('Kms_Reports', function () {
|
|
|
65
65
|
it('KmsReport by timezone marrocos', async () => {
|
|
66
66
|
const reports = await getReports(process.env.email, process.env.password)
|
|
67
67
|
const userData = await reports.getUserData()
|
|
68
|
-
userData.
|
|
69
|
-
const data = await reports.kmsReport(convertFromLocal(new Date(2024,
|
|
68
|
+
userData.devices = userData.devices.filter(d => d.id === 93497)
|
|
69
|
+
const data = await reports.kmsReport(convertFromLocal(new Date(2024, 2, 18, 0, 0, 0), userData.user.attributes.timezone), convertFromLocal(new Date(2024, 2, 18, 23, 59, 59), userData.user.attributes.timezone),
|
|
70
70
|
userData)
|
|
71
|
-
const device = data[0].devices.find(d => d.device.id ===
|
|
71
|
+
const device = data[0].devices.find(d => d.device.id === 93497)
|
|
72
72
|
assert.equal(device, 1)
|
|
73
73
|
}, 3000000)
|
|
74
74
|
})
|
package/src/util/trips.js
CHANGED
|
@@ -138,8 +138,15 @@ async function getDataByDay (device, date, data, userData, traccarInstance) {
|
|
|
138
138
|
return { tripsByDay, routeByDay, refuelingPositionsByDay, zoneInOutDayData }
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
function isValidAvgSpeed (kms, startTime, endTime) {
|
|
142
|
+
const totalTime = new Date(endTime).getTime() - new Date(startTime).getTime()
|
|
143
|
+
const avgSpeed = (kms / 1000) / (totalTime / (1000 * 60 * 60))
|
|
144
|
+
return avgSpeed < 200
|
|
145
|
+
}
|
|
146
|
+
|
|
141
147
|
function getKms (trips) {
|
|
142
|
-
|
|
148
|
+
const odometerKms = trips.length > 0 ? trips[trips.length - 1].endOdometer - trips[0].startOdometer : 0
|
|
149
|
+
return odometerKms > 0 && isValidAvgSpeed(odometerKms, trips[0].startTime, trips[trips.length - 1].endTime) ? odometerKms : trips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0)
|
|
143
150
|
}
|
|
144
151
|
|
|
145
152
|
function isInsideTimetable (t, userData) {
|
package/src/util/utils.js
CHANGED
|
@@ -41,8 +41,8 @@ function convertMS (duration, withSeconds) {
|
|
|
41
41
|
return withSeconds ? hours + ':' + minutes + ':' + seconds : hours + ':' + minutes
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
exports.formatNumber = function formatNumber (value
|
|
45
|
-
return
|
|
44
|
+
exports.formatNumber = function formatNumber (value) {
|
|
45
|
+
return Number(value.toFixed(1))
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function coordsDistance (lon1, lat1, lon2, lat2) {
|