fleetmap-reports 1.0.423 → 1.0.426
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/index.test.js +1 -1
- package/src/speeding-report.js +71 -27
- package/src/trip-report.js +1 -1
package/package.json
CHANGED
package/src/index.test.js
CHANGED
|
@@ -64,7 +64,7 @@ describe('Test_Reports', function () {
|
|
|
64
64
|
const device = data[0].devices.find(d => d.device.id === 25808)
|
|
65
65
|
assert.equal(device.trips.length, 11) // Total Trips
|
|
66
66
|
console.log(device.trips[0])
|
|
67
|
-
assert.equal(device.trips[0].endAddress, '
|
|
67
|
+
assert.equal(device.trips[0].endAddress, 'RS-409, 184-314 - Centro, Vera Cruz - RS, 96880-000, Brazil')
|
|
68
68
|
assert.equal(device.trips[1].endPOIName, undefined)
|
|
69
69
|
}, 20000)
|
|
70
70
|
// eslint-disable-next-line no-undef
|
package/src/speeding-report.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const messages = require('../lang')
|
|
2
2
|
const jsPDF = require('jspdf')
|
|
3
|
-
const { convertMS, convertToLocaleString } = require('./util/utils')
|
|
3
|
+
const { convertMS, convertToLocaleString, convertToFeature, convertPositionToFeature } = require('./util/utils')
|
|
4
4
|
const { headerFromUser, AmiriRegular } = require('./util/pdfDocument')
|
|
5
5
|
require('jspdf-autotable')
|
|
6
6
|
const { getStyle } = require('./reportStyle')
|
|
@@ -12,6 +12,8 @@ const { devicesToProcess } = require('./util/device')
|
|
|
12
12
|
const { point } = require('@turf/helpers')
|
|
13
13
|
const distance = require('@turf/distance')
|
|
14
14
|
const { insideGeofence } = require('./util/geofence')
|
|
15
|
+
const booleanPointInPolygon = require('@turf/boolean-point-in-polygon')
|
|
16
|
+
const automaticReports = require('./automaticReports')
|
|
15
17
|
|
|
16
18
|
const fileName = 'SpeedingReport'
|
|
17
19
|
const eventTypes = ['deviceOverspeed']
|
|
@@ -69,29 +71,24 @@ async function createSpeedingReportByGroup (from, to, userData, traccarInstance)
|
|
|
69
71
|
async function createSpeedingReportByDevice (from, to, userData, traccarInstance) {
|
|
70
72
|
const devices = devicesToProcess(userData)
|
|
71
73
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (userData.roadSpeedLimits) {
|
|
77
|
-
events.push(...await getHereEvents(devices, routes, userData.maxSpeedThreshold))
|
|
78
|
-
} else {
|
|
79
|
-
if (!userData.useVehicleSpeedLimit && userData.customSpeed) {
|
|
80
|
-
events.push(...await getCustomSpeedLimitEvents(devices, routes, userData.customSpeed))
|
|
81
|
-
} else {
|
|
82
|
-
events.push(...await traccarHelper.getEvents(traccarInstance, from, to, devices, eventTypes))
|
|
83
|
-
}
|
|
74
|
+
const allData = {
|
|
75
|
+
devices: [],
|
|
76
|
+
xpert: devices.filter(d => d && d.attributes && d.attributes.xpert).length > 0
|
|
84
77
|
}
|
|
85
78
|
|
|
86
|
-
|
|
87
|
-
// empty report
|
|
88
|
-
return { devices: [] }
|
|
89
|
-
}
|
|
79
|
+
const sliced = automaticReports.sliceArray(devices, 5)
|
|
90
80
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
81
|
+
let deviceCount = 0
|
|
82
|
+
for (const slice of sliced) {
|
|
83
|
+
const { routes, events } = await getEvents(traccarInstance, from, to, slice, userData, deviceCount, devices.length)
|
|
84
|
+
if (events.length > 0) {
|
|
85
|
+
const devicesProcessed = await processDevices(from, to, slice, events, routes, userData)
|
|
86
|
+
allData.devices.push(...devicesProcessed)
|
|
87
|
+
}
|
|
88
|
+
deviceCount = deviceCount + slice.length
|
|
94
89
|
}
|
|
90
|
+
|
|
91
|
+
return allData
|
|
95
92
|
}
|
|
96
93
|
|
|
97
94
|
async function createSpeedingReportByDriver (from, to, userData, traccarInstance) {
|
|
@@ -103,26 +100,73 @@ async function createSpeedingReportByDriver (from, to, userData, traccarInstance
|
|
|
103
100
|
return { drivers: [] }
|
|
104
101
|
}
|
|
105
102
|
|
|
106
|
-
const
|
|
103
|
+
const { routes, events } = await getEvents(traccarInstance, from, to, devices, userData)
|
|
104
|
+
|
|
105
|
+
if (!events.length) {
|
|
106
|
+
// empty report
|
|
107
|
+
return { drivers: [] }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return { drivers: await processDrivers(from, to, events, routes, userData) }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function getEvents (traccarInstance, from, to, devices, userData, deviceCount, totalDevices) {
|
|
114
|
+
const geofencesFeatures = userData.geofences.filter(g => g.area.startsWith('POLYGON') &&
|
|
115
|
+
g.attributes.speedLimit).map(g => convertToFeature(g))
|
|
116
|
+
|
|
117
|
+
const allInOne = await traccarHelper.getAllInOne(traccarInstance, from, to, devices, true, false, false, false, deviceCount, totalDevices)
|
|
107
118
|
const routes = allInOne.route
|
|
108
119
|
|
|
109
120
|
const events = []
|
|
110
121
|
if (!userData.useVehicleSpeedLimit && userData.customSpeed) {
|
|
111
122
|
events.push(...await getCustomSpeedLimitEvents(devices, routes, userData.customSpeed))
|
|
112
123
|
} else {
|
|
113
|
-
|
|
124
|
+
const traccarEvents = await traccarHelper.getEvents(traccarInstance, from, to, devices, eventTypes)
|
|
125
|
+
if (geofencesFeatures.length) {
|
|
126
|
+
events.push(...getGeofenceSpeedLimitEvents(geofencesFeatures, routes, devices))
|
|
127
|
+
events.push(...traccarEvents.filter(e => !(e.geofenceId)))
|
|
128
|
+
} else {
|
|
129
|
+
events.push(...traccarEvents)
|
|
130
|
+
}
|
|
114
131
|
}
|
|
115
132
|
|
|
116
133
|
if (userData.roadSpeedLimits) {
|
|
117
134
|
events.push(...await getHereEvents(devices, routes, userData.maxSpeedThreshold))
|
|
118
135
|
}
|
|
136
|
+
return { routes, events }
|
|
137
|
+
}
|
|
119
138
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return { drivers: [] }
|
|
123
|
-
}
|
|
139
|
+
function getGeofenceSpeedLimitEvents (geofencesFeatures, routes, devices) {
|
|
140
|
+
const events = []
|
|
124
141
|
|
|
125
|
-
|
|
142
|
+
devices.forEach(d => {
|
|
143
|
+
const deviceRoute = routes.filter(p => p.deviceId === d.id)
|
|
144
|
+
const routePoints = deviceRoute.map(p => convertPositionToFeature(p))
|
|
145
|
+
geofencesFeatures.forEach(g => {
|
|
146
|
+
let eventIsActive = false
|
|
147
|
+
routePoints.forEach(p => {
|
|
148
|
+
if (booleanPointInPolygon.default(p, g) && p.properties.position.speed > g.properties.geofence.attributes.speedLimit) {
|
|
149
|
+
if (!eventIsActive) {
|
|
150
|
+
const event = {
|
|
151
|
+
positionId: p.properties.position.id,
|
|
152
|
+
deviceId: d.id,
|
|
153
|
+
geofenceId: g.properties.geofence.id,
|
|
154
|
+
attributes: {
|
|
155
|
+
speedLimit: g.properties.geofence.attributes.speedLimit,
|
|
156
|
+
speed: p.properties.position.speed
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
events.push(event)
|
|
160
|
+
}
|
|
161
|
+
eventIsActive = true
|
|
162
|
+
} else {
|
|
163
|
+
eventIsActive = false
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
return events
|
|
126
170
|
}
|
|
127
171
|
|
|
128
172
|
async function processDrivers (from, to, events, routes, userData) {
|
package/src/trip-report.js
CHANGED
|
@@ -158,7 +158,7 @@ function processDevices (from, to, devices, data, userData, traccar) {
|
|
|
158
158
|
trip.stopEngineHours = 0
|
|
159
159
|
}
|
|
160
160
|
if (trip.endAddress === null) {
|
|
161
|
-
traccar.axios.get(`/server/geocode?latitude=${trip.
|
|
161
|
+
traccar.axios.get(`/server/geocode?latitude=${trip.endLat}&longitude=${trip.endLon}`)
|
|
162
162
|
.then(d => { trip.endAddress = d.data })
|
|
163
163
|
}
|
|
164
164
|
})
|