fleetmap-reports 1.0.958 → 1.0.959
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/tests/zones.test.js +17 -0
- package/src/zone-report.js +39 -34
package/package.json
CHANGED
package/src/tests/zones.test.js
CHANGED
|
@@ -61,4 +61,21 @@ describe('zones', function () {
|
|
|
61
61
|
assert.equal(first.days[0].distanceOut, 0)
|
|
62
62
|
assert.equal(first.days[2].distanceOut, 0)
|
|
63
63
|
}, 4000000)
|
|
64
|
+
|
|
65
|
+
it('works with casais zones in columns 2', async () => {
|
|
66
|
+
const report = await getReports()
|
|
67
|
+
const userData = await report.getUserData()
|
|
68
|
+
userData.zonesByColumn = true
|
|
69
|
+
userData.devices = userData.devices.filter(d => d.id === 81201)
|
|
70
|
+
userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde ' ||
|
|
71
|
+
g.name === 'baliza 2 - raio amarelo')
|
|
72
|
+
userData.onlyWithKmsOut = false
|
|
73
|
+
const result = await report.zoneReport(
|
|
74
|
+
new Date(Date.UTC(2023, 7, 7, 0, 0, 0, 0)),
|
|
75
|
+
new Date(Date.UTC(2023, 7, 7, 23, 59, 59, 0)),
|
|
76
|
+
userData)
|
|
77
|
+
const first = result[0].devices[0]
|
|
78
|
+
console.log(first)
|
|
79
|
+
assert.equal(first.days[0].distanceOut, 554.6037095121401)
|
|
80
|
+
}, 4000000)
|
|
64
81
|
})
|
package/src/zone-report.js
CHANGED
|
@@ -275,7 +275,7 @@ function getAnyLastExit (inDate, alerts, deviceRoute) {
|
|
|
275
275
|
.filter(a => a.type === 'geofenceExit')
|
|
276
276
|
.find(a => new Date(a.position.fixTime).getTime() < inDate)
|
|
277
277
|
|
|
278
|
-
if (next && !alerts.filter(a => a.type === '
|
|
278
|
+
if (next && !alerts.filter(a => a.type === 'geofenceEnter' &&
|
|
279
279
|
new Date(a.position.fixTime).getTime() < inDate &&
|
|
280
280
|
new Date(a.position.fixTime).getTime() > new Date(next.position.fixTime).getTime()).length) {
|
|
281
281
|
return (next && next.position && new Date(next.position.fixTime).getTime()) ||
|
|
@@ -336,7 +336,7 @@ function calculateDistanceOut (zoneInOutDayData, dayRoute, fromByDay, toByDay, f
|
|
|
336
336
|
|
|
337
337
|
function analyseAlerts (alerts, deviceRoute, userData, from, to, device) {
|
|
338
338
|
const zoneInOutData = []
|
|
339
|
-
|
|
339
|
+
let zoneInData = []
|
|
340
340
|
|
|
341
341
|
alerts.forEach(a => {
|
|
342
342
|
if (!a.position) {
|
|
@@ -345,11 +345,12 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to, device) {
|
|
|
345
345
|
if (a.type === 'geofenceEnter') {
|
|
346
346
|
const driver = userData.drivers.find(d => a.position.attributes && d.uniqueId === a.position.attributes.driverUniqueId)
|
|
347
347
|
a.position.driverName = driver ? driver.name : ''
|
|
348
|
-
if (
|
|
349
|
-
|
|
348
|
+
if (zoneInData.length === 0) {
|
|
349
|
+
const anyLastExist = getAnyLastExit(new Date(a.position.fixTime).getTime(), alerts, deviceRoute)
|
|
350
|
+
a.anyLastExit = anyLastExist || from
|
|
350
351
|
}
|
|
351
352
|
|
|
352
|
-
zoneInData
|
|
353
|
+
zoneInData.push(a)
|
|
353
354
|
} else if (a.type === 'geofenceExit') {
|
|
354
355
|
const geofence = userData.geofences.find(g => g.id === a.geofenceId)
|
|
355
356
|
if (!geofence) {
|
|
@@ -364,22 +365,27 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to, device) {
|
|
|
364
365
|
const totalOutTime = nextIn - outDate
|
|
365
366
|
const distanceOut = calculateDistance(routeAfterOut, device.attributes['report.ignoreOdometer'])
|
|
366
367
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
368
|
+
let anyNextIn
|
|
369
|
+
let distanceOutAny = 0
|
|
370
|
+
if (zoneInData.length < 2) {
|
|
371
|
+
anyNextIn = getAnyNextIn(outDate, alerts, deviceRoute)
|
|
372
|
+
const routeAfterOutAndBeforeAnyNextIn = deviceRoute.filter(p =>
|
|
373
|
+
new Date(p.fixTime).getTime() >= outDate &&
|
|
374
|
+
new Date(p.fixTime).getTime() <= anyNextIn
|
|
375
|
+
)
|
|
376
|
+
distanceOutAny = zoneInData.length < 2 ? Math.round(calculateDistance(routeAfterOutAndBeforeAnyNextIn, device.attributes['report.ignoreOdometer'])) : 0
|
|
377
|
+
}
|
|
373
378
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
const
|
|
379
|
+
const inData = zoneInData.find(z => z.geofenceId === a.geofenceId)
|
|
380
|
+
if (inData) {
|
|
381
|
+
const totalInTime = new Date(a.position.fixTime).getTime() - new Date(inData.position.fixTime).getTime()
|
|
382
|
+
const inDate = new Date(inData.position.fixTime).getTime()
|
|
377
383
|
const routeIn = deviceRoute.filter(p =>
|
|
378
384
|
new Date(p.fixTime).getTime() >= inDate &&
|
|
379
385
|
new Date(p.fixTime).getTime() < outDate
|
|
380
386
|
)
|
|
381
387
|
zoneInOutData.push({
|
|
382
|
-
inTime:
|
|
388
|
+
inTime: inData.position,
|
|
383
389
|
outTime: a.position,
|
|
384
390
|
totalInTime,
|
|
385
391
|
totalOutTime,
|
|
@@ -391,9 +397,9 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to, device) {
|
|
|
391
397
|
geofenceName: geofence.name,
|
|
392
398
|
geofenceId: geofence.id,
|
|
393
399
|
stopped: routeIn.filter(p => !p.attributes.ignition).length > 0,
|
|
394
|
-
driverName:
|
|
400
|
+
driverName: inData.position.driverName
|
|
395
401
|
})
|
|
396
|
-
|
|
402
|
+
zoneInData = zoneInData.filter(z => z.geofenceId === a.geofenceId)
|
|
397
403
|
} else {
|
|
398
404
|
const totalInTime = new Date(a.position.fixTime).getTime() - from.getTime()
|
|
399
405
|
const routeIn = deviceRoute.filter(p =>
|
|
@@ -417,24 +423,23 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to, device) {
|
|
|
417
423
|
}
|
|
418
424
|
})
|
|
419
425
|
|
|
420
|
-
for (const
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
new Date(p.fixTime).getTime() >= new Date(zoneInData[i].position.fixTime).getTime() &&
|
|
426
|
+
for (const inData of zoneInData) {
|
|
427
|
+
const geofence = userData.geofences.find(g => g.id === inData.geofenceId)
|
|
428
|
+
if (geofence) {
|
|
429
|
+
const totalInTime = to.getTime() - new Date(inData.position.fixTime).getTime()
|
|
430
|
+
const routeIn = deviceRoute.filter(p =>
|
|
431
|
+
new Date(p.fixTime).getTime() >= new Date(inData.position.fixTime).getTime() &&
|
|
427
432
|
new Date(p.fixTime).getTime() < to.getTime()
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
433
|
+
)
|
|
434
|
+
zoneInOutData.push({
|
|
435
|
+
inTime: inData.position,
|
|
436
|
+
totalInTime,
|
|
437
|
+
distanceIn: calculateDistance(routeIn, device.attributes['report.ignoreOdometer']),
|
|
438
|
+
geofenceName: geofence.name,
|
|
439
|
+
geofenceId: geofence.id,
|
|
440
|
+
driverName: inData.position.driverName,
|
|
441
|
+
anyLastExit: inData.anyLastExit
|
|
442
|
+
})
|
|
438
443
|
}
|
|
439
444
|
}
|
|
440
445
|
|