fleetmap-reports 1.0.693 → 1.0.694
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/fuel.test.js +0 -1
- package/src/tests/index.js +2 -2
- package/src/tests/zones.test.js +14 -0
- package/src/zone-report.js +21 -20
package/package.json
CHANGED
package/src/tests/fuel.test.js
CHANGED
|
@@ -5,7 +5,6 @@ const assert = require('assert')
|
|
|
5
5
|
const deviceId = 122575
|
|
6
6
|
// eslint-disable-next-line no-undef
|
|
7
7
|
describe('Test_Reports', function () {
|
|
8
|
-
this.timeout(5000000)
|
|
9
8
|
it('Trip by device', async () => {
|
|
10
9
|
console.log('trip by device')
|
|
11
10
|
const report = await getReports()
|
package/src/tests/index.js
CHANGED
|
@@ -14,9 +14,9 @@ const axios = require('axios').create({ ...traccarConfig.baseOptions, baseURL: t
|
|
|
14
14
|
|
|
15
15
|
axiosCookieJarSupport(axios)
|
|
16
16
|
|
|
17
|
-
const getReports = async () => {
|
|
17
|
+
const getReports = async (email, password) => {
|
|
18
18
|
try {
|
|
19
|
-
await new SessionApi(traccarConfig, null, axios).sessionPost(process.env.email, process.env.password)
|
|
19
|
+
await new SessionApi(traccarConfig, null, axios).sessionPost(email || process.env.email, password || process.env.password)
|
|
20
20
|
return new Index(traccarConfig, axios, cookieJar)
|
|
21
21
|
} catch (e) {
|
|
22
22
|
console.error(e)
|
package/src/tests/zones.test.js
CHANGED
|
@@ -6,6 +6,7 @@ describe('zones', function () {
|
|
|
6
6
|
const ellca = require('./ellca.json')
|
|
7
7
|
userData.devices = userData.devices.filter(d => ellca.find(e => e === d.name))
|
|
8
8
|
console.log(userData.devices.length)
|
|
9
|
+
console.log(userData.devices.map(d => d.id))
|
|
9
10
|
userData.geofences = userData.geofences.filter(g => g.name === 'Geofence Ellca 2')
|
|
10
11
|
console.log(userData.geofences)
|
|
11
12
|
const result = await report.zoneReport(
|
|
@@ -14,4 +15,17 @@ describe('zones', function () {
|
|
|
14
15
|
userData)
|
|
15
16
|
console.log('result', result)
|
|
16
17
|
}, 4000000)
|
|
18
|
+
|
|
19
|
+
it('works with afriquia', async () => {
|
|
20
|
+
const report = await getReports('moviflotte@gmail.com', 'moviflotte@gmail.com')
|
|
21
|
+
const userData = await report.getUserData()
|
|
22
|
+
console.log(userData.devices.length)
|
|
23
|
+
console.log(userData.devices.map(d => d.id))
|
|
24
|
+
console.log(userData.geofences)
|
|
25
|
+
const result = await report.zoneReport(
|
|
26
|
+
new Date(Date.UTC(2023, 5, 11, 0, 0, 0, 0)),
|
|
27
|
+
new Date(Date.UTC(2023, 5, 11, 23, 59, 59, 0)),
|
|
28
|
+
userData)
|
|
29
|
+
console.log('result', result)
|
|
30
|
+
}, 4000000)
|
|
17
31
|
})
|
package/src/zone-report.js
CHANGED
|
@@ -219,7 +219,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
|
|
|
219
219
|
const nextIn = getNextIn(outDate, alerts, a.geofenceId, deviceRoute)
|
|
220
220
|
const routeAfterOut = deviceRoute.filter(p =>
|
|
221
221
|
new Date(p.fixTime).getTime() >= outDate &&
|
|
222
|
-
|
|
222
|
+
new Date(p.fixTime).getTime() < nextIn
|
|
223
223
|
)
|
|
224
224
|
const totalOutTime = nextIn - outDate
|
|
225
225
|
const distanceOut = calculateDistance(routeAfterOut)
|
|
@@ -228,7 +228,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
|
|
|
228
228
|
const inDate = new Date(zoneInData[a.geofenceId].position.fixTime).getTime()
|
|
229
229
|
const routeIn = deviceRoute.filter(p =>
|
|
230
230
|
new Date(p.fixTime).getTime() >= inDate &&
|
|
231
|
-
|
|
231
|
+
new Date(p.fixTime).getTime() < outDate
|
|
232
232
|
)
|
|
233
233
|
zoneInOutData.push({
|
|
234
234
|
inTime: zoneInData[a.geofenceId].position,
|
|
@@ -247,7 +247,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
|
|
|
247
247
|
const totalInTime = new Date(a.position.fixTime).getTime() - from.getTime()
|
|
248
248
|
const routeIn = deviceRoute.filter(p =>
|
|
249
249
|
new Date(p.fixTime).getTime() >= from.getTime() &&
|
|
250
|
-
|
|
250
|
+
new Date(p.fixTime).getTime() < outDate
|
|
251
251
|
)
|
|
252
252
|
zoneInOutData.push({
|
|
253
253
|
outTime: a.position,
|
|
@@ -270,7 +270,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
|
|
|
270
270
|
const totalInTime = to.getTime() - new Date(zoneInData[i].position.fixTime).getTime()
|
|
271
271
|
const routeIn = deviceRoute.filter(p =>
|
|
272
272
|
new Date(p.fixTime).getTime() >= new Date(zoneInData[i].position.fixTime).getTime() &&
|
|
273
|
-
|
|
273
|
+
new Date(p.fixTime).getTime() < to.getTime()
|
|
274
274
|
)
|
|
275
275
|
zoneInOutData.push({
|
|
276
276
|
inTime: zoneInData[i].position,
|
|
@@ -296,14 +296,6 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
|
|
|
296
296
|
return zoneInOutData
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
function checkGeofenceEnter (p1, p2, g) {
|
|
300
|
-
return !checkGeofenceIn(p1, g) && checkGeofenceIn(p2, g)
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function checkGeofenceExit (p1, p2, g) {
|
|
304
|
-
return checkGeofenceEnter(p2, p1, g)
|
|
305
|
-
}
|
|
306
|
-
|
|
307
299
|
function getInAndOutEvents (devices, route, userData) {
|
|
308
300
|
const events = []
|
|
309
301
|
const geofencesFeatures = userData.geofences.map(g => convertToFeature(g))
|
|
@@ -313,22 +305,31 @@ function getInAndOutEvents (devices, route, userData) {
|
|
|
313
305
|
const routePoints = deviceRoute.sort(sortPositions).map(p => convertPositionToFeature(p))
|
|
314
306
|
const deviceEvents = []
|
|
315
307
|
routePoints.filter(p => p.properties.position.valid).forEach((p, i, array) => {
|
|
308
|
+
p.inside = {}
|
|
316
309
|
if (!i) {
|
|
317
|
-
|
|
310
|
+
geofencesFeatures.forEach((g, id) => {
|
|
318
311
|
if (checkGeofenceIn(p, g)) {
|
|
312
|
+
p.inside[id] = true
|
|
319
313
|
deviceEvents.push(createEvent('geofenceIn', d.id, p, g))
|
|
320
314
|
}
|
|
321
|
-
}
|
|
315
|
+
})
|
|
322
316
|
return
|
|
323
317
|
}
|
|
324
318
|
const previous = array[i - 1]
|
|
325
|
-
|
|
326
|
-
if (
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
319
|
+
geofencesFeatures.forEach((g, id) => {
|
|
320
|
+
if (previous.inside[id]) {
|
|
321
|
+
if (!checkGeofenceIn(p, g)) {
|
|
322
|
+
deviceEvents.push(createEvent('geofenceExit', d.id, p, g))
|
|
323
|
+
} else {
|
|
324
|
+
previous.inside[id] = true
|
|
325
|
+
}
|
|
326
|
+
} else {
|
|
327
|
+
if (checkGeofenceIn(p, g)) {
|
|
328
|
+
p.inside[id] = true
|
|
329
|
+
deviceEvents.push(createEvent('geofenceEnter', d.id, p, g))
|
|
330
|
+
}
|
|
330
331
|
}
|
|
331
|
-
}
|
|
332
|
+
})
|
|
332
333
|
})
|
|
333
334
|
events.push(...deviceEvents)
|
|
334
335
|
})
|