fleetmap-reports 1.0.867 → 1.0.869
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 +7 -0
- package/src/index.js +0 -1
- package/src/partnerReports/afriquia.js +0 -5
- package/src/speeding-report.js +11 -6
- package/src/tests/activity.test.js +10 -0
- package/src/tests/index.test.js +11 -3
- package/src/tests/speeding.test.js +1 -1
- package/src/tests/zones.test.js +12 -0
package/package.json
CHANGED
package/src/events-report.js
CHANGED
|
@@ -84,6 +84,13 @@ async function processDevices (from, to, devices, data, traccar, userData) {
|
|
|
84
84
|
for (const a of deviceAlerts) {
|
|
85
85
|
a.position = positions.find(p => p.id === a.positionId)
|
|
86
86
|
|
|
87
|
+
if (a.type === 'alarm' && a.position) {
|
|
88
|
+
for (const p of positions.filter(p => p.fixTime >= a.position.fixTime)) {
|
|
89
|
+
if (p.attributes.alarm !== a.position.attributes.alarm) { break }
|
|
90
|
+
a.endPosition = p
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
87
94
|
if (!a.geofenceId && a.position) {
|
|
88
95
|
const poi = getNearestPOI(a.position, userData.geofences)
|
|
89
96
|
a.geofenceId = poi && poi.p.id
|
package/src/index.js
CHANGED
|
@@ -182,6 +182,5 @@ function Reports (config, axios, cookieJar) {
|
|
|
182
182
|
this.stopReportToExcel = (userData, reportData) => {
|
|
183
183
|
return require('./stop-report').exportStopReportToExcel(userData, reportData)
|
|
184
184
|
}
|
|
185
|
-
this.getPdf = require('./carbone').getPdf
|
|
186
185
|
}
|
|
187
186
|
module.exports = Reports
|
|
@@ -6,11 +6,6 @@ const { convertToFeature, convertPositionToFeature } = require('../util/utils')
|
|
|
6
6
|
function calculateLastStopTime (stopTime, to, time) {
|
|
7
7
|
return stopTime + (to.getTime() - new Date(time).getTime())
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
function calculateFirstStopTime (stopTime, from, time) {
|
|
11
|
-
return stopTime + (new Date(time).getTime() - from.getTime())
|
|
12
|
-
}
|
|
13
|
-
|
|
14
9
|
async function createActivityReport (from, to, userData, traccarInstance) {
|
|
15
10
|
const unauthorizedGeofences = []
|
|
16
11
|
const authorizedGeofences = []
|
package/src/speeding-report.js
CHANGED
|
@@ -299,18 +299,23 @@ async function getCustomSpeedLimitEvents (devices, routes, customSpeed) {
|
|
|
299
299
|
return events
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
+
function getCountry (position) {
|
|
303
|
+
const country = crg.get_country(position.latitude, position.longitude)
|
|
304
|
+
return country && country.code
|
|
305
|
+
}
|
|
306
|
+
|
|
302
307
|
async function getRoadSpeedLimits (devices, routes, threshold, minimumMinutes = 0) {
|
|
303
308
|
const position = routes[0]
|
|
304
|
-
const country =
|
|
309
|
+
const country = getCountry(position)
|
|
305
310
|
const config = {
|
|
306
311
|
CHL: getOSMSpeedingEvents,
|
|
307
312
|
MAR: getOSMSpeedingEvents
|
|
308
313
|
}
|
|
309
|
-
const method = config[country
|
|
310
|
-
return method(devices, routes, threshold, minimumMinutes)
|
|
314
|
+
const method = config[country] || getHereEvents
|
|
315
|
+
return method(devices, routes, threshold, minimumMinutes, country && country.code)
|
|
311
316
|
}
|
|
312
317
|
|
|
313
|
-
async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes = 0) {
|
|
318
|
+
async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes = 0, country) {
|
|
314
319
|
const chunk = 1000
|
|
315
320
|
const events = []
|
|
316
321
|
for (const d of devices) {
|
|
@@ -323,7 +328,7 @@ async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes
|
|
|
323
328
|
// eslint-disable-next-line camelcase
|
|
324
329
|
matched_points,
|
|
325
330
|
edges
|
|
326
|
-
} = await axios.post(
|
|
331
|
+
} = await axios.post(`http://valhalla-${getCountry(slice[0]) || country}.pinme.io:8002/trace_attributes`,
|
|
327
332
|
{
|
|
328
333
|
costing: 'auto',
|
|
329
334
|
shape_match: 'map_snap',
|
|
@@ -357,7 +362,7 @@ async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes
|
|
|
357
362
|
}
|
|
358
363
|
})
|
|
359
364
|
} catch (e) {
|
|
360
|
-
console.error(e.message, e.response && e.response.data, slice)
|
|
365
|
+
console.error(e.message, e.response && e.response.data, slice[0])
|
|
361
366
|
}
|
|
362
367
|
}
|
|
363
368
|
const reduced = results.reduce((acc, cur, idx, src) => {
|
|
@@ -72,4 +72,14 @@ describe('activity report', function () {
|
|
|
72
72
|
console.log(device)
|
|
73
73
|
assert.equal(device.summary.reduce((a, b) => a + b.convertedSpentFuel, 0), 168.79999999999995)
|
|
74
74
|
}, 800000)
|
|
75
|
+
it('Activity test performance', async () => {
|
|
76
|
+
const report = await getReports('q.trans', 'quality1214')
|
|
77
|
+
const userData = await report.getUserData()
|
|
78
|
+
console.log(userData)
|
|
79
|
+
userData.groupByDay = true
|
|
80
|
+
const data = await report.activityReport(new Date(2023, 7, 1, 0, 0, 0, 0),
|
|
81
|
+
new Date(2023, 31, 5, 23, 59, 59, 0),
|
|
82
|
+
userData)
|
|
83
|
+
assert.equal(data.length, 1)
|
|
84
|
+
}, 8000000)
|
|
75
85
|
})
|
package/src/tests/index.test.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const { getReports } = require('./index')
|
|
3
3
|
const assert = require('assert')
|
|
4
4
|
const utils = require('../util/utils')
|
|
5
|
+
const { createGPSJumpReport } = require('../partnerReports/gpsjump-report')
|
|
5
6
|
|
|
6
7
|
// eslint-disable-next-line no-undef
|
|
7
8
|
describe('Test_Reports', function () {
|
|
@@ -18,12 +19,19 @@ describe('Test_Reports', function () {
|
|
|
18
19
|
const pdf = await report.speedingReportToPDF(userData, data[0])
|
|
19
20
|
pdf.save()
|
|
20
21
|
}, 40000)
|
|
21
|
-
|
|
22
22
|
it('converts madrid time', async () => {
|
|
23
23
|
assert.equal(false, utils.isClientSide())
|
|
24
24
|
console.log(utils.convertToLocaleString(new Date(), 'es-CL', 'Europe/Madrid'))
|
|
25
25
|
})
|
|
26
|
-
|
|
26
|
+
it('gps jump device', async () => {
|
|
27
|
+
const report = await getReports('HASSANE', 'movitec.1637')
|
|
28
|
+
const userData = await report.getUserData()
|
|
29
|
+
userData.devices = userData.devices.filter(d => d.id === 148725)
|
|
30
|
+
const data = await createGPSJumpReport(new Date(2023, 8, 22, 0, 0, 0, 0),
|
|
31
|
+
new Date(2023, 8, 24, 23, 59, 59, 0),
|
|
32
|
+
userData, report.traccar)
|
|
33
|
+
console.log(data)
|
|
34
|
+
}, 40000)
|
|
27
35
|
it('Idle by device', async () => {
|
|
28
36
|
const report = await getReports()
|
|
29
37
|
const userData = await report.getUserData()
|
|
@@ -54,7 +62,7 @@ describe('Test_Reports', function () {
|
|
|
54
62
|
const totalIdleTime = driver.idleEvents.reduce((a, b) => a + b.idleTime, 0)
|
|
55
63
|
assert.equal(driver.idleEvents.length, 15) // Total Alerts
|
|
56
64
|
assert.equal(totalIdleTime, 16000) // Total Duration
|
|
57
|
-
}, 20000)
|
|
65
|
+
}, 20000),
|
|
58
66
|
// eslint-disable-next-line no-undef
|
|
59
67
|
it('test allinone', async () => {
|
|
60
68
|
console.log('Start')
|
|
@@ -20,7 +20,7 @@ describe('speeding tests', function () {
|
|
|
20
20
|
const userData = await report.getUserData()
|
|
21
21
|
userData.roadSpeedLimits = true
|
|
22
22
|
const { device } = await getSpeedingReport(report, userData)
|
|
23
|
-
assert.equal(device.alerts.length,
|
|
23
|
+
assert.equal(device.alerts.length, 6) // Total Alerts
|
|
24
24
|
console.log(device.alerts)
|
|
25
25
|
|
|
26
26
|
userData.minimumIdleMinutes = 1
|
package/src/tests/zones.test.js
CHANGED
|
@@ -27,6 +27,18 @@ describe('zones', function () {
|
|
|
27
27
|
console.log('result', result)
|
|
28
28
|
}, 4000000)
|
|
29
29
|
|
|
30
|
+
it('works with afriquia', async () => {
|
|
31
|
+
const report = await getReports(process.env.USER_AFRIQUIA, process.env.PASS_AFRIQUIA)
|
|
32
|
+
const userData = await report.getUserData()
|
|
33
|
+
console.log(userData.devices.length)
|
|
34
|
+
console.log(userData.geofences)
|
|
35
|
+
const result = await report.zoneReport(
|
|
36
|
+
new Date(Date.UTC(2023, 5, 11, 0, 0, 0, 0)),
|
|
37
|
+
new Date(Date.UTC(2023, 5, 11, 23, 59, 59, 0)),
|
|
38
|
+
userData)
|
|
39
|
+
console.log('result', result)
|
|
40
|
+
}, 4000000)
|
|
41
|
+
|
|
30
42
|
// eslint-disable-next-line no-undef
|
|
31
43
|
it('works with casais', async () => {
|
|
32
44
|
const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
|