fleetmap-reports 1.0.571 → 1.0.572

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.571",
3
+ "version": "1.0.572",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -72,7 +72,7 @@ async function createZoneReport (from, to, userData, traccar) {
72
72
  console.log('Geofence Enter/Exit Alerts:' + alerts.length)
73
73
 
74
74
  if (alerts.length) {
75
- allData.devices.push(...await processDevices(from, to, devices, userData.drivers, userData.geofences, alerts, traccar))
75
+ allData.devices.push(...await processDevices(from, to, devices, userData.drivers, userData.geofences, { alerts, route: data.route }, traccar))
76
76
  }
77
77
  deviceCount = deviceCount + slice.length
78
78
  }
@@ -86,7 +86,7 @@ async function processDevices (from, to, devices, drivers, geofences, data) {
86
86
  const devicesResult = []
87
87
 
88
88
  for (const d of devices) {
89
- const alerts = data.filter(t => t.deviceId === d.id)
89
+ const alerts = data.alerts.filter(t => t.deviceId === d.id)
90
90
  if (alerts.length > 0) {
91
91
  // const response = await traccar.reports.reportsRouteGet(from, to, [d.id])
92
92
 
@@ -105,12 +105,15 @@ async function processDevices (from, to, devices, drivers, geofences, data) {
105
105
  const geofence = geofences.find(g => g.id === a.geofenceId)
106
106
  if (zoneInData[a.geofenceId]) {
107
107
  const totalInTime = moment(a.position.fixTime).diff(moment(zoneInData[a.geofenceId].position.fixTime), 'seconds')
108
+ const route = data.route.filter(p => p.fixTime >= zoneInData[a.geofenceId].position.fixTime &&
109
+ p.fixTime <= a.position.fixTime)
108
110
  if (geofence) {
109
111
  zoneInOutData.push({
110
112
  inTime: zoneInData[a.geofenceId].position,
111
113
  outTime: a.position,
112
114
  totalTime: totalInTime,
113
115
  geofenceName: geofence.name,
116
+ stopped: route.filter(p => !p.attributes.ignition).length > 0,
114
117
  driverName: zoneInData[a.geofenceId].position.driverName
115
118
  })
116
119
  }