fleetmap-reports 1.0.641 → 1.0.643
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 +30 -25
package/package.json
CHANGED
|
@@ -11,24 +11,16 @@ function calculateFirstStopTime (stopTime, from, time) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
async function createActivityReport (from, to, userData, traccarInstance) {
|
|
14
|
-
console.log(process.env.AFRIQUIA_NOT_AUTH_GROUP_ID, process.env.AFRIQUIA_AUTH_GROUP_ID )
|
|
15
|
-
|
|
16
|
-
const notAuthGroup = userData.groups.find(g => g.id === process.env.AFRIQUIA_NOT_AUTH_GROUP_ID)
|
|
17
|
-
const authGroup = userData.groups.find(g => g.id === process.env.AFRIQUIA_AUTH_GROUP_ID)
|
|
18
|
-
|
|
19
14
|
const unauthorizedGeofences = []
|
|
20
15
|
const authorizedGeofences = []
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
authorizedGeofences.push(...(userData.geofences.filter(g => geofenceIds.includes(g.id))))
|
|
30
|
-
console.log('authorizedGeofences', unauthorizedGeofences)
|
|
31
|
-
}
|
|
16
|
+
|
|
17
|
+
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
|
+
unauthorizedGeofences.push(...(userData.geofences.filter(g => notAuthGeofenceIds.includes(g.id))))
|
|
19
|
+
console.log('unauthorizedGeofences', unauthorizedGeofences)
|
|
20
|
+
|
|
21
|
+
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
|
+
authorizedGeofences.push(...(userData.geofences.filter(g => authGeofenceIds.includes(g.id))))
|
|
23
|
+
console.log('authorizedGeofences', authorizedGeofences)
|
|
32
24
|
|
|
33
25
|
const allInOne = await traccar.getAllInOne(traccarInstance, from, to, userData.devices, true, true, true, false)
|
|
34
26
|
|
|
@@ -39,12 +31,25 @@ async function createActivityReport (from, to, userData, traccarInstance) {
|
|
|
39
31
|
const stops = allInOne.stops.filter(s => s.deviceId === d.id)
|
|
40
32
|
const group = userData.groups.find(g => g.id === d.groupId)
|
|
41
33
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
let unauthorizedStops = 0
|
|
35
|
+
let authorizedStops = 0
|
|
36
|
+
let otherStops = 0
|
|
37
|
+
|
|
38
|
+
stops.forEach(s => {
|
|
39
|
+
const unauthorized = unauthorizedGeofences.find(g => insideGeofence({ latitude: s.latitude, longitude: s.longitude }, g))
|
|
40
|
+
|
|
41
|
+
if (unauthorized) {
|
|
42
|
+
unauthorizedStops = unauthorizedStops + 1
|
|
43
|
+
} else {
|
|
44
|
+
const authorized = authorizedGeofences.find(g => insideGeofence({ latitude: s.latitude, longitude: s.longitude }, g))
|
|
45
|
+
|
|
46
|
+
if (authorized) {
|
|
47
|
+
authorizedStops = authorizedStops + 1
|
|
48
|
+
} else {
|
|
49
|
+
otherStops = otherStops + 1
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
})
|
|
48
53
|
|
|
49
54
|
const idleEvents = getIdleEvents(route)
|
|
50
55
|
|
|
@@ -94,9 +99,9 @@ async function createActivityReport (from, to, userData, traccarInstance) {
|
|
|
94
99
|
totalIdleEvents: idleEvents.length,
|
|
95
100
|
minIdleEvent: idleTimeArray.length > 0 ? Math.min(...idleTimeArray) : 0,
|
|
96
101
|
maxIdleEvent: idleTimeArray.length > 0 ? Math.max(...idleTimeArray) : 0,
|
|
97
|
-
otherStops
|
|
98
|
-
authorizedStops
|
|
99
|
-
unauthorizedStops
|
|
102
|
+
otherStops,
|
|
103
|
+
authorizedStops,
|
|
104
|
+
unauthorizedStops,
|
|
100
105
|
authorizedStopsTime: unauthorizedStops.reduce((a, b) => a + (b.duration > b.engineHours ? (b.duration - b.engineHours) : 0), 0),
|
|
101
106
|
averageSpeed: totalDistance > 0 ? ((trips.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / totalDistance) : 0,
|
|
102
107
|
maxSpeed: trips.reduce((a, b) => {
|