fleetmap-reports 1.0.651 → 1.0.652

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.651",
3
+ "version": "1.0.652",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -2,7 +2,6 @@ function devicesToProcess (userData) {
2
2
  const groupIds = userData.groups.map(g => g.id)
3
3
  const devices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
4
4
  devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
5
-
6
5
  console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
7
6
  return devices
8
7
  }
@@ -27,7 +27,6 @@ async function createZoneReport (from, to, userData, traccar) {
27
27
  const url = `https://${process.env.SERVER_HOST}/reports/zone-report`
28
28
  return axios.post(url, { from, to, userData }, { withCredentials: true }).then(d => d.data)
29
29
  }
30
- console.log('Create ZoneReport')
31
30
  const reportData = []
32
31
  const types = ['geofenceEnter', 'geofenceExit']
33
32
 
@@ -109,39 +108,37 @@ async function processDevices (from, to, devices, userData, data) {
109
108
  zoneInData[a.geofenceId] = a
110
109
  } else if (a.type === 'geofenceExit') {
111
110
  const geofence = userData.geofences.find(g => g.id === a.geofenceId)
111
+ if (!geofence) { return }
112
+ const outDate = new Date(a.position.fixTime).getTime()
113
+ const routeAfterOut = deviceRoute.filter(p =>
114
+ new Date(p.fixTime).getTime() >= outDate &&
115
+ new Date(p.fixTime).getTime() < getNextIn(outDate, alerts, a.geofenceId, deviceRoute)
116
+ )
112
117
  if (zoneInData[a.geofenceId]) {
113
118
  const totalInTime = moment(a.position.fixTime).diff(moment(zoneInData[a.geofenceId].position.fixTime), 'seconds')
114
119
  const inDate = new Date(zoneInData[a.geofenceId].position.fixTime).getTime()
115
- const outDate = new Date(a.position.fixTime).getTime()
116
120
  const routeIn = deviceRoute.filter(p =>
117
121
  new Date(p.fixTime).getTime() >= inDate &&
118
122
  new Date(p.fixTime).getTime() < outDate
119
123
  )
120
- const routeAfterOut = deviceRoute.filter(p =>
121
- new Date(p.fixTime).getTime() >= outDate &&
122
- new Date(p.fixTime).getTime() < getNextIn(outDate, alerts, a.geofenceId, deviceRoute)
123
- )
124
- if (geofence) {
125
- zoneInOutData.push({
126
- inTime: zoneInData[a.geofenceId].position,
127
- outTime: a.position,
128
- totalTime: totalInTime,
129
- distanceIn: calculateDistance(routeIn),
130
- distanceOut: calculateDistance(routeAfterOut),
131
- geofenceName: geofence.name,
132
- stopped: routeIn.filter(p => !p.attributes.ignition).length > 0,
133
- driverName: zoneInData[a.geofenceId].position.driverName
134
- })
135
- }
124
+ zoneInOutData.push({
125
+ inTime: zoneInData[a.geofenceId].position,
126
+ outTime: a.position,
127
+ totalTime: totalInTime,
128
+ distanceIn: calculateDistance(routeIn),
129
+ distanceOut: calculateDistance(routeAfterOut),
130
+ geofenceName: geofence.name,
131
+ stopped: routeIn.filter(p => !p.attributes.ignition).length > 0,
132
+ driverName: zoneInData[a.geofenceId].position.driverName
133
+ })
136
134
  zoneInData[a.geofenceId] = null
137
135
  } else {
138
- if (geofence) {
139
- zoneInOutData.push({
140
- outTime: a.position,
141
- geofenceName: geofence.name,
142
- driverName: ''
143
- })
144
- }
136
+ zoneInOutData.push({
137
+ outTime: a.position,
138
+ geofenceName: geofence.name,
139
+ driverName: '',
140
+ distanceOut: calculateDistance(routeAfterOut)
141
+ })
145
142
  }
146
143
  }
147
144
  }