fleetmap-reports 1.0.625 → 1.0.626

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,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.625",
3
+ "version": "1.0.626",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -3,14 +3,21 @@ const { getIdleEvents } = require('../util/route')
3
3
  const { insideGeofence } = require('../util/geofence')
4
4
 
5
5
  async function createActivityReport (from, to, userData, traccarInstance) {
6
- const group = userData.groups.find(g => g.name === 'Zones Non Autorisées')
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
- if (group) {
10
- const geofenceIds = (await traccarInstance.geofences.geofencesGet(undefined, undefined, undefined, group.id, undefined, undefined).then(r => r.data)).map(g => g.id)
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
 
@@ -46,7 +56,8 @@ async function createActivityReport (from, to, userData, traccarInstance) {
46
56
  totalIdleEvents: idleEvents.length,
47
57
  minIdleEvent: idleTimeArray.length > 0 ? Math.min(...idleTimeArray) : 0,
48
58
  maxIdleEvent: idleTimeArray.length > 0 ? Math.max(...idleTimeArray) : 0,
49
- authorizedStops: stops.length - unauthorizedStops.length,
59
+ otherStops: stops.length - unauthorizedStops.length - authorizedStops.length,
60
+ authorizedStops: authorizedStops.length,
50
61
  unauthorizedStops: unauthorizedStops.length,
51
62
  authorizedStopsTime: unauthorizedStops.reduce((a, b) => a + (b.duration > b.engineHours ? (b.duration - b.engineHours) : 0), 0),
52
63
  averageSpeed: totalDistance > 0 ? ((trips.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / totalDistance) : 0,