fleetmap-reports 1.0.625 → 1.0.627
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
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
const traccar = require('../util/traccar')
|
|
2
2
|
const { getIdleEvents } = require('../util/route')
|
|
3
|
-
const { insideGeofence } = require('../util/geofence')
|
|
3
|
+
const { insideGeofence, getNearestPOIs } = require('../util/geofence')
|
|
4
4
|
|
|
5
5
|
async function createActivityReport (from, to, userData, traccarInstance) {
|
|
6
|
-
const
|
|
6
|
+
const notAuthGroup = userData.groups.find(g => g.name === 'Zones Non Autorisées')
|
|
7
|
+
const authGroup = userData.groups.find(g => g.name === 'Zones Autorisées')
|
|
7
8
|
|
|
8
9
|
const unauthorizedGeofences = []
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
const authorizedGeofences = []
|
|
11
|
+
if (notAuthGroup) {
|
|
12
|
+
const geofenceIds = (await traccarInstance.geofences.geofencesGet(undefined, undefined, undefined, notAuthGroup.id, undefined, undefined).then(r => r.data)).map(g => g.id)
|
|
11
13
|
unauthorizedGeofences.push(...(userData.geofences.filter(g => geofenceIds.includes(g.id))))
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
if (authGroup) {
|
|
17
|
+
const geofenceIds = (await traccarInstance.geofences.geofencesGet(undefined, undefined, undefined, authGroup.id, undefined, undefined).then(r => r.data)).map(g => g.id)
|
|
18
|
+
authorizedGeofences.push(...(userData.geofences.filter(g => geofenceIds.includes(g.id))))
|
|
19
|
+
}
|
|
20
|
+
|
|
14
21
|
const allInOne = await traccar.getAllInOne(traccarInstance, from, to, userData.devices, true, true, true, false)
|
|
15
22
|
|
|
16
23
|
const reportData = []
|
|
@@ -23,6 +30,9 @@ async function createActivityReport (from, to, userData, traccarInstance) {
|
|
|
23
30
|
const unauthorizedStops = stops.filter(s =>
|
|
24
31
|
unauthorizedGeofences.find(g => insideGeofence({ latitude: s.latitude, longitude: s.longitude }, g))
|
|
25
32
|
)
|
|
33
|
+
const authorizedStops = stops.filter(s =>
|
|
34
|
+
authorizedGeofences.find(g => insideGeofence({ latitude: s.latitude, longitude: s.longitude }, g))
|
|
35
|
+
)
|
|
26
36
|
|
|
27
37
|
const idleEvents = getIdleEvents(route)
|
|
28
38
|
|
|
@@ -32,13 +42,19 @@ async function createActivityReport (from, to, userData, traccarInstance) {
|
|
|
32
42
|
|
|
33
43
|
const idleTimeArray = idleEvents.map(e => e.idleTime).filter(a => a > 0)
|
|
34
44
|
|
|
45
|
+
const startTrip = trips.length ? trips[0] : undefined
|
|
46
|
+
const endTrip = trips.length ? trips[trips.length - 1] : undefined
|
|
47
|
+
|
|
48
|
+
const startNearestPOIs = startTrip ? getNearestPOIs(startTrip.startLon, startTrip.startLat, userData.geofences) : []
|
|
49
|
+
const endNearestPOIs = endTrip ? getNearestPOIs(endTrip.endLon, endTrip.endLat, userData.geofences) : []
|
|
50
|
+
|
|
35
51
|
const deviceData = {
|
|
36
52
|
device: d.name,
|
|
37
53
|
group: group ? group.name : '',
|
|
38
|
-
startAddress:
|
|
39
|
-
startTime:
|
|
40
|
-
endAddress:
|
|
41
|
-
endTime:
|
|
54
|
+
startAddress: startNearestPOIs.length > 0 ? startNearestPOIs[0].p.name : (startTrip ? startTrip.startAddress : ''),
|
|
55
|
+
startTime: startTrip ? startTrip.startTime : '',
|
|
56
|
+
endAddress: endNearestPOIs.length > 0 ? endNearestPOIs[0].p.name : (endTrip ? endTrip.endAddress : ''),
|
|
57
|
+
endTime: endTrip ? endTrip.endTime : '',
|
|
42
58
|
drivingTime,
|
|
43
59
|
stopTime,
|
|
44
60
|
idleTime: idleEvents.reduce((a, b) => a + b.idleTime, 0),
|
|
@@ -46,7 +62,8 @@ async function createActivityReport (from, to, userData, traccarInstance) {
|
|
|
46
62
|
totalIdleEvents: idleEvents.length,
|
|
47
63
|
minIdleEvent: idleTimeArray.length > 0 ? Math.min(...idleTimeArray) : 0,
|
|
48
64
|
maxIdleEvent: idleTimeArray.length > 0 ? Math.max(...idleTimeArray) : 0,
|
|
49
|
-
|
|
65
|
+
otherStops: stops.length - unauthorizedStops.length - authorizedStops.length,
|
|
66
|
+
authorizedStops: authorizedStops.length,
|
|
50
67
|
unauthorizedStops: unauthorizedStops.length,
|
|
51
68
|
authorizedStopsTime: unauthorizedStops.reduce((a, b) => a + (b.duration > b.engineHours ? (b.duration - b.engineHours) : 0), 0),
|
|
52
69
|
averageSpeed: totalDistance > 0 ? ((trips.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / totalDistance) : 0,
|