fleetmap-reports 1.0.424 → 1.0.425
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/speeding-report.js +70 -26
package/package.json
CHANGED
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)
|
|
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,6 +100,20 @@ async function createSpeedingReportByDriver (from, to, userData, traccarInstance
|
|
|
103
100
|
return { drivers: [] }
|
|
104
101
|
}
|
|
105
102
|
|
|
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) {
|
|
114
|
+
const geofencesFeatures = userData.geofences.filter(g => g.area.startsWith('POLYGON') &&
|
|
115
|
+
g.attributes.speedLimit).map(g => convertToFeature(g))
|
|
116
|
+
|
|
106
117
|
const allInOne = await traccarHelper.getAllInOne(traccarInstance, from, to, devices, true, false, false, false)
|
|
107
118
|
const routes = allInOne.route
|
|
108
119
|
|
|
@@ -110,19 +121,52 @@ async function createSpeedingReportByDriver (from, to, userData, traccarInstance
|
|
|
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) {
|