fleetmap-reports 1.0.981 → 1.0.982

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 +27 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.981",
3
+ "version": "1.0.982",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -94,7 +94,7 @@ async function processDevices (from, to, devices, userData, data) {
94
94
  for (const d of devices) {
95
95
  const alerts = data.alerts.filter(t => t.deviceId === d.id)
96
96
  const deviceRoute = data.route.filter(p => p.deviceId === d.id)
97
- const zoneInOutData = analyseAlerts(alerts, deviceRoute, userData, from, to, d).filter(d => !userData.onlyWithStop || d.stopped)
97
+ let zoneInOutData = analyseAlerts(alerts, deviceRoute, userData, from, to, d).filter(d => !userData.onlyWithStop || d.stopped)
98
98
 
99
99
  if (userData.groupByDay || userData.zonesByColumn) {
100
100
  const dates = getDates(from, to, userData.user.attributes.timezone)
@@ -191,18 +191,35 @@ async function processDevices (from, to, devices, userData, data) {
191
191
  if (zoneInOutData.length > 0) {
192
192
  if (userData.tripsBetweenZones) {
193
193
  const tripsBetweenZones = []
194
- zoneInOutData.forEach((a, index) => {
195
- if (index + 1 < zoneInOutData.length && a.outTime && zoneInOutData[index + 1].inTime) {
194
+ zoneInOutData = zoneInOutData.sort((a, b) => a.inTime && b.inTime && new Date(a.inTime.fixTime).getTime() - new Date(b.inTime.fixTime).getTime())
195
+ let outGeofence
196
+ let inGeofence
197
+ for (let i = 0; i < zoneInOutData.length - 1; i++) {
198
+ if (!outGeofence) {
199
+ outGeofence = zoneInOutData[i]
200
+ }
201
+ inGeofence = zoneInOutData[i + 1]
202
+
203
+ if (outGeofence.outTime &&
204
+ inGeofence.inTime &&
205
+ new Date(outGeofence.outTime.fixTime).getTime() < new Date(inGeofence.inTime.fixTime).getTime()) {
196
206
  tripsBetweenZones.push({
197
- outTime: a.outTime,
198
- outGeofenceName: a.geofenceName,
199
- inTime: zoneInOutData[index + 1].inTime,
200
- inGeofenceName: zoneInOutData[index + 1].geofenceName,
201
- distanceOut: a.distanceOutAny,
202
- totalOutTime: new Date(zoneInOutData[index + 1].inTime.fixTime).getTime() - new Date(a.outTime.fixTime).getTime()
207
+ outTime: outGeofence.outTime,
208
+ outGeofenceName: outGeofence.geofenceName,
209
+ inTime: inGeofence.inTime,
210
+ inGeofenceName: inGeofence.geofenceName,
211
+ distanceOut: outGeofence.distanceOutAny,
212
+ totalOutTime: new Date(inGeofence.inTime.fixTime).getTime() - new Date(outGeofence.outTime.fixTime).getTime()
203
213
  })
214
+ outGeofence = undefined
215
+ } else {
216
+ if (outGeofence.outTime &&
217
+ inGeofence.outTime &&
218
+ new Date(outGeofence.outTime.fixTime).getTime() <= new Date(inGeofence.outTime.fixTime).getTime()) {
219
+ outGeofence = undefined
220
+ }
204
221
  }
205
- })
222
+ }
206
223
  if (tripsBetweenZones.length > 0) {
207
224
  devicesResult.push({
208
225
  device: d,