fleetmap-reports 1.0.898 → 1.0.900
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/partnerReports/performance-report.js +1 -1
- package/src/tests/activity.test.js +0 -10
- package/src/tests/index.test.js +3 -11
- package/src/tests/performance.test.js +0 -12
- package/src/tests/zones.test.js +0 -12
- package/src/util/trips.js +1 -1
- package/src/util/utils.js +5 -1
- package/src/zone-report.js +20 -20
package/package.json
CHANGED
|
@@ -144,7 +144,7 @@ function getDeviceData (allInOne, d) {
|
|
|
144
144
|
? a.map((p, index) => index === 0 ? 0 : new Date(p.fixTime).getTime() - new Date(a[index - 1].fixTime).getTime()).reduce((a, b) => a + b, 0)
|
|
145
145
|
: 0).reduce((a, b) => a + b, 0)
|
|
146
146
|
const economicDistance = economicRPMSections.map(a => a.length > 1
|
|
147
|
-
? calculateDistance(a)
|
|
147
|
+
? calculateDistance(a, d.attributes['report.ignoreOdometer'])
|
|
148
148
|
: 0).reduce((a, b) => a + b, 0)
|
|
149
149
|
const economicConsumption = economicRPMSections.map(a => a.length > 1
|
|
150
150
|
? a[a.length - 1].attributes.fuelUsed - a[0].attributes.fuelUsed
|
|
@@ -72,14 +72,4 @@ describe('activity report', function () {
|
|
|
72
72
|
console.log(device)
|
|
73
73
|
assert.equal(device.summary.reduce((a, b) => a + b.convertedSpentFuel, 0), 168.79999999999995)
|
|
74
74
|
}, 800000)
|
|
75
|
-
it('Activity test performance', async () => {
|
|
76
|
-
const report = await getReports('q.trans', 'quality1214')
|
|
77
|
-
const userData = await report.getUserData()
|
|
78
|
-
console.log(userData)
|
|
79
|
-
userData.groupByDay = true
|
|
80
|
-
const data = await report.activityReport(new Date(2023, 7, 1, 0, 0, 0, 0),
|
|
81
|
-
new Date(2023, 31, 5, 23, 59, 59, 0),
|
|
82
|
-
userData)
|
|
83
|
-
assert.equal(data.length, 1)
|
|
84
|
-
}, 8000000)
|
|
85
75
|
})
|
package/src/tests/index.test.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
const { getReports } = require('./index')
|
|
3
3
|
const assert = require('assert')
|
|
4
4
|
const utils = require('../util/utils')
|
|
5
|
-
const { createGPSJumpReport } = require('../partnerReports/gpsjump-report')
|
|
6
5
|
|
|
7
6
|
// eslint-disable-next-line no-undef
|
|
8
7
|
describe('Test_Reports', function () {
|
|
@@ -19,19 +18,12 @@ describe('Test_Reports', function () {
|
|
|
19
18
|
const pdf = await report.speedingReportToPDF(userData, data[0])
|
|
20
19
|
pdf.save()
|
|
21
20
|
}, 40000)
|
|
21
|
+
|
|
22
22
|
it('converts madrid time', async () => {
|
|
23
23
|
assert.equal(false, utils.isClientSide())
|
|
24
24
|
console.log(utils.convertToLocaleString(new Date(), 'es-CL', 'Europe/Madrid'))
|
|
25
25
|
})
|
|
26
|
-
|
|
27
|
-
const report = await getReports('HASSANE', 'movitec.1637')
|
|
28
|
-
const userData = await report.getUserData()
|
|
29
|
-
userData.devices = userData.devices.filter(d => d.id === 148725)
|
|
30
|
-
const data = await createGPSJumpReport(new Date(2023, 8, 22, 0, 0, 0, 0),
|
|
31
|
-
new Date(2023, 8, 24, 23, 59, 59, 0),
|
|
32
|
-
userData, report.traccar)
|
|
33
|
-
console.log(data)
|
|
34
|
-
}, 40000)
|
|
26
|
+
|
|
35
27
|
it('Idle by device', async () => {
|
|
36
28
|
const report = await getReports()
|
|
37
29
|
const userData = await report.getUserData()
|
|
@@ -62,7 +54,7 @@ describe('Test_Reports', function () {
|
|
|
62
54
|
const totalIdleTime = driver.idleEvents.reduce((a, b) => a + b.idleTime, 0)
|
|
63
55
|
assert.equal(driver.idleEvents.length, 15) // Total Alerts
|
|
64
56
|
assert.equal(totalIdleTime, 16000) // Total Duration
|
|
65
|
-
}, 20000)
|
|
57
|
+
}, 20000)
|
|
66
58
|
// eslint-disable-next-line no-undef
|
|
67
59
|
it('test allinone', async () => {
|
|
68
60
|
console.log('Start')
|
|
@@ -2,7 +2,6 @@ const { getReports } = require('./index')
|
|
|
2
2
|
const { createPerformanceReport } = require('../partnerReports/performance-report')
|
|
3
3
|
const assert = require('assert')
|
|
4
4
|
const { convertMS } = require('../util/utils')
|
|
5
|
-
const {createDailyUseReport} = require("../partnerReports/dailyuse-report");
|
|
6
5
|
// eslint-disable-next-line no-undef
|
|
7
6
|
describe('performance', function () {
|
|
8
7
|
// eslint-disable-next-line no-undef
|
|
@@ -34,15 +33,4 @@ describe('performance', function () {
|
|
|
34
33
|
console.log(data)
|
|
35
34
|
assert.equal(data[0].consumption, 168.51989999999998)
|
|
36
35
|
}, 8000000)
|
|
37
|
-
|
|
38
|
-
it('dailyuse report inofleet', async () => {
|
|
39
|
-
const report = await getReports()
|
|
40
|
-
const userData = await report.getUserData()
|
|
41
|
-
const data = await createDailyUseReport(
|
|
42
|
-
new Date(Date.UTC(2023, 9, 1, 0, 0, 0, 0)),
|
|
43
|
-
new Date(Date.UTC(2023, 9, 1, 23, 59, 59, 0)),
|
|
44
|
-
userData,
|
|
45
|
-
report.traccar)
|
|
46
|
-
console.log(data)
|
|
47
|
-
}, 8000000)
|
|
48
36
|
})
|
package/src/tests/zones.test.js
CHANGED
|
@@ -27,18 +27,6 @@ describe('zones', function () {
|
|
|
27
27
|
console.log('result', result)
|
|
28
28
|
}, 4000000)
|
|
29
29
|
|
|
30
|
-
it('works with afriquia', async () => {
|
|
31
|
-
const report = await getReports(process.env.USER_AFRIQUIA, process.env.PASS_AFRIQUIA)
|
|
32
|
-
const userData = await report.getUserData()
|
|
33
|
-
console.log(userData.devices.length)
|
|
34
|
-
console.log(userData.geofences)
|
|
35
|
-
const result = await report.zoneReport(
|
|
36
|
-
new Date(Date.UTC(2023, 5, 11, 0, 0, 0, 0)),
|
|
37
|
-
new Date(Date.UTC(2023, 5, 11, 23, 59, 59, 0)),
|
|
38
|
-
userData)
|
|
39
|
-
console.log('result', result)
|
|
40
|
-
}, 4000000)
|
|
41
|
-
|
|
42
30
|
// eslint-disable-next-line no-undef
|
|
43
31
|
it('works with casais', async () => {
|
|
44
32
|
const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
|
package/src/util/trips.js
CHANGED
|
@@ -120,7 +120,7 @@ function calculateTrip (device, route) {
|
|
|
120
120
|
return {
|
|
121
121
|
deviceId: device.id,
|
|
122
122
|
deviceName: device.name,
|
|
123
|
-
distance: calculateDistance(route) * 1000,
|
|
123
|
+
distance: calculateDistance(route, device.attributes['report.ignoreOdometer']) * 1000,
|
|
124
124
|
averageSpeed: Math.round((route.map(p => p.speed).reduce((a, b) => a + b, 0)) / route.length),
|
|
125
125
|
maxSpeed: route.map(p => p.speed).reduce(function (a, b) { return Math.max(a, b) }),
|
|
126
126
|
spentFuel: 0,
|
package/src/util/utils.js
CHANGED
|
@@ -241,7 +241,11 @@ exports.getLogo = (user) => {
|
|
|
241
241
|
}
|
|
242
242
|
exports.convertToFeature = convertToFeature
|
|
243
243
|
exports.convertPositionToFeature = convertPositionToFeature
|
|
244
|
-
exports.calculateDistance = (positions) => {
|
|
244
|
+
exports.calculateDistance = (positions, ignoreOdometer) => {
|
|
245
|
+
if (!ignoreOdometer && positions.length > 1 && positions[0].attributes.odometer && positions[positions.length - 1].attributes.odometer) {
|
|
246
|
+
return (positions[positions.length - 1].attributes.odometer - positions[0].attributes.odometer) / 1000
|
|
247
|
+
}
|
|
248
|
+
|
|
245
249
|
return positions
|
|
246
250
|
.sort((a, b) => new Date(a.fixTime).getTime() - new Date(b.fixTime).getTime())
|
|
247
251
|
.map(p => [p.longitude, p.latitude])
|
package/src/zone-report.js
CHANGED
|
@@ -93,7 +93,7 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
93
93
|
for (const d of devices) {
|
|
94
94
|
const alerts = data.alerts.filter(t => t.deviceId === d.id)
|
|
95
95
|
const deviceRoute = data.route.filter(p => p.deviceId === d.id)
|
|
96
|
-
const zoneInOutData = analyseAlerts(alerts, deviceRoute, userData, from, to).filter(d => !userData.onlyWithStop || d.stopped)
|
|
96
|
+
const zoneInOutData = analyseAlerts(alerts, deviceRoute, userData, from, to, d).filter(d => !userData.onlyWithStop || d.stopped)
|
|
97
97
|
|
|
98
98
|
if (userData.groupByDay || userData.zonesByColumn) {
|
|
99
99
|
const dates = getDates(from, to, userData.user.attributes.timezone)
|
|
@@ -115,8 +115,8 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
115
115
|
const lastOut = zoneInOutDayData.slice().reverse().find(z => z.outTime && new Date(z.outTime.fixTime) < toByDay)
|
|
116
116
|
|
|
117
117
|
const timeIn = calculateTimeIn(zoneInOutDayData, fromByDay, from, toByDay, to)
|
|
118
|
-
const distanceIn = calculateDistanceIn(zoneInOutDayData, deviceRoute, dayRoute, fromByDay, toByDay, to)
|
|
119
|
-
const distanceOut = calculateDistanceOut(zoneInOutDayData, dayRoute, fromByDay, toByDay, 'distanceOut')
|
|
118
|
+
const distanceIn = calculateDistanceIn(zoneInOutDayData, deviceRoute, dayRoute, fromByDay, toByDay, to, d)
|
|
119
|
+
const distanceOut = calculateDistanceOut(zoneInOutDayData, dayRoute, fromByDay, toByDay, 'distanceOut', d)
|
|
120
120
|
|
|
121
121
|
dataByDay.push({
|
|
122
122
|
date,
|
|
@@ -145,7 +145,7 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
145
145
|
const zoneInOutDayData = zoneInOutData.filter(z => (!z.inTime || (new Date(z.inTime.fixTime) < toByDay)) &&
|
|
146
146
|
(!z.outTime || (new Date(z.outTime.fixTime) > fromByDay)))
|
|
147
147
|
|
|
148
|
-
const distanceOut = calculateDistanceOut(zoneInOutDayData, deviceRoute, fromByDay, toByDay, 'distanceOutAny')
|
|
148
|
+
const distanceOut = calculateDistanceOut(zoneInOutDayData, deviceRoute, fromByDay, toByDay, 'distanceOutAny', d)
|
|
149
149
|
|
|
150
150
|
const geofences = geofencesData.map(g => {
|
|
151
151
|
const day = g.days.find(day => day.date === date)
|
|
@@ -265,7 +265,7 @@ function getAnyNextIn (outDate, alerts, deviceRoute) {
|
|
|
265
265
|
new Date(deviceRoute.slice(-1)[0].fixTime).getTime()
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
function calculateDistanceIn (zoneInOutDayData, deviceRoute, dayRoute, fromByDay, toByDay, to) {
|
|
268
|
+
function calculateDistanceIn (zoneInOutDayData, deviceRoute, dayRoute, fromByDay, toByDay, to, device) {
|
|
269
269
|
let distanceIn = zoneInOutDayData.length && dayRoute.length ? zoneInOutDayData.reduce((a, b) => a + (b.distanceIn || 0), 0) : 0
|
|
270
270
|
|
|
271
271
|
if (zoneInOutDayData.length) {
|
|
@@ -273,21 +273,21 @@ function calculateDistanceIn (zoneInOutDayData, deviceRoute, dayRoute, fromByDay
|
|
|
273
273
|
if (!zoneInOutDayData[0].inTime || new Date(zoneInOutDayData[0].inTime.fixTime) < fromByDay) {
|
|
274
274
|
const routeDayBefore = deviceRoute.filter(p => (!zoneInOutDayData[0].inTime || (new Date(p.fixTime) >= new Date(zoneInOutDayData[0].inTime.fixTime))) &&
|
|
275
275
|
new Date(p.fixTime) < fromByDay)
|
|
276
|
-
distanceIn = distanceIn - calculateDistance(routeDayBefore)
|
|
276
|
+
distanceIn = distanceIn - calculateDistance(routeDayBefore, device.attributes['report.ignoreOdometer'])
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
// Check if the last entry ends only on the next day
|
|
280
280
|
if (!zoneInOutDayData[zoneInOutDayData.length - 1].outTime || new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime) > toByDay) {
|
|
281
281
|
const outTime = zoneInOutDayData[zoneInOutDayData.length - 1].outTime ? new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime) : to
|
|
282
282
|
const routeDayAfter = deviceRoute.filter(p => new Date(p.fixTime) < outTime && new Date(p.fixTime) > toByDay)
|
|
283
|
-
distanceIn = distanceIn - calculateDistance(routeDayAfter)
|
|
283
|
+
distanceIn = distanceIn - calculateDistance(routeDayAfter, device.attributes['report.ignoreOdometer'])
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
return distanceIn
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
function calculateDistanceOut (zoneInOutDayData, dayRoute, fromByDay, toByDay, field) {
|
|
290
|
+
function calculateDistanceOut (zoneInOutDayData, dayRoute, fromByDay, toByDay, field, device) {
|
|
291
291
|
if (zoneInOutDayData.length) {
|
|
292
292
|
let distanceOut = zoneInOutDayData.reduce((a, b) => a + (b[field] || 0), 0) -
|
|
293
293
|
(zoneInOutDayData[zoneInOutDayData.length - 1][field] || 0)
|
|
@@ -298,23 +298,23 @@ function calculateDistanceOut (zoneInOutDayData, dayRoute, fromByDay, toByDay, f
|
|
|
298
298
|
new Date(p.fixTime).getTime() < new Date(zoneInOutDayData[0].inTime.fixTime).getTime() &&
|
|
299
299
|
new Date(p.fixTime).getTime() >= fromByDay.getTime()
|
|
300
300
|
)
|
|
301
|
-
distanceOut = distanceOut + calculateDistance(routeOut)
|
|
301
|
+
distanceOut = distanceOut + calculateDistance(routeOut, device.attributes['report.ignoreOdometer'])
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
if (zoneInOutDayData[zoneInOutDayData.length - 1].outTime && new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime) < toByDay) {
|
|
305
305
|
const routeOut = dayRoute.filter(p =>
|
|
306
306
|
new Date(p.fixTime) >= new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime).getTime() &&
|
|
307
307
|
new Date(p.fixTime) < toByDay.getTime())
|
|
308
|
-
distanceOut = distanceOut + calculateDistance(routeOut)
|
|
308
|
+
distanceOut = distanceOut + calculateDistance(routeOut, device.attributes['report.ignoreOdometer'])
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
return distanceOut
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
return calculateDistance(dayRoute.filter(p => new Date(p.fixTime) >= fromByDay && new Date(p.fixTime) < toByDay))
|
|
314
|
+
return calculateDistance(dayRoute.filter(p => new Date(p.fixTime) >= fromByDay && new Date(p.fixTime) < toByDay), device.attributes['report.ignoreOdometer'])
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
function analyseAlerts (alerts, deviceRoute, userData, from, to) {
|
|
317
|
+
function analyseAlerts (alerts, deviceRoute, userData, from, to, device) {
|
|
318
318
|
const zoneInOutData = []
|
|
319
319
|
const zoneInData = {}
|
|
320
320
|
|
|
@@ -338,14 +338,14 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
|
|
|
338
338
|
new Date(p.fixTime).getTime() < nextIn
|
|
339
339
|
)
|
|
340
340
|
const totalOutTime = nextIn - outDate
|
|
341
|
-
const distanceOut = calculateDistance(routeAfterOut)
|
|
341
|
+
const distanceOut = calculateDistance(routeAfterOut, device.attributes['report.ignoreOdometer'])
|
|
342
342
|
|
|
343
343
|
const anyNextIn = getAnyNextIn(outDate, alerts, deviceRoute)
|
|
344
344
|
const routeAfterOutAndBeforeAnyNextIn = deviceRoute.filter(p =>
|
|
345
345
|
new Date(p.fixTime).getTime() >= outDate &&
|
|
346
|
-
new Date(p.fixTime).getTime()
|
|
346
|
+
new Date(p.fixTime).getTime() <= anyNextIn
|
|
347
347
|
)
|
|
348
|
-
const distanceOutAny = Object.keys(zoneInData).length < 2 ? Math.round(calculateDistance(routeAfterOutAndBeforeAnyNextIn)) : 0
|
|
348
|
+
const distanceOutAny = Object.keys(zoneInData).length < 2 ? Math.round(calculateDistance(routeAfterOutAndBeforeAnyNextIn, device.attributes['report.ignoreOdometer'])) : 0
|
|
349
349
|
|
|
350
350
|
if (zoneInData[a.geofenceId]) {
|
|
351
351
|
const totalInTime = new Date(a.position.fixTime).getTime() - new Date(zoneInData[a.geofenceId].position.fixTime).getTime()
|
|
@@ -359,7 +359,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
|
|
|
359
359
|
outTime: a.position,
|
|
360
360
|
totalInTime,
|
|
361
361
|
totalOutTime,
|
|
362
|
-
distanceIn: calculateDistance(routeIn),
|
|
362
|
+
distanceIn: calculateDistance(routeIn, device.attributes['report.ignoreOdometer']),
|
|
363
363
|
distanceOut,
|
|
364
364
|
distanceOutAny,
|
|
365
365
|
geofenceName: geofence.name,
|
|
@@ -380,7 +380,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
|
|
|
380
380
|
geofenceId: geofence.id,
|
|
381
381
|
totalInTime,
|
|
382
382
|
totalOutTime,
|
|
383
|
-
distanceIn: calculateDistance(routeIn),
|
|
383
|
+
distanceIn: calculateDistance(routeIn, device.attributes['report.ignoreOdometer']),
|
|
384
384
|
driverName: '',
|
|
385
385
|
distanceOut,
|
|
386
386
|
distanceOutAny
|
|
@@ -401,7 +401,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
|
|
|
401
401
|
zoneInOutData.push({
|
|
402
402
|
inTime: zoneInData[i].position,
|
|
403
403
|
totalInTime,
|
|
404
|
-
distanceIn: calculateDistance(routeIn),
|
|
404
|
+
distanceIn: calculateDistance(routeIn, device.attributes['report.ignoreOdometer']),
|
|
405
405
|
geofenceName: geofence.name,
|
|
406
406
|
geofenceId: geofence.id,
|
|
407
407
|
driverName: zoneInData[i].position.driverName
|
|
@@ -413,8 +413,8 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
|
|
|
413
413
|
if (!zoneInOutData.length && userData.groupByDay) {
|
|
414
414
|
const geofenceIn = alerts.find(a => a.type === 'geofenceIn')
|
|
415
415
|
zoneInOutData.push({
|
|
416
|
-
distanceIn: geofenceIn ? calculateDistance(deviceRoute) : 0,
|
|
417
|
-
distanceOut: !geofenceIn ? calculateDistance(deviceRoute) : 0,
|
|
416
|
+
distanceIn: geofenceIn ? calculateDistance(deviceRoute, device.attributes['report.ignoreOdometer']) : 0,
|
|
417
|
+
distanceOut: !geofenceIn ? calculateDistance(deviceRoute, device.attributes['report.ignoreOdometer']) : 0,
|
|
418
418
|
totalTime: to.getTime() - from.getTime()
|
|
419
419
|
})
|
|
420
420
|
}
|