fleetmap-reports 1.0.763 → 1.0.765
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
|
@@ -7,47 +7,108 @@ async function createPerformanceReport (from, to, userData, traccar) {
|
|
|
7
7
|
const reportData = []
|
|
8
8
|
|
|
9
9
|
const devices = userData.devices
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
|
|
10
|
+
|
|
11
|
+
if (devices.length !== 1) {
|
|
12
|
+
const sliced = automaticReports.sliceArray(devices, 5)
|
|
13
|
+
let deviceCount = 0
|
|
14
|
+
for (const slice of sliced) {
|
|
15
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, false, false, deviceCount, devices.length)
|
|
16
|
+
|
|
17
|
+
slice.forEach(d => {
|
|
18
|
+
const { endTripData, canDriverStyle } = getDeviceXpertData(allInOne, d)
|
|
19
|
+
|
|
20
|
+
const deviceData = {
|
|
21
|
+
device: d.name,
|
|
22
|
+
drivingTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeDriving - endTripData[0].totalTimeDriving : 0,
|
|
23
|
+
idleTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeInIdle - endTripData[0].totalTimeInIdle : 0,
|
|
24
|
+
drivingConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionDriving - endTripData[0].totalFuelConsumptionDriving : 0,
|
|
25
|
+
idleConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionInIdle - endTripData[0].totalFuelConsumptionInIdle : 0,
|
|
26
|
+
drivingDistance: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelled - endTripData[0].totalDistanceTravelled : 0,
|
|
27
|
+
cruiseControlTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeWithCruiseControl - endTripData[0].totalTimeWithCruiseControl : 0,
|
|
28
|
+
cruiseControlConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionWithCruiseControl - endTripData[0].totalFuelConsumptionWithCruiseControl : 0,
|
|
29
|
+
cruiseControlDistance: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelledWithCruiseControl - endTripData[0].totalDistanceTravelledWithCruiseControl : 0,
|
|
30
|
+
economicTime: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeInEcoRange - canDriverStyle[0].totalTimeInEcoRange : 0,
|
|
31
|
+
economicConsumption: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalFuelConsumptionInEcoRange - canDriverStyle[0].totalFuelConsumptionInEcoRange : 0,
|
|
32
|
+
economicDistance: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalDistanceInEcoRange - canDriverStyle[0].totalDistanceInEcoRange : 0,
|
|
33
|
+
highEngineRPM: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeWithHighRpmAndTorque - canDriverStyle[0].totalTimeWithHighRpmAndTorque : 0,
|
|
34
|
+
hardBreaking: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshBrakes - canDriverStyle[0].totalNumberOfHarshBrakes : 0,
|
|
35
|
+
hardAcceleration: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshAccelerations - canDriverStyle[0].totalNumberOfHarshAccelerations : 0
|
|
36
|
+
}
|
|
37
|
+
reportData.push(deviceData)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
deviceCount = deviceCount + slice.length
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, userData.devices, true, true, false, false)
|
|
44
|
+
|
|
45
|
+
const device = userData.devices[0]
|
|
46
|
+
const { endTripData, canDriverStyle } = getDeviceXpertData(allInOne, device)
|
|
47
|
+
|
|
48
|
+
const drivingTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeDriving - endTripData[0].totalTimeDriving : 0
|
|
49
|
+
const idleTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeInIdle - endTripData[0].totalTimeInIdle : 0
|
|
50
|
+
const cruiseControlTime = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeWithCruiseControl - endTripData[0].totalTimeWithCruiseControl : 0
|
|
51
|
+
const economicTime = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeInEcoRange - canDriverStyle[0].totalTimeInEcoRange : 0
|
|
52
|
+
const highEngineRPM = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeWithHighRpmAndTorque - canDriverStyle[0].totalTimeWithHighRpmAndTorque : 0
|
|
53
|
+
const hardBreaking = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshBrakes - canDriverStyle[0].totalNumberOfHarshBrakes : 0
|
|
54
|
+
const hardAcceleration = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshAccelerations - canDriverStyle[0].totalNumberOfHarshAccelerations : 0
|
|
55
|
+
|
|
56
|
+
const drivingConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionDriving - endTripData[0].totalFuelConsumptionDriving : 0
|
|
57
|
+
const idleConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionInIdle - endTripData[0].totalFuelConsumptionInIdle : 0
|
|
58
|
+
const cruiseControlConsumption = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionWithCruiseControl - endTripData[0].totalFuelConsumptionWithCruiseControl : 0
|
|
59
|
+
const economicConsumption = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalFuelConsumptionInEcoRange - canDriverStyle[0].totalFuelConsumptionInEcoRange : 0
|
|
60
|
+
|
|
61
|
+
const drivingDistance = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelled - endTripData[0].totalDistanceTravelled : 0
|
|
62
|
+
const cruiseControlDistance = endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelledWithCruiseControl - endTripData[0].totalDistanceTravelledWithCruiseControl : 0
|
|
63
|
+
const economicDistance = canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalDistanceInEcoRange - canDriverStyle[0].totalDistanceInEcoRange : 0
|
|
64
|
+
|
|
65
|
+
const totalTime = drivingTime + idleTime
|
|
66
|
+
const totalConsumption = drivingConsumption + idleConsumption
|
|
67
|
+
|
|
68
|
+
const totalData = getRowData(device, 'Totale', totalTime, totalConsumption, drivingDistance, drivingDistance > 0 ? totalConsumption * 100 / drivingDistance : 0)
|
|
69
|
+
const drivingData = getRowData(device, 'Conduite', drivingTime, drivingConsumption, drivingDistance, drivingDistance > 0 ? drivingConsumption * 100 / drivingDistance : 0)
|
|
70
|
+
const idleData = getRowData(device, 'Ralenti', idleTime, idleConsumption, '', totalConsumption > 0 ? idleConsumption * 100 / totalConsumption : 0)
|
|
71
|
+
const economicData = getRowData(device, 'Économique', economicTime, economicConsumption, economicDistance, totalTime > 0 ? economicTime * 100 / totalTime : 0)
|
|
72
|
+
const cruiseControlData = getRowData(device, 'Économique', cruiseControlTime, cruiseControlConsumption, cruiseControlDistance, totalTime > 0 ? cruiseControlTime * 100 / totalTime : 0)
|
|
73
|
+
const highEngineRPMData = getRowData(device, 'Tour moteur élevé', highEngineRPM, '', '', totalTime > 0 ? highEngineRPM * 100 / totalTime : 0)
|
|
74
|
+
const hardBreakingData = getRowData(device, 'Freinage brusque', hardBreaking, '', '', drivingDistance > 0 ? hardBreaking * 100 / drivingDistance : 0)
|
|
75
|
+
const hardAccelerationData = getRowData(device, 'Accéleration brusque', hardAcceleration, '', '', drivingDistance > 0 ? hardAcceleration * 100 / drivingDistance : 0)
|
|
76
|
+
|
|
77
|
+
reportData.push(totalData)
|
|
78
|
+
reportData.push(drivingData)
|
|
79
|
+
reportData.push(idleData)
|
|
80
|
+
reportData.push(economicData)
|
|
81
|
+
reportData.push(cruiseControlData)
|
|
82
|
+
reportData.push(highEngineRPMData)
|
|
83
|
+
reportData.push(hardBreakingData)
|
|
84
|
+
reportData.push(hardAccelerationData)
|
|
49
85
|
}
|
|
50
86
|
return reportData
|
|
51
87
|
}
|
|
52
88
|
|
|
89
|
+
function getDeviceXpertData (allInOne, d) {
|
|
90
|
+
const deviceRoute = allInOne.route.filter(t => t.deviceId === d.id)
|
|
91
|
+
const deviceTrips = allInOne.trips.filter(t => t.deviceId === d.id)
|
|
92
|
+
|
|
93
|
+
const uncompletedTrip = getUncompletedTrip(d, deviceRoute, deviceTrips)
|
|
94
|
+
if (uncompletedTrip) {
|
|
95
|
+
deviceTrips.push(uncompletedTrip)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
|
|
99
|
+
const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
|
|
100
|
+
return { endTripData, canDriverStyle }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function getRowData (device, description, time, consumption, economicDistance, totalTime) {
|
|
104
|
+
return {
|
|
105
|
+
device: device.name,
|
|
106
|
+
description,
|
|
107
|
+
time,
|
|
108
|
+
consumption,
|
|
109
|
+
distance: economicDistance,
|
|
110
|
+
indicator: totalTime > 0 ? time * 100 / totalTime : 0
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
53
114
|
exports.createPerformanceReport = createPerformanceReport
|
|
@@ -2,15 +2,14 @@ const { getReports } = require('./index')
|
|
|
2
2
|
const { createPerformanceReport } = require('../partnerReports/performance-report')
|
|
3
3
|
// eslint-disable-next-line no-undef
|
|
4
4
|
describe('performance', function () {
|
|
5
|
-
this.timeout(500000)
|
|
6
5
|
// eslint-disable-next-line no-undef
|
|
7
6
|
it('performance report', async () => {
|
|
8
7
|
const report = await getReports()
|
|
9
8
|
const userData = await report.getUserData()
|
|
10
|
-
userData.devices = userData.devices.filter(d => d.
|
|
9
|
+
userData.devices = userData.devices.filter(d => d.attributes.xpert)
|
|
11
10
|
const data = await createPerformanceReport(
|
|
12
|
-
new Date(Date.UTC(2023, 5,
|
|
13
|
-
new Date(Date.UTC(2023, 5,
|
|
11
|
+
new Date(Date.UTC(2023, 5, 10, 0, 0, 0, 0)),
|
|
12
|
+
new Date(Date.UTC(2023, 5, 20, 23, 59, 59, 0)),
|
|
14
13
|
userData,
|
|
15
14
|
report.traccar)
|
|
16
15
|
console.log(data)
|
package/src/tests/zones.test.js
CHANGED
|
@@ -2,7 +2,6 @@ const { getReports } = require('./index')
|
|
|
2
2
|
const assert = require('assert')
|
|
3
3
|
// eslint-disable-next-line no-undef
|
|
4
4
|
describe('zones', function () {
|
|
5
|
-
this.timeout(500000)
|
|
6
5
|
// eslint-disable-next-line no-undef
|
|
7
6
|
it('works with ellca', async () => {
|
|
8
7
|
const report = await getReports()
|
|
@@ -55,50 +54,14 @@ describe('zones', function () {
|
|
|
55
54
|
const userData = await report.getUserData()
|
|
56
55
|
userData.zonesByColumn = true
|
|
57
56
|
userData.devices = userData.devices.filter(d => d.name === 'G-1101-E Clio')
|
|
58
|
-
userData.geofences = userData.geofences.filter(g => g.name === 'baliza raio verde ')
|
|
57
|
+
userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde ')
|
|
58
|
+
userData.onlyWithKmsOut = true
|
|
59
59
|
const result = await report.zoneReport(
|
|
60
60
|
new Date(Date.UTC(2023, 0, 1, 0, 0, 0, 0)),
|
|
61
61
|
new Date(Date.UTC(2023, 0, 31, 23, 59, 59, 0)),
|
|
62
62
|
userData)
|
|
63
63
|
const first = result[0].devices[0].days[0]
|
|
64
64
|
console.log(first)
|
|
65
|
-
assert.equal(first.distanceOut,
|
|
66
|
-
}, 4000000)
|
|
67
|
-
|
|
68
|
-
// eslint-disable-next-line no-undef
|
|
69
|
-
it('works with casais 2', async () => {
|
|
70
|
-
const report = await getReports('mario.andre.moreira@casais.gi', 'Casais.23')
|
|
71
|
-
const userData = await report.getUserData()
|
|
72
|
-
userData.groupByDay = true
|
|
73
|
-
userData.devices = userData.devices.filter(d => d.name === 'G-2542-F Fiat Tipo')
|
|
74
|
-
userData.geofences = userData.geofences.filter(g => g.name === 'baliza raio verde ')
|
|
75
|
-
assert.equal(userData.geofences.length > 0, true)
|
|
76
|
-
assert.equal(userData.devices.length > 0, true)
|
|
77
|
-
const result = await report.zoneReport(
|
|
78
|
-
new Date(2023, 1, 27, 0, 0, 0, 0),
|
|
79
|
-
new Date(2023, 1, 27, 23, 59, 59, 0),
|
|
80
|
-
userData)
|
|
81
|
-
assert.equal(result[0].devices[0].geofences.length, 1)
|
|
82
|
-
assert.equal(result[0].devices[0].geofences[0].days.length, 1)
|
|
83
|
-
const first = result[0].devices[0].geofences[0].days[0]
|
|
84
|
-
assert.equal(first.firstIn, '2023-02-27T21:53:16.000+0000')
|
|
85
|
-
assert.equal(first.distanceIn, 93.03917199839687)
|
|
86
|
-
assert.equal(first.distanceOut, 819.6685737216337)
|
|
87
|
-
}, 4000000)
|
|
88
|
-
|
|
89
|
-
it('works with casais 3', async () => {
|
|
90
|
-
const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
|
|
91
|
-
const userData = await report.getUserData()
|
|
92
|
-
userData.zonesByColumn = true
|
|
93
|
-
userData.devices = userData.devices.filter(d => d.name === 'G-1101-E Clio')
|
|
94
|
-
userData.geofences = userData.geofences.filter(g => g.name === 'baliza raio verde ' || g.name === 'baliza raio amarelo ')
|
|
95
|
-
const result = await report.zoneReport(
|
|
96
|
-
new Date(Date.UTC(2023, 0, 29, 0, 0, 0, 0)),
|
|
97
|
-
new Date(Date.UTC(2023, 0, 31, 23, 59, 59, 0)),
|
|
98
|
-
userData)
|
|
99
|
-
const first = result[0].devices[0].geofences[0]
|
|
100
|
-
console.log(first)
|
|
101
|
-
assert.equal(first.name, 'baliza raio verde ')
|
|
102
|
-
assert.equal(first.distanceIn, '1069.343491503579')
|
|
65
|
+
assert.equal(first.distanceOut, 35.52274536571346)
|
|
103
66
|
}, 4000000)
|
|
104
67
|
})
|
package/src/zone-report.js
CHANGED
|
@@ -147,10 +147,11 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
147
147
|
const distanceOut = calculateDistanceOut(zoneInOutDayData, deviceRoute, fromByDay, toByDay, 'distanceOutAny')
|
|
148
148
|
|
|
149
149
|
const geofences = geofencesData.map(g => {
|
|
150
|
+
const day = g.days.find(day => day.date === date)
|
|
150
151
|
return {
|
|
151
152
|
geofenceId: g.geofenceId,
|
|
152
153
|
geofenceName: g.geofenceName,
|
|
153
|
-
distanceIn:
|
|
154
|
+
distanceIn: day && day.distanceIn
|
|
154
155
|
}
|
|
155
156
|
})
|
|
156
157
|
|