fleetmap-reports 1.0.915 → 1.0.916
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 +5 -5
- package/src/zone-report.js +10 -5
package/package.json
CHANGED
package/src/tests/zones.test.js
CHANGED
|
@@ -48,16 +48,16 @@ describe('zones', function () {
|
|
|
48
48
|
const report = await getReports('fleetmap.joao.penas2@gmail.com', 'penas46881')
|
|
49
49
|
const userData = await report.getUserData()
|
|
50
50
|
userData.zonesByColumn = true
|
|
51
|
-
userData.devices = userData.devices.filter(d => d.
|
|
51
|
+
userData.devices = userData.devices.filter(d => d.id === 81202)
|
|
52
52
|
userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde ' ||
|
|
53
53
|
g.name === 'baliza 2 - raio amarelo')
|
|
54
|
-
userData.onlyWithKmsOut =
|
|
54
|
+
userData.onlyWithKmsOut = false
|
|
55
55
|
const result = await report.zoneReport(
|
|
56
|
-
new Date(Date.UTC(2023,
|
|
57
|
-
new Date(Date.UTC(2023,
|
|
56
|
+
new Date(Date.UTC(2023, 6, 13, 0, 0, 0, 0)),
|
|
57
|
+
new Date(Date.UTC(2023, 6, 13, 23, 59, 59, 0)),
|
|
58
58
|
userData)
|
|
59
59
|
const first = result[0].devices[0]
|
|
60
60
|
console.log(first)
|
|
61
|
-
assert.equal(first.distanceOut,
|
|
61
|
+
assert.equal(first.days[0].distanceOut, 28)
|
|
62
62
|
}, 4000000)
|
|
63
63
|
})
|
package/src/zone-report.js
CHANGED
|
@@ -261,8 +261,13 @@ function getAnyNextIn (outDate, alerts, deviceRoute) {
|
|
|
261
261
|
const next = alerts
|
|
262
262
|
.filter(a => a.type === 'geofenceEnter')
|
|
263
263
|
.find(a => new Date(a.position.fixTime).getTime() > outDate)
|
|
264
|
-
|
|
265
|
-
|
|
264
|
+
|
|
265
|
+
if (!alerts.filter(a => a.type === 'geofenceExit' &&
|
|
266
|
+
new Date(a.position.fixTime).getTime() > outDate &&
|
|
267
|
+
new Date(a.position.fixTime).getTime() < new Date(next.position.fixTime).getTime()).length) {
|
|
268
|
+
return (next && next.position && new Date(next.position.fixTime).getTime()) ||
|
|
269
|
+
new Date(deviceRoute.slice(-1)[0].fixTime).getTime()
|
|
270
|
+
}
|
|
266
271
|
}
|
|
267
272
|
|
|
268
273
|
function calculateDistanceIn (zoneInOutDayData, deviceRoute, dayRoute, fromByDay, toByDay, to, device) {
|
|
@@ -289,9 +294,8 @@ function calculateDistanceIn (zoneInOutDayData, deviceRoute, dayRoute, fromByDay
|
|
|
289
294
|
|
|
290
295
|
function calculateDistanceOut (zoneInOutDayData, dayRoute, fromByDay, toByDay, field, device) {
|
|
291
296
|
if (zoneInOutDayData.length) {
|
|
292
|
-
const dataInsideDay = zoneInOutDayData.filter(z =>
|
|
293
|
-
let distanceOut = dataInsideDay.reduce((a, b) => a + (b[field] || 0), 0)
|
|
294
|
-
(dataInsideDay.length ? (dataInsideDay[dataInsideDay.length - 1][field] || 0) : 0)
|
|
297
|
+
const dataInsideDay = zoneInOutDayData.filter(z => z.outTime && new Date(z.outTime.fixTime) < toByDay)
|
|
298
|
+
let distanceOut = dataInsideDay.reduce((a, b) => a + (b[field] || 0), 0)
|
|
295
299
|
|
|
296
300
|
if (zoneInOutDayData[0].inTime && new Date(zoneInOutDayData[0].inTime.fixTime) > fromByDay) {
|
|
297
301
|
// Add distanceOut before the first entry
|
|
@@ -303,6 +307,7 @@ function calculateDistanceOut (zoneInOutDayData, dayRoute, fromByDay, toByDay, f
|
|
|
303
307
|
}
|
|
304
308
|
|
|
305
309
|
if (zoneInOutDayData[zoneInOutDayData.length - 1].outTime && new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime) < toByDay) {
|
|
310
|
+
distanceOut = distanceOut - zoneInOutDayData[zoneInOutDayData.length - 1][field]
|
|
306
311
|
const routeOut = dayRoute.filter(p =>
|
|
307
312
|
new Date(p.fixTime) >= new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime).getTime() &&
|
|
308
313
|
new Date(p.fixTime) < toByDay.getTime())
|