fleetmap-reports 1.0.572 → 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 +13 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.572",
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, route: data.route }, 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,31 +82,28 @@ 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
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')
108
- const route = data.route.filter(p => p.fixTime >= zoneInData[a.geofenceId].position.fixTime &&
109
- p.fixTime <= a.position.fixTime)
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)
110
107
  if (geofence) {
111
108
  zoneInOutData.push({
112
109
  inTime: zoneInData[a.geofenceId].position,
@@ -133,7 +130,7 @@ async function processDevices (from, to, devices, drivers, geofences, data) {
133
130
 
134
131
  for (const i in zoneInData) {
135
132
  if (zoneInData[i]) {
136
- const geofence = geofences.find(g => g.id === zoneInData[i].geofenceId)
133
+ const geofence = userData.geofences.find(g => g.id === zoneInData[i].geofenceId)
137
134
  if (geofence) {
138
135
  zoneInOutData.push({
139
136
  inTime: zoneInData[i].position,
@@ -144,12 +141,14 @@ async function processDevices (from, to, devices, drivers, geofences, data) {
144
141
  }
145
142
  }
146
143
 
147
- if (zoneInOutData.length > 0) {
144
+ const result = userData.onlyWithStop ? zoneInOutData.filter(d => d.stopped) : zoneInOutData
145
+
146
+ if (result.length > 0) {
148
147
  devicesResult.push({
149
148
  device: d,
150
149
  from,
151
150
  to,
152
- geofences: zoneInOutData
151
+ geofences: result
153
152
  })
154
153
  }
155
154
  }