fleetmap-reports 1.0.571 → 1.0.573

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/zone-report.js +15 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.571",
3
+ "version": "1.0.573",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -46,7 +46,7 @@ async function createZoneReport (from, to, userData, traccar) {
46
46
  devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
47
47
 
48
48
  if (data.length > 0) {
49
- groupData.devices = await processDevices(from, to, devices, userData.drivers, userData.geofences, data)
49
+ groupData.devices = await processDevices(from, to, devices, userData, { alerts: data })
50
50
  reportData.push(groupData)
51
51
  }
52
52
  }
@@ -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, { alerts, route: data.route }))
76
76
  }
77
77
  deviceCount = deviceCount + slice.length
78
78
  }
@@ -82,35 +82,35 @@ async function createZoneReport (from, to, userData, traccar) {
82
82
  return reportData
83
83
  }
84
84
 
85
- async function processDevices (from, to, devices, drivers, geofences, data) {
85
+ async function processDevices (from, to, devices, userData, 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
- // const response = await traccar.reports.reportsRouteGet(from, to, [d.id])
92
-
93
91
  const zoneInOutData = []
94
92
  const zoneInData = {}
95
- // const positions = response.data
96
93
 
97
94
  alerts.forEach(a => {
98
- // a.position = positions.find(p => p.id === a.positionId)
99
95
  if (a.position) {
100
96
  if (a.type === 'geofenceEnter') {
101
- const driver = drivers.find(d => a.position.attributes && d.uniqueId === a.position.attributes.driverUniqueId)
97
+ const driver = userData.drivers.find(d => a.position.attributes && d.uniqueId === a.position.attributes.driverUniqueId)
102
98
  a.position.driverName = driver ? driver.name : ''
103
99
  zoneInData[a.geofenceId] = a
104
100
  } else if (a.type === 'geofenceExit') {
105
- const geofence = geofences.find(g => g.id === a.geofenceId)
101
+ const geofence = userData.geofences.find(g => g.id === a.geofenceId)
106
102
  if (zoneInData[a.geofenceId]) {
107
103
  const totalInTime = moment(a.position.fixTime).diff(moment(zoneInData[a.geofenceId].position.fixTime), 'seconds')
104
+ const route = data.route.filter(p => new Date(p.fixTime).getTime() >= new Date(zoneInData[a.geofenceId].position.fixTime).getTime() &&
105
+ new Date(p.fixTime).getTime() <= new Date(a.position.fixTime).getTime())
106
+ console.log(route)
108
107
  if (geofence) {
109
108
  zoneInOutData.push({
110
109
  inTime: zoneInData[a.geofenceId].position,
111
110
  outTime: a.position,
112
111
  totalTime: totalInTime,
113
112
  geofenceName: geofence.name,
113
+ stopped: route.filter(p => !p.attributes.ignition).length > 0,
114
114
  driverName: zoneInData[a.geofenceId].position.driverName
115
115
  })
116
116
  }
@@ -130,7 +130,7 @@ async function processDevices (from, to, devices, drivers, geofences, data) {
130
130
 
131
131
  for (const i in zoneInData) {
132
132
  if (zoneInData[i]) {
133
- const geofence = geofences.find(g => g.id === zoneInData[i].geofenceId)
133
+ const geofence = userData.geofences.find(g => g.id === zoneInData[i].geofenceId)
134
134
  if (geofence) {
135
135
  zoneInOutData.push({
136
136
  inTime: zoneInData[i].position,
@@ -141,12 +141,14 @@ async function processDevices (from, to, devices, drivers, geofences, data) {
141
141
  }
142
142
  }
143
143
 
144
- if (zoneInOutData.length > 0) {
144
+ const result = userData.onlyWithStop ? zoneInOutData.filter(d => d.stopped) : zoneInOutData
145
+
146
+ if (result.length > 0) {
145
147
  devicesResult.push({
146
148
  device: d,
147
149
  from,
148
150
  to,
149
- geofences: zoneInOutData
151
+ geofences: result
150
152
  })
151
153
  }
152
154
  }