fleetmap-reports 1.0.755 → 1.0.757
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 +16 -16
- package/src/tests/zones.test.js +16 -0
- package/src/util/xpert.js +2 -0
- package/src/zone-report.js +47 -10
package/package.json
CHANGED
|
@@ -22,25 +22,25 @@ async function createPerformanceReport (from, to, userData, traccar) {
|
|
|
22
22
|
deviceTrips.push(uncompletedTrip)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m))
|
|
26
|
-
const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m))
|
|
25
|
+
const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
|
|
26
|
+
const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
|
|
27
27
|
|
|
28
28
|
const deviceData = {
|
|
29
29
|
device: d.name,
|
|
30
|
-
drivingTime: endTripData.
|
|
31
|
-
idleTime: endTripData.
|
|
32
|
-
drivingConsumption: endTripData.
|
|
33
|
-
idleConsumption: endTripData.
|
|
34
|
-
drivingDistance: endTripData.
|
|
35
|
-
cruiseControlTime: endTripData.
|
|
36
|
-
cruiseControlConsumption: endTripData.
|
|
37
|
-
cruiseControlDistance: endTripData.
|
|
38
|
-
economicTime: canDriverStyle.
|
|
39
|
-
economicConsumption: canDriverStyle.
|
|
40
|
-
economicDistance: canDriverStyle.
|
|
41
|
-
highEngineRPM: canDriverStyle.
|
|
42
|
-
hardBreaking: canDriverStyle.
|
|
43
|
-
hardAcceleration: canDriverStyle.
|
|
30
|
+
drivingTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeDriving - endTripData[0].totalTimeDriving : 0,
|
|
31
|
+
idleTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeInIdle - endTripData[0].totalTimeInIdle : 0,
|
|
32
|
+
drivingConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionDriving - endTripData[0].totalFuelConsumptionDriving : 0,
|
|
33
|
+
idleConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionInIdle - endTripData[0].totalFuelConsumptionInIdle : 0,
|
|
34
|
+
drivingDistance: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelled - endTripData[0].totalDistanceTravelled : 0,
|
|
35
|
+
cruiseControlTime: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalTimeWithCruiseControl - endTripData[0].totalTimeWithCruiseControl : 0,
|
|
36
|
+
cruiseControlConsumption: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalFuelConsumptionWithCruiseControl - endTripData[0].totalFuelConsumptionWithCruiseControl : 0,
|
|
37
|
+
cruiseControlDistance: endTripData.length > 1 ? endTripData[endTripData.length - 1].totalDistanceTravelledWithCruiseControl - endTripData[0].totalDistanceTravelledWithCruiseControl : 0,
|
|
38
|
+
economicTime: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeInEcoRange - canDriverStyle[0].totalTimeInEcoRange : 0,
|
|
39
|
+
economicConsumption: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalFuelConsumptionInEcoRange - canDriverStyle[0].totalFuelConsumptionInEcoRange : 0,
|
|
40
|
+
economicDistance: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalDistanceInEcoRange - canDriverStyle[0].totalDistanceInEcoRange : 0,
|
|
41
|
+
highEngineRPM: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalTimeWithHighRpmAndTorque - canDriverStyle[0].totalTimeWithHighRpmAndTorque : 0,
|
|
42
|
+
hardBreaking: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshBrakes - canDriverStyle[0].totalNumberOfHarshBrakes : 0,
|
|
43
|
+
hardAcceleration: canDriverStyle.length > 1 ? canDriverStyle[canDriverStyle.length - 1].totalNumberOfHarshAccelerations - canDriverStyle[0].totalNumberOfHarshAccelerations : 0
|
|
44
44
|
}
|
|
45
45
|
reportData.push(deviceData)
|
|
46
46
|
})
|
package/src/tests/zones.test.js
CHANGED
|
@@ -69,4 +69,20 @@ describe('zones', function () {
|
|
|
69
69
|
assert.equal(first.distanceIn, 93.03917199839687)
|
|
70
70
|
assert.equal(first.distanceOut, 819.6685737216337)
|
|
71
71
|
}, 4000000)
|
|
72
|
+
|
|
73
|
+
it('works with casais 3', async () => {
|
|
74
|
+
const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
|
|
75
|
+
const userData = await report.getUserData()
|
|
76
|
+
userData.zonesByColumn = true
|
|
77
|
+
userData.devices = userData.devices.filter(d => d.name === 'G-1101-E Clio')
|
|
78
|
+
userData.geofences = userData.geofences.filter(g => g.name === 'baliza raio verde ' || g.name === 'baliza raio amarelo ')
|
|
79
|
+
const result = await report.zoneReport(
|
|
80
|
+
new Date(Date.UTC(2023, 0, 1, 0, 0, 0, 0)),
|
|
81
|
+
new Date(Date.UTC(2023, 0, 31, 23, 59, 59, 0)),
|
|
82
|
+
userData)
|
|
83
|
+
const first = result[0].devices[0].geofences[0]
|
|
84
|
+
console.log(first)
|
|
85
|
+
assert.equal(first.name, 'baliza raio verde ')
|
|
86
|
+
assert.equal(first.distanceIn, '1069.343491503579')
|
|
87
|
+
}, 4000000)
|
|
72
88
|
})
|
package/src/util/xpert.js
CHANGED
|
@@ -2,6 +2,7 @@ function parseEndTripMessage (xpertMessage) {
|
|
|
2
2
|
const data = xpertMessage.split(',')
|
|
3
3
|
|
|
4
4
|
return {
|
|
5
|
+
date: data[1],
|
|
5
6
|
totalDistanceTravelled: Number(data[2]),
|
|
6
7
|
totalDistanceTravelledWithCruiseControl: Number(data[3]),
|
|
7
8
|
totalFuelConsumption: Number(data[4]),
|
|
@@ -22,6 +23,7 @@ function parseCanDriverStyleMessage (xpertMessage) {
|
|
|
22
23
|
const data = xpertMessage.split(',')
|
|
23
24
|
|
|
24
25
|
return {
|
|
26
|
+
date: data[1],
|
|
25
27
|
totalFuelConsumptionInEcoRange: Number(data[2]),
|
|
26
28
|
totalTimeInEcoRange: Number(data[3]),
|
|
27
29
|
totalDistanceInEcoRange: Number(data[4]),
|
package/src/zone-report.js
CHANGED
|
@@ -70,8 +70,13 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
70
70
|
deviceCount, devices.length, sliceSize, deviceChunk, undefined)
|
|
71
71
|
|
|
72
72
|
const route = filterPositions(data.route)
|
|
73
|
-
const alerts =
|
|
74
|
-
|
|
73
|
+
const alerts = []
|
|
74
|
+
if (isClientSide()) {
|
|
75
|
+
alerts.push(...(await getInAndOutEvents(slice, cleanPositions(route), userData)))
|
|
76
|
+
} else {
|
|
77
|
+
alerts.push(...(await parallel('zone-report', 'getInAndOutEvents', slice, cleanPositions(route), userData)))
|
|
78
|
+
}
|
|
79
|
+
allData.devices.push(...await processDevices(from, to, devices, userData, { alerts, route, summary: data.summary }))
|
|
75
80
|
|
|
76
81
|
deviceCount = deviceCount + slice.length
|
|
77
82
|
}
|
|
@@ -98,7 +103,7 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
98
103
|
|
|
99
104
|
const zoneInOutData = analyseAlerts(alerts, deviceRoute, userData, from, to).filter(d => !userData.onlyWithStop || d.stopped)
|
|
100
105
|
|
|
101
|
-
if (userData.groupByDay) {
|
|
106
|
+
if (userData.groupByDay || userData.zonesByColumn) {
|
|
102
107
|
const dates = getDates(from, to, userData.user.attributes.timezone)
|
|
103
108
|
|
|
104
109
|
const geofencesData = []
|
|
@@ -175,13 +180,45 @@ async function processDevices (from, to, devices, userData, data) {
|
|
|
175
180
|
})
|
|
176
181
|
}
|
|
177
182
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
if (userData.zonesByColumn) {
|
|
184
|
+
const groupByDay = []
|
|
185
|
+
for (const date of dates) {
|
|
186
|
+
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
187
|
+
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
188
|
+
|
|
189
|
+
const dayRoute = deviceRoute.filter(p => new Date(p.fixTime) >= fromByDay && new Date(p.fixTime) < toByDay)
|
|
190
|
+
const totalDistance = calculateDistance(dayRoute)
|
|
191
|
+
|
|
192
|
+
const geofences = geofencesData.map(g => {
|
|
193
|
+
return {
|
|
194
|
+
geofenceName: g.geofenceName,
|
|
195
|
+
distanceIn: g.days.find(day => day.date === date).distanceIn
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
groupByDay.push({
|
|
200
|
+
date,
|
|
201
|
+
geofences,
|
|
202
|
+
distanceOut: totalDistance - geofences.reduce((a, b) => a + (b.distanceIn || 0), 0)
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
devicesResult.push({
|
|
207
|
+
device: d,
|
|
208
|
+
from,
|
|
209
|
+
to,
|
|
210
|
+
zonesByColumn: true,
|
|
211
|
+
days: groupByDay
|
|
212
|
+
})
|
|
213
|
+
} else {
|
|
214
|
+
devicesResult.push({
|
|
215
|
+
device: d,
|
|
216
|
+
from,
|
|
217
|
+
to,
|
|
218
|
+
groupByDay: true,
|
|
219
|
+
geofences: geofencesData
|
|
220
|
+
})
|
|
221
|
+
}
|
|
185
222
|
} else {
|
|
186
223
|
if (zoneInOutData.length > 0) {
|
|
187
224
|
devicesResult.push({
|