fleetmap-reports 1.0.498 → 1.0.500
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/index.test.js +18 -2
- package/src/location-report.js +18 -9
- package/src/speeding-report.js +7 -7
- package/src/util/odoo.js +13 -7
package/package.json
CHANGED
package/src/index.test.js
CHANGED
|
@@ -15,6 +15,7 @@ async function getSpeedingReport (report, userData) {
|
|
|
15
15
|
|
|
16
16
|
// eslint-disable-next-line no-undef
|
|
17
17
|
describe('Test_Reports', function () {
|
|
18
|
+
this.timeout(5000000)
|
|
18
19
|
// eslint-disable-next-line no-undef
|
|
19
20
|
it('Speeding by device', async () => {
|
|
20
21
|
const report = await getReports()
|
|
@@ -36,7 +37,7 @@ describe('Test_Reports', function () {
|
|
|
36
37
|
assert.equal(device.alerts.length, 13) // Total Alerts
|
|
37
38
|
assert.equal(totalDistance, 46.64576895855739) // Total Kms
|
|
38
39
|
assert.equal(totalEventTime, 1402000) // Total Duration
|
|
39
|
-
},
|
|
40
|
+
}, 30000)
|
|
40
41
|
// eslint-disable-next-line no-undef
|
|
41
42
|
it('Trip by device', async () => {
|
|
42
43
|
const report = await getReports()
|
|
@@ -376,7 +377,7 @@ describe('Test_Reports', function () {
|
|
|
376
377
|
assert.equal(device.days[0].spentFuel, 2)
|
|
377
378
|
}, 30000)
|
|
378
379
|
// eslint-disable-next-line no-undef
|
|
379
|
-
it('FuelConsumption Odoo Report', async () => {
|
|
380
|
+
/* it('FuelConsumption Odoo Report', async () => {
|
|
380
381
|
const report = await getReports()
|
|
381
382
|
const userData = await report.getUserData()
|
|
382
383
|
userData.withOdooServices = true
|
|
@@ -391,6 +392,21 @@ describe('Test_Reports', function () {
|
|
|
391
392
|
assert.equal(device.days.length, 25)
|
|
392
393
|
}, 30000)
|
|
393
394
|
// eslint-disable-next-line no-undef
|
|
395
|
+
it('FuelConsumption Odoo13 Report', async () => {
|
|
396
|
+
const report = await getReports()
|
|
397
|
+
const userData = await report.getUserData()
|
|
398
|
+
userData.withOdooServices = true
|
|
399
|
+
userData.devices = userData.devices.filter(d => d.id === 22326)
|
|
400
|
+
const data = await report.fuelConsumptionReport(
|
|
401
|
+
new Date(Date.UTC(2022, 9, 1, 0, 0, 0, 0)),
|
|
402
|
+
new Date(Date.UTC(2022, 9, 31, 23, 59, 59, 0)),
|
|
403
|
+
userData)
|
|
404
|
+
|
|
405
|
+
assert.equal(data.length, 1)
|
|
406
|
+
const device = data[0].devices.find(d => d.device.id === 22326)
|
|
407
|
+
assert.equal(device.days.length, 25)
|
|
408
|
+
}, 30000) */
|
|
409
|
+
// eslint-disable-next-line no-undef
|
|
394
410
|
it('Zone Report', async () => {
|
|
395
411
|
const report = await getReports()
|
|
396
412
|
const userData = await report.getUserData()
|
package/src/location-report.js
CHANGED
|
@@ -6,6 +6,7 @@ const { getUserPartner } = require('fleetmap-partners')
|
|
|
6
6
|
const { convertToLocaleString, getTranslations } = require('./util/utils')
|
|
7
7
|
const traccarHelper = require('./util/traccar')
|
|
8
8
|
const { devicesToProcess } = require('./util/device')
|
|
9
|
+
const automaticReports = require('./automaticReports')
|
|
9
10
|
|
|
10
11
|
const fileName = 'LocationReport'
|
|
11
12
|
|
|
@@ -86,27 +87,35 @@ async function createLocationReportByDevice (from, to, userData, traccar) {
|
|
|
86
87
|
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
const
|
|
90
|
-
const routeData = allInOne.route
|
|
90
|
+
const sliced = automaticReports.sliceArray(devices, 5)
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
let deviceCount = 0
|
|
93
|
+
for (const slice of sliced) {
|
|
94
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, false, false, false, deviceCount, devices.length)
|
|
95
|
+
const routeData = allInOne.route
|
|
93
96
|
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
console.log('Locations:' + routeData.length)
|
|
98
|
+
|
|
99
|
+
if (routeData.length > 0) {
|
|
100
|
+
allData.devices.push(...processDevices(from, to, slice, {
|
|
101
|
+
route: routeData
|
|
102
|
+
}, userData))
|
|
103
|
+
}
|
|
104
|
+
deviceCount = deviceCount + slice.length
|
|
96
105
|
}
|
|
97
106
|
|
|
98
107
|
return allData
|
|
99
108
|
}
|
|
100
109
|
|
|
101
|
-
function processDevices (from, to, devices,
|
|
110
|
+
function processDevices (from, to, devices, data, userData) {
|
|
102
111
|
const devicesResult = []
|
|
103
112
|
|
|
104
113
|
for (const d of devices) {
|
|
105
|
-
const positions = data.filter(t => t.deviceId === d.id)
|
|
114
|
+
const positions = data.route.filter(t => t.deviceId === d.id)
|
|
106
115
|
|
|
107
|
-
if (drivers.length > 0) {
|
|
116
|
+
if (userData.drivers.length > 0) {
|
|
108
117
|
positions.forEach(p => {
|
|
109
|
-
const driver = drivers.find(d => d.uniqueId === p.attributes.driverUniqueId)
|
|
118
|
+
const driver = userData.drivers.find(d => d.uniqueId === p.attributes.driverUniqueId)
|
|
110
119
|
if (driver) {
|
|
111
120
|
p.driverName = driver.name
|
|
112
121
|
}
|
package/src/speeding-report.js
CHANGED
|
@@ -83,18 +83,18 @@ async function createSpeedingReportByDevice (from, to, userData, traccarInstance
|
|
|
83
83
|
const sliced = automaticReports.sliceArray(devices, 10)
|
|
84
84
|
|
|
85
85
|
let deviceCount = 0
|
|
86
|
-
|
|
87
|
-
const { routes, events } = await getEvents(traccarInstance, from, to, slice, userData, deviceCount, devices.length, slice.length)
|
|
88
|
-
if (processServerSide()) {
|
|
89
|
-
console.log('LOADING_MESSAGE:' + slice[0].name)
|
|
90
|
-
console.log(`PROGRESS_PERC:${deviceCount / devices.length * 100}`)
|
|
91
|
-
}
|
|
86
|
+
await Promise.all(sliced.map(async slice => {
|
|
87
|
+
const { routes, events } = await getEvents(traccarInstance, from, to, slice, userData, deviceCount, devices.length, slice.length)
|
|
92
88
|
if (events.length > 0) {
|
|
93
89
|
const devicesProcessed = await processDevices(from, to, slice, events, routes, userData)
|
|
94
90
|
allData.devices.push(...devicesProcessed)
|
|
95
91
|
}
|
|
96
92
|
deviceCount = deviceCount + slice.length
|
|
97
|
-
|
|
93
|
+
if (processServerSide()) {
|
|
94
|
+
console.log('LOADING_MESSAGE:' + slice[0].name)
|
|
95
|
+
console.log(`PROGRESS_PERC:${deviceCount / devices.length * 100}`)
|
|
96
|
+
}
|
|
97
|
+
}))
|
|
98
98
|
|
|
99
99
|
return allData
|
|
100
100
|
}
|
package/src/util/odoo.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
|
|
2
|
-
async function getOdooFuelServices(traccar, from, to) {
|
|
3
|
-
|
|
2
|
+
async function getOdooFuelServices (traccar, from, to) {
|
|
3
|
+
const url = `/odoo/reports/refuelingServices?startDate=${from.toDateString()}&endDate=${to.toDateString()}`
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
console.log('LOADING_MESSAGE:' + url)
|
|
6
|
+
console.log(await traccar.axios.get(url, {
|
|
7
|
+
jar: traccar.cookieJar,
|
|
8
|
+
withCredentials: true
|
|
9
|
+
}))
|
|
10
|
+
const { data } = await traccar.axios.get(url, {
|
|
11
|
+
jar: traccar.cookieJar,
|
|
12
|
+
withCredentials: true
|
|
13
|
+
})
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
console.log(data)
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
return data
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
exports.getOdooFuelServices = getOdooFuelServices
|