fleetmap-reports 1.0.443 → 1.0.446
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/events-report.js +8 -7
- package/src/index.test.js +0 -2
- package/src/util/odoo.js +7 -9
package/package.json
CHANGED
package/src/events-report.js
CHANGED
|
@@ -56,14 +56,14 @@ async function getReportData (from, to, devices, types, traccar) {
|
|
|
56
56
|
const arrayOfArrays = automaticReports.sliceArray(devices)
|
|
57
57
|
const traccarTypes = new Set(types.map(t => t.startsWith('alarm') ? 'alarm' : t))
|
|
58
58
|
const traccarSubTypes = types.map(t => t.startsWith('alarm') ? t.replace('alarm_', '') : '').filter(Boolean)
|
|
59
|
-
|
|
59
|
+
await Promise.all(arrayOfArrays.map(async a => {
|
|
60
60
|
const response = await traccar.reports.reportsEventsGet(from, to, a.map(d => d.id), null, traccarTypes)
|
|
61
61
|
if (types.length > 0) {
|
|
62
62
|
data = data.concat(response.data.filter(e => e.type === 'alarm' ? traccarSubTypes.includes(e.attributes.alarm) : true))
|
|
63
63
|
} else {
|
|
64
64
|
data = data.concat(response.data)
|
|
65
65
|
}
|
|
66
|
-
}
|
|
66
|
+
}))
|
|
67
67
|
console.log('Alerts:' + data.length)
|
|
68
68
|
return data
|
|
69
69
|
}
|
|
@@ -71,9 +71,7 @@ async function getReportData (from, to, devices, types, traccar) {
|
|
|
71
71
|
async function processDevices (from, to, devices, geofences, drivers, data, traccar) {
|
|
72
72
|
const devicesResult = []
|
|
73
73
|
let i = 0
|
|
74
|
-
|
|
75
|
-
console.log('LOADING_MESSAGE:' + d.name)
|
|
76
|
-
console.log(`PROGRESS_PERC:${++i / devices.length * 100}`)
|
|
74
|
+
await Promise.all(devices.map(async d => {
|
|
77
75
|
const alerts = data.filter(t => t.deviceId === d.id)
|
|
78
76
|
|
|
79
77
|
if (alerts.length > 0) {
|
|
@@ -100,6 +98,9 @@ async function processDevices (from, to, devices, geofences, drivers, data, trac
|
|
|
100
98
|
}
|
|
101
99
|
}
|
|
102
100
|
|
|
101
|
+
console.log('LOADING_MESSAGE:' + d.name)
|
|
102
|
+
console.log(`PROGRESS_PERC:${++i / devices.length * 100}`)
|
|
103
|
+
|
|
103
104
|
devicesResult.push({
|
|
104
105
|
device: d,
|
|
105
106
|
from,
|
|
@@ -107,7 +108,7 @@ async function processDevices (from, to, devices, geofences, drivers, data, trac
|
|
|
107
108
|
alerts
|
|
108
109
|
})
|
|
109
110
|
}
|
|
110
|
-
}
|
|
111
|
+
}))
|
|
111
112
|
|
|
112
113
|
return devicesResult
|
|
113
114
|
}
|
|
@@ -261,7 +262,7 @@ function getAlertInfo (drivers, alert) {
|
|
|
261
262
|
const driver = drivers.find(d => d.uniqueId === alert.attributes.driverUniqueId)
|
|
262
263
|
return driver ? driver.name : alert.attributes.driverUniqueId
|
|
263
264
|
}
|
|
264
|
-
return
|
|
265
|
+
return alert.driver
|
|
265
266
|
}
|
|
266
267
|
|
|
267
268
|
function getAlertDate (user, alert) {
|
package/src/index.test.js
CHANGED
|
@@ -15,12 +15,10 @@ async function getSpeedingReport (report, userData) {
|
|
|
15
15
|
|
|
16
16
|
// eslint-disable-next-line no-undef
|
|
17
17
|
describe('Test_Reports', function () {
|
|
18
|
-
this.timeout(500000)
|
|
19
18
|
// eslint-disable-next-line no-undef
|
|
20
19
|
it('Speeding by device', async () => {
|
|
21
20
|
const report = await getReports()
|
|
22
21
|
const userData = await report.getUserData()
|
|
23
|
-
userData.roadSpeedLimit = true
|
|
24
22
|
const { device, totalDistance, totalEventTime } = await getSpeedingReport(report, userData)
|
|
25
23
|
assert.equal(device.alerts.length, 15) // Total Alerts
|
|
26
24
|
assert.equal(totalDistance, 19.59984677533689) // Total Kms
|
package/src/util/odoo.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
|
|
2
|
-
async function getOdooFuelServices
|
|
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
|
-
|
|
8
|
-
withCredentials: true
|
|
9
|
-
})
|
|
5
|
+
const {data} = await traccar.axios.get(url,{
|
|
6
|
+
jar: traccar.cookieJar,
|
|
7
|
+
withCredentials: true })
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
console.log(data)
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
return data
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
exports.getOdooFuelServices = getOdooFuelServices
|