fleetmap-reports 1.0.686 → 1.0.688
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/fueldrop-report.js +10 -20
- package/src/tests/fuel.test.js +1 -0
- package/src/util/traccar.js +1 -1
package/package.json
CHANGED
package/src/fueldrop-report.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const automaticReports = require('./automaticReports')
|
|
2
2
|
const { devicesToProcess } = require('./util/device')
|
|
3
3
|
const { getTranslations } = require('./util/utils')
|
|
4
|
+
const traccarHelper = require('./util/traccar')
|
|
4
5
|
|
|
5
6
|
function calculateFuelDrop (position, positions) {
|
|
6
7
|
const index = positions.indexOf(position)
|
|
@@ -21,48 +22,43 @@ function calculateFuelDrop (position, positions) {
|
|
|
21
22
|
async function createFuelDropReport (from, to, userData, traccar) {
|
|
22
23
|
console.log('Create FuelDropReport')
|
|
23
24
|
|
|
24
|
-
const reportData = []
|
|
25
|
-
|
|
26
25
|
const allData = {
|
|
27
26
|
devices: [],
|
|
28
27
|
from,
|
|
29
28
|
to
|
|
30
29
|
}
|
|
31
30
|
|
|
31
|
+
const reportData = []
|
|
32
|
+
reportData.push(allData)
|
|
33
|
+
|
|
32
34
|
const devices = devicesToProcess(userData)
|
|
33
35
|
|
|
34
|
-
const arrayOfArrays = automaticReports.sliceArray(devices)
|
|
36
|
+
const arrayOfArrays = automaticReports.sliceArray(devices, 50)
|
|
35
37
|
let data = []
|
|
36
|
-
const types = ['deviceFuelDrop']
|
|
37
38
|
|
|
39
|
+
const types = ['deviceFuelDrop']
|
|
38
40
|
for (const a of arrayOfArrays) {
|
|
39
41
|
const response = await traccar.reports.reportsEventsGet(from, to, a.map(d => d.id), null, types)
|
|
40
42
|
data = data.concat(response.data)
|
|
41
43
|
}
|
|
42
|
-
|
|
43
44
|
console.log('FuelDrop Alerts:' + data.length)
|
|
44
|
-
|
|
45
|
-
if (data.length === 0) {
|
|
46
|
-
return reportData
|
|
47
|
-
}
|
|
48
45
|
allData.totalDevices = 0
|
|
49
46
|
allData.totalFuelDrops = 0
|
|
50
47
|
allData.totalFuelDropLiters = 0
|
|
51
48
|
|
|
52
49
|
for (const d of devices) {
|
|
53
50
|
const alerts = data.filter(t => t.deviceId === d.id)
|
|
54
|
-
|
|
55
51
|
if (alerts.length > 0) {
|
|
56
|
-
const
|
|
57
|
-
const
|
|
52
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, [d], true, false, false, false, 1, devices.length)
|
|
53
|
+
const route = allInOne.route.filter(t => t.deviceId === d.id)
|
|
58
54
|
|
|
59
55
|
for (const a of alerts) {
|
|
60
56
|
a.fuelDropLiters = 0
|
|
61
57
|
if (a.positionId > 0) {
|
|
62
|
-
const position =
|
|
58
|
+
const position = route.find(p => p.id === a.positionId)
|
|
63
59
|
if (position) {
|
|
64
60
|
a.position = position
|
|
65
|
-
const diff = calculateFuelDrop(position,
|
|
61
|
+
const diff = calculateFuelDrop(position, route)
|
|
66
62
|
a.fuelDropLiters = Math.round(diff * d.attributes.fuel_tank_capacity / 100)
|
|
67
63
|
}
|
|
68
64
|
}
|
|
@@ -76,16 +72,10 @@ async function createFuelDropReport (from, to, userData, traccar) {
|
|
|
76
72
|
device: d,
|
|
77
73
|
alerts: filteredAlerts
|
|
78
74
|
})
|
|
79
|
-
|
|
80
|
-
allData.totalDevices = allData.totalDevices + 1
|
|
81
|
-
allData.totalFuelDrops = allData.totalFuelDrops + filteredAlerts.length
|
|
82
|
-
allData.totalFuelDropLiters = allData.totalFuelDropLiters + filteredAlerts.reduce((a, b) => a + b.fuelDropLiters, 0)
|
|
83
75
|
}
|
|
84
76
|
}
|
|
85
77
|
}
|
|
86
78
|
|
|
87
|
-
reportData.push(allData)
|
|
88
|
-
|
|
89
79
|
return reportData
|
|
90
80
|
}
|
|
91
81
|
|
package/src/tests/fuel.test.js
CHANGED
|
@@ -5,6 +5,7 @@ const assert = require('assert')
|
|
|
5
5
|
const deviceId = 122575
|
|
6
6
|
// eslint-disable-next-line no-undef
|
|
7
7
|
describe('Test_Reports', function () {
|
|
8
|
+
this.timeout(5000000)
|
|
8
9
|
it('Trip by device', async () => {
|
|
9
10
|
console.log('trip by device')
|
|
10
11
|
const report = await getReports()
|
package/src/util/traccar.js
CHANGED
|
@@ -79,7 +79,7 @@ async function getAllInOne (
|
|
|
79
79
|
sliceSize = 5,
|
|
80
80
|
devicesPerRequest = 1,
|
|
81
81
|
counter = undefined) {
|
|
82
|
-
let url = `/reports/allinone?from=${from.toISOString()}&to=${to.toISOString()}`
|
|
82
|
+
let url = `/reports/5120/allinone?from=${from.toISOString()}&to=${to.toISOString()}`
|
|
83
83
|
if (getRoutes) url += '&type=route'
|
|
84
84
|
if (getTrips) url += '&type=trips'
|
|
85
85
|
if (getStops) url += '&type=stops'
|