fleetmap-reports 1.0.662 → 1.0.664
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 +1 -1
- package/src/zone-report.js +75 -40
package/package.json
CHANGED
package/src/zone-report.js
CHANGED
|
@@ -99,11 +99,10 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
99
99
|
|
|
100
100
|
if (alerts.length > 0) {
|
|
101
101
|
const zoneInOutData = userData.groupByDay
|
|
102
|
-
? analyseAlertsGroupGeofences(alerts, deviceRoute)
|
|
102
|
+
? analyseAlertsGroupGeofences(alerts, deviceRoute, from, to)
|
|
103
103
|
: analyseAlerts(alerts, deviceRoute, userData)
|
|
104
104
|
|
|
105
105
|
const result = userData.onlyWithStop ? zoneInOutData.filter(d => d.stopped) : zoneInOutData
|
|
106
|
-
const resultSorted = result.sort((a, b) => a.inTime && b.inTime ? new Date(a.inTime.fixTime).getTime() - new Date(b.inTime.fixTime).getTime() : -1)
|
|
107
106
|
|
|
108
107
|
if (userData.groupByDay) {
|
|
109
108
|
const dates = getDates(from, to)
|
|
@@ -113,35 +112,40 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
113
112
|
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
114
113
|
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
115
114
|
|
|
116
|
-
const zoneInOutDayData =
|
|
117
|
-
new Date(z.outTime.fixTime) > fromByDay)
|
|
118
|
-
const firstIn = zoneInOutDayData.find(z => new Date(z.inTime.fixTime) > fromByDay)
|
|
119
|
-
const lastOut = zoneInOutDayData.findLast(z => new Date(z.outTime.fixTime) < toByDay)
|
|
115
|
+
const zoneInOutDayData = result.filter(z => (!z.inTime || (new Date(z.inTime.fixTime) < toByDay)) &&
|
|
116
|
+
(!z.outTime || (new Date(z.outTime.fixTime) > fromByDay)))
|
|
120
117
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
const firstIn = zoneInOutDayData.find(z => z.inTime && new Date(z.inTime.fixTime) > fromByDay)
|
|
119
|
+
const lastOut = zoneInOutDayData.slice().reverse().find(z => z.outTime && new Date(z.outTime.fixTime) < toByDay)
|
|
120
|
+
|
|
121
|
+
let timeIn = zoneInOutDayData.length ? zoneInOutDayData.reduce((a, b) => a + (b.totalTime || 0), 0) : 0
|
|
122
|
+
|
|
123
|
+
let distanceIn = zoneInOutDayData.length ? zoneInOutDayData.reduce((a, b) => a + (b.distanceIn || 0), 0) : 0
|
|
124
|
+
let distanceOut = 0
|
|
125
|
+
if (zoneInOutDayData.length) {
|
|
126
|
+
distanceOut = zoneInOutDayData.reduce((a, b) => a + (b.distanceOut || 0), 0) - zoneInOutDayData[zoneInOutDayData.length - 1].distanceOut
|
|
127
|
+
} else {
|
|
128
|
+
distanceOut = calculateDistance(deviceRoute.filter(p => new Date(p.fixTime) >= fromByDay && new Date(p.fixTime) < toByDay))
|
|
129
|
+
}
|
|
126
130
|
|
|
127
131
|
if (zoneInOutDayData.length) {
|
|
128
132
|
// Check if the first entry starts only on the day before
|
|
129
|
-
if (new Date(zoneInOutDayData[0].inTime.fixTime) < fromByDay) {
|
|
130
|
-
|
|
131
|
-
|
|
133
|
+
if (!zoneInOutDayData[0].inTime || new Date(zoneInOutDayData[0].inTime.fixTime) < fromByDay) {
|
|
134
|
+
const inTime = zoneInOutDayData[0].inTime ? new Date(zoneInOutDayData[0].inTime.fixTime) : from
|
|
135
|
+
timeIn = timeIn - (fromByDay.getTime() - inTime.getTime())
|
|
136
|
+
const routeDayBefore = deviceRoute.filter(p => (!zoneInOutDayData[0].inTime || new Date(p.fixTime) > new Date(zoneInOutDayData[0].inTime.fixTime)) &&
|
|
132
137
|
new Date(p.fixTime) < fromByDay)
|
|
133
138
|
distanceIn = distanceIn - calculateDistance(routeDayBefore)
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
// Check if the last entry ends only on the next day
|
|
137
|
-
if (new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime) > toByDay) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
if (!zoneInOutDayData[zoneInOutDayData.length - 1].outTime || new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime) > toByDay) {
|
|
143
|
+
const outTime = zoneInOutDayData[zoneInOutDayData.length - 1].outTime ? new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime) : to
|
|
144
|
+
timeIn = timeIn - (outTime.getTime() - (toByDay.getTime() + 1000))
|
|
145
|
+
const routeDayAfter = deviceRoute.filter(p => new Date(p.fixTime) < outTime && new Date(p.fixTime) > toByDay)
|
|
141
146
|
distanceIn = distanceIn - calculateDistance(routeDayAfter)
|
|
142
|
-
|
|
143
|
-
const routeOut = deviceRoute.filter(p => new Date(p.fixTime) >
|
|
144
|
-
new Date(p.fixTime) < toByDay)
|
|
147
|
+
} else {
|
|
148
|
+
const routeOut = deviceRoute.filter(p => (!zoneInOutDayData[zoneInOutDayData.length - 1].outTime || new Date(p.fixTime) > zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime) && new Date(p.fixTime) < toByDay)
|
|
145
149
|
distanceOut = distanceOut + calculateDistance(routeOut)
|
|
146
150
|
}
|
|
147
151
|
}
|
|
@@ -152,8 +156,8 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
152
156
|
lastOut: lastOut ? lastOut.outTime.fixTime : undefined,
|
|
153
157
|
distanceIn,
|
|
154
158
|
distanceOut,
|
|
155
|
-
timeIn
|
|
156
|
-
timeOut: (24 * 60 * 60) -
|
|
159
|
+
timeIn,
|
|
160
|
+
timeOut: (24 * 60 * 60 * 1000) - timeIn
|
|
157
161
|
})
|
|
158
162
|
}
|
|
159
163
|
|
|
@@ -169,7 +173,7 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
169
173
|
device: d,
|
|
170
174
|
from,
|
|
171
175
|
to,
|
|
172
|
-
geofences:
|
|
176
|
+
geofences: result
|
|
173
177
|
})
|
|
174
178
|
}
|
|
175
179
|
}
|
|
@@ -179,9 +183,9 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
179
183
|
return devicesResult
|
|
180
184
|
}
|
|
181
185
|
|
|
182
|
-
function analyseAlertsGroupGeofences (alerts, deviceRoute) {
|
|
186
|
+
function analyseAlertsGroupGeofences (alerts, deviceRoute, from, to) {
|
|
183
187
|
const zoneInOutData = []
|
|
184
|
-
const zoneInData = {}
|
|
188
|
+
const zoneInData = { inCount: 0 }
|
|
185
189
|
|
|
186
190
|
alerts.forEach(a => {
|
|
187
191
|
if (!a.position) {
|
|
@@ -197,9 +201,31 @@ function analyseAlertsGroupGeofences (alerts, deviceRoute) {
|
|
|
197
201
|
return
|
|
198
202
|
}
|
|
199
203
|
if (a.type === 'geofenceExit') {
|
|
204
|
+
if (zoneInData.inCount === 0) {
|
|
205
|
+
zoneInOutData.splice(0, zoneInOutData.length)
|
|
206
|
+
const totalInTime = new Date(a.position.fixTime).getTime() - from.getTime()
|
|
207
|
+
const outDate = new Date(a.position.fixTime).getTime()
|
|
208
|
+
const routeIn = deviceRoute.filter(p =>
|
|
209
|
+
new Date(p.fixTime).getTime() >= from &&
|
|
210
|
+
new Date(p.fixTime).getTime() < outDate
|
|
211
|
+
)
|
|
212
|
+
const routeAfterOut = deviceRoute.filter(p =>
|
|
213
|
+
new Date(p.fixTime).getTime() >= outDate &&
|
|
214
|
+
new Date(p.fixTime).getTime() < getNextIn(outDate, alerts, undefined, deviceRoute)
|
|
215
|
+
)
|
|
216
|
+
const distanceOut = calculateDistance(routeAfterOut)
|
|
217
|
+
zoneInOutData.push({
|
|
218
|
+
outTime: a.position,
|
|
219
|
+
totalTime: totalInTime,
|
|
220
|
+
distanceIn: calculateDistance(routeIn),
|
|
221
|
+
distanceOut
|
|
222
|
+
})
|
|
223
|
+
return
|
|
224
|
+
}
|
|
225
|
+
|
|
200
226
|
zoneInData.inCount--
|
|
201
227
|
if (zoneInData.inCount === 0) {
|
|
202
|
-
const totalInTime =
|
|
228
|
+
const totalInTime = new Date(a.position.fixTime).getTime() - new Date(zoneInData.inTime.position.fixTime).getTime()
|
|
203
229
|
const inDate = new Date(zoneInData.inTime.position.fixTime).getTime()
|
|
204
230
|
const outDate = new Date(a.position.fixTime).getTime()
|
|
205
231
|
const routeAfterOut = deviceRoute.filter(p =>
|
|
@@ -216,8 +242,7 @@ function analyseAlertsGroupGeofences (alerts, deviceRoute) {
|
|
|
216
242
|
outTime: a.position,
|
|
217
243
|
totalTime: totalInTime,
|
|
218
244
|
distanceIn: calculateDistance(routeIn),
|
|
219
|
-
distanceOut
|
|
220
|
-
stopped: routeIn.filter(p => !p.attributes.ignition).length > 0
|
|
245
|
+
distanceOut
|
|
221
246
|
})
|
|
222
247
|
zoneInData.inTime = undefined
|
|
223
248
|
}
|
|
@@ -225,7 +250,17 @@ function analyseAlertsGroupGeofences (alerts, deviceRoute) {
|
|
|
225
250
|
})
|
|
226
251
|
|
|
227
252
|
if (zoneInData.inTime) {
|
|
228
|
-
|
|
253
|
+
const totalInTime = to.getTime() - new Date(zoneInData.inTime.position.fixTime).getTime()
|
|
254
|
+
const routeIn = deviceRoute.filter(p =>
|
|
255
|
+
new Date(p.fixTime).getTime() >= new Date(zoneInData.inTime.position.fixTime).getTime() &&
|
|
256
|
+
new Date(p.fixTime).getTime() < to.getTime()
|
|
257
|
+
)
|
|
258
|
+
zoneInOutData.push({
|
|
259
|
+
inTime: zoneInData.inTime.position,
|
|
260
|
+
distanceIn: calculateDistance(routeIn),
|
|
261
|
+
distanceOut: 0,
|
|
262
|
+
totalTime: totalInTime
|
|
263
|
+
})
|
|
229
264
|
}
|
|
230
265
|
return zoneInOutData
|
|
231
266
|
}
|
|
@@ -402,10 +437,10 @@ async function exportZoneReportToPDF (userData, reportData) {
|
|
|
402
437
|
convertToLocaleDateString(a.date, userData.user.attributes.lang, userData.user.attributes.timezone),
|
|
403
438
|
a.firstIn ? convertToLocaleTimeString(a.firstIn, userData.user.attributes.lang, userData.user.attributes.timezone) : '-',
|
|
404
439
|
a.lastOut ? convertToLocaleTimeString(a.lastOut, userData.user.attributes.lang, userData.user.attributes.timezone) : '-',
|
|
405
|
-
a.distanceIn.
|
|
406
|
-
a.timeIn ? convertMS(a.timeIn
|
|
407
|
-
a.distanceOut.
|
|
408
|
-
a.timeOut ? convertMS(a.timeOut
|
|
440
|
+
a.distanceIn.toFixed(0),
|
|
441
|
+
a.timeIn ? convertMS(a.timeIn, false) : '',
|
|
442
|
+
a.distanceOut.toFixed(0),
|
|
443
|
+
a.timeOut ? convertMS(a.timeOut, false) : ''
|
|
409
444
|
]
|
|
410
445
|
data.push(temp)
|
|
411
446
|
})
|
|
@@ -427,9 +462,9 @@ async function exportZoneReportToPDF (userData, reportData) {
|
|
|
427
462
|
? [
|
|
428
463
|
'Total:' + d.days.length,
|
|
429
464
|
'', '',
|
|
430
|
-
d.days.reduce((a, b) => a + b.distanceIn, 0).
|
|
465
|
+
d.days.reduce((a, b) => a + b.distanceIn, 0).toFixed(0),
|
|
431
466
|
'',
|
|
432
|
-
d.days.reduce((a, b) => a + b.distanceOut, 0).
|
|
467
|
+
d.days.reduce((a, b) => a + b.distanceOut, 0).toFixed(0)
|
|
433
468
|
]
|
|
434
469
|
: [
|
|
435
470
|
'Total:' + d.geofences.length
|
|
@@ -503,10 +538,10 @@ function exportZoneReportToExcel (userData, reportData) {
|
|
|
503
538
|
date: convertToLocaleDateString(a.date, userData.user.attributes.lang, userData.user.attributes.timezone),
|
|
504
539
|
firstIn: a.firstIn ? convertToLocaleTimeString(a.firstIn, userData.user.attributes.lang, userData.user.attributes.timezone) : '-',
|
|
505
540
|
lastOut: a.lastOut ? convertToLocaleTimeString(a.lastOut, userData.user.attributes.lang, userData.user.attributes.timezone) : '-',
|
|
506
|
-
distanceIn: a.distanceIn
|
|
507
|
-
distanceOut: a.distanceOut
|
|
508
|
-
timeIn: convertMS(a.timeIn
|
|
509
|
-
timeOut: convertMS(a.timeOut
|
|
541
|
+
distanceIn: a.distanceIn.toFixed(0),
|
|
542
|
+
distanceOut: a.distanceOut.toFixed(0),
|
|
543
|
+
timeIn: convertMS(a.timeIn),
|
|
544
|
+
timeOut: convertMS(a.timeOut)
|
|
510
545
|
}
|
|
511
546
|
}))
|
|
512
547
|
: data.concat(d.geofences.map(a => {
|