fleetmap-reports 1.0.680 → 1.0.681
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/partnerReports/afriquia.js +13 -3
- package/src/util/geofence.js +14 -0
- package/src/zone-report.js +1 -14
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const traccar = require('../util/traccar')
|
|
2
2
|
const { getIdleEvents } = require('../util/route')
|
|
3
|
-
const {
|
|
3
|
+
const { getNearestPOIs, checkGeofenceIn } = require('../util/geofence')
|
|
4
|
+
const { convertToFeature, convertPositionToFeature } = require('../util/utils')
|
|
4
5
|
|
|
5
6
|
function calculateLastStopTime (stopTime, to, time) {
|
|
6
7
|
return stopTime + (to.getTime() - new Date(time).getTime())
|
|
@@ -16,10 +17,12 @@ async function createActivityReport (from, to, userData, traccarInstance) {
|
|
|
16
17
|
|
|
17
18
|
const notAuthGeofenceIds = (await traccarInstance.geofences.geofencesGet(undefined, undefined, undefined, Number(process.env.AFRIQUIA_NOT_AUTH_GROUP_ID), undefined, undefined).then(r => r.data)).map(g => g.id)
|
|
18
19
|
unauthorizedGeofences.push(...(userData.geofences.filter(g => notAuthGeofenceIds.includes(g.id))))
|
|
20
|
+
const unauthorizedGeofencesFeatures = unauthorizedGeofences.map(g => convertToFeature(g))
|
|
19
21
|
console.log('unauthorizedGeofences', unauthorizedGeofences)
|
|
20
22
|
|
|
21
23
|
const authGeofenceIds = (await traccarInstance.geofences.geofencesGet(undefined, undefined, undefined, Number(process.env.AFRIQUIA_AUTH_GROUP_ID), undefined, undefined).then(r => r.data)).map(g => g.id)
|
|
22
24
|
authorizedGeofences.push(...(userData.geofences.filter(g => authGeofenceIds.includes(g.id))))
|
|
25
|
+
const authorizedGeofencesFeatures = authorizedGeofences.map(g => convertToFeature(g))
|
|
23
26
|
console.log('authorizedGeofences', authorizedGeofences)
|
|
24
27
|
|
|
25
28
|
const allInOne = await traccar.getAllInOne(traccarInstance, from, to, userData.devices, true, true, true, false)
|
|
@@ -37,12 +40,19 @@ async function createActivityReport (from, to, userData, traccarInstance) {
|
|
|
37
40
|
let authorizedStopsTime = 0
|
|
38
41
|
|
|
39
42
|
stops.forEach(s => {
|
|
40
|
-
const
|
|
43
|
+
const point = convertPositionToFeature({ latitude: s.latitude, longitude: s.longitude })
|
|
44
|
+
const unauthorized = unauthorizedGeofencesFeatures.find(g => {
|
|
45
|
+
const geofenceFeature = unauthorizedGeofencesFeatures.find(gF => gF.properties.geofence.id === g.id)
|
|
46
|
+
return checkGeofenceIn(point, geofenceFeature)
|
|
47
|
+
})
|
|
41
48
|
|
|
42
49
|
if (unauthorized) {
|
|
43
50
|
unauthorizedStops = unauthorizedStops + 1
|
|
44
51
|
} else {
|
|
45
|
-
const authorized = authorizedGeofences.find(g =>
|
|
52
|
+
const authorized = authorizedGeofences.find(g => {
|
|
53
|
+
const geofenceFeature = authorizedGeofencesFeatures.find(gF => gF.properties.geofence.id === g.id)
|
|
54
|
+
return checkGeofenceIn(point, geofenceFeature)
|
|
55
|
+
})
|
|
46
56
|
|
|
47
57
|
if (authorized) {
|
|
48
58
|
authorizedStops = authorizedStops + 1
|
package/src/util/geofence.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const turf = require('@turf/helpers')
|
|
2
2
|
const inside = require('@turf/boolean-point-in-polygon')
|
|
3
3
|
const { coordsDistance } = require('./utils')
|
|
4
|
+
const booleanPointInPolygon = require('@turf/boolean-point-in-polygon')
|
|
5
|
+
const distance = require('@turf/distance')
|
|
6
|
+
const pointToLineDistance = require('@turf/point-to-line-distance')
|
|
4
7
|
|
|
5
8
|
exports.insideGeofence = function insideGeofence (position, geofence) {
|
|
6
9
|
const coords = geofence.area.slice(9, geofence.area.length - 2).split(',')
|
|
@@ -32,3 +35,14 @@ exports.loadGroupsData = async function loadGroupsData (userData, traccarInstanc
|
|
|
32
35
|
g.geofenceIds = (await traccarInstance.geofences.geofencesGet(undefined, undefined, undefined, g.id, undefined, undefined).then(r => r.data)).map(g => g.id)
|
|
33
36
|
}
|
|
34
37
|
}
|
|
38
|
+
|
|
39
|
+
exports.checkGeofenceIn = function checkGeofenceIn (p, g) {
|
|
40
|
+
switch (g.geometry.type) {
|
|
41
|
+
case 'Polygon':
|
|
42
|
+
return booleanPointInPolygon.default(p, g)
|
|
43
|
+
case 'Point':
|
|
44
|
+
return distance.default(p, g, { units: 'meters' }) >= g.properties.distance
|
|
45
|
+
case 'LineString':
|
|
46
|
+
return pointToLineDistance.default(p, g, { units: 'meters' }) > (g.properties.geofence.attributes.polylineDistance || 25)
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/zone-report.js
CHANGED
|
@@ -11,12 +11,10 @@ const { headerFromUser, addTable } = require('./util/pdfDocument')
|
|
|
11
11
|
const { getStyle } = require('./reportStyle')
|
|
12
12
|
const { getUserPartner } = require('fleetmap-partners')
|
|
13
13
|
const { devicesToProcess } = require('./util/device')
|
|
14
|
-
const pointToLineDistance = require('@turf/point-to-line-distance')
|
|
15
|
-
const booleanPointInPolygon = require('@turf/boolean-point-in-polygon')
|
|
16
|
-
const distance = require('@turf/distance')
|
|
17
14
|
const axios = require('axios')
|
|
18
15
|
const { processServerSide } = require('./util')
|
|
19
16
|
const { filterPositions } = require('./util/route')
|
|
17
|
+
const { checkGeofenceIn } = require('./util/geofence')
|
|
20
18
|
const sliceSize = 100
|
|
21
19
|
const deviceChunk = 5
|
|
22
20
|
const fileName = 'ZoneReport'
|
|
@@ -301,17 +299,6 @@ function checkGeofenceExit (p1, p2, g) {
|
|
|
301
299
|
return checkGeofenceEnter(p2, p1, g)
|
|
302
300
|
}
|
|
303
301
|
|
|
304
|
-
function checkGeofenceIn (p, g) {
|
|
305
|
-
switch (g.geometry.type) {
|
|
306
|
-
case 'Polygon':
|
|
307
|
-
return booleanPointInPolygon.default(p, g)
|
|
308
|
-
case 'Point':
|
|
309
|
-
return distance.default(p, g, { units: 'meters' }) >= g.properties.distance
|
|
310
|
-
case 'LineString':
|
|
311
|
-
return pointToLineDistance.default(p, g, { units: 'meters' }) > (g.properties.geofence.attributes.polylineDistance || 25)
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
302
|
function getInAndOutEvents (devices, route, userData) {
|
|
316
303
|
const events = []
|
|
317
304
|
devices.forEach(d => {
|