fleetmap-reports 1.0.509 → 1.0.510
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 +4 -3
- package/src/speeding-report.js +6 -9
package/package.json
CHANGED
package/src/index.test.js
CHANGED
|
@@ -30,10 +30,11 @@ describe('Test_Reports', function () {
|
|
|
30
30
|
const report = await getReports()
|
|
31
31
|
const userData = await report.getUserData()
|
|
32
32
|
userData.roadSpeedLimits = false
|
|
33
|
-
userData.customSpeed =
|
|
33
|
+
userData.customSpeed = false
|
|
34
|
+
userData.useVehicleSpeedLimit = true
|
|
34
35
|
const data = await report.speedingReport(
|
|
35
|
-
new Date(Date.UTC(2022,
|
|
36
|
-
new Date(Date.UTC(2022,
|
|
36
|
+
new Date(Date.UTC(2022, 9, 22, 0, 0, 0, 0)),
|
|
37
|
+
new Date(Date.UTC(2022, 9, 22, 23, 59, 59, 0)),
|
|
37
38
|
userData)
|
|
38
39
|
const device = data[0].devices.find(d => d.device.id === 22326)
|
|
39
40
|
console.log('device', device)
|
package/src/speeding-report.js
CHANGED
|
@@ -56,7 +56,7 @@ async function createSpeedingReportByGroup (from, to, userData, traccarInstance)
|
|
|
56
56
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
57
57
|
|
|
58
58
|
if (events.length > 0) {
|
|
59
|
-
groupData.devices =
|
|
59
|
+
groupData.devices = processDevices(from, to, devices, events, routes, userData)
|
|
60
60
|
reportData.push(groupData)
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -87,7 +87,7 @@ async function createSpeedingReportByDevice (from, to, userData, traccarInstance
|
|
|
87
87
|
await Promise.all(sliced.map(async slice => {
|
|
88
88
|
const { routes, events } = await getEvents(traccarInstance, from, to, slice, userData, deviceCount, devices.length, slice.length)
|
|
89
89
|
if (events.length > 0) {
|
|
90
|
-
const devicesProcessed =
|
|
90
|
+
const devicesProcessed = processDevices(from, to, slice, events, routes, userData)
|
|
91
91
|
allData.devices.push(...devicesProcessed)
|
|
92
92
|
}
|
|
93
93
|
deviceCount = deviceCount + slice.length
|
|
@@ -189,7 +189,7 @@ function getGeofenceSpeedLimitEvents (geofencesFeatures, routes, devices) {
|
|
|
189
189
|
async function processDrivers (from, to, events, routes, userData) {
|
|
190
190
|
const driversResult = []
|
|
191
191
|
|
|
192
|
-
|
|
192
|
+
findEventsPosition(from, to, userData.devices, events, routes, userData)
|
|
193
193
|
|
|
194
194
|
userData.drivers.forEach(d => {
|
|
195
195
|
const driverEvents = events.filter(e => e.position && e.position.attributes.driverUniqueId === d.uniqueId)
|
|
@@ -210,9 +210,9 @@ async function processDrivers (from, to, events, routes, userData) {
|
|
|
210
210
|
return driversResult
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
|
|
213
|
+
function processDevices (from, to, devices, events, routes, userData) {
|
|
214
214
|
const devicesResult = []
|
|
215
|
-
|
|
215
|
+
findEventsPosition(from, to, devices, events, routes, userData)
|
|
216
216
|
|
|
217
217
|
for (const d of devices) {
|
|
218
218
|
const deviceEvents = events.filter(e => e.deviceId === d.id && e.position)
|
|
@@ -233,10 +233,9 @@ async function processDevices (from, to, devices, events, routes, userData) {
|
|
|
233
233
|
return devicesResult
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
-
|
|
236
|
+
function findEventsPosition (from, to, devices, events, routes, userData) {
|
|
237
237
|
for (const d of devices) {
|
|
238
238
|
const deviceEvents = events.filter(e => e.deviceId === d.id && e.positionId)
|
|
239
|
-
console.log(d.name, deviceEvents.length)
|
|
240
239
|
if (deviceEvents.length > 0) {
|
|
241
240
|
const positions = routes.filter(p => p.deviceId === d.id)
|
|
242
241
|
for (const a of deviceEvents) {
|
|
@@ -251,7 +250,6 @@ async function findEventsPosition (from, to, devices, events, routes, userData)
|
|
|
251
250
|
}
|
|
252
251
|
|
|
253
252
|
if (!userData.roadSpeedLimits) {
|
|
254
|
-
console.log('ignorting eventdata')
|
|
255
253
|
a.position = positions[pIndex]
|
|
256
254
|
calculateEventData(positions, pIndex, a, d, geofence, userData)
|
|
257
255
|
}
|
|
@@ -264,7 +262,6 @@ async function findEventsPosition (from, to, devices, events, routes, userData)
|
|
|
264
262
|
console.error('cant find position for event', a)
|
|
265
263
|
}
|
|
266
264
|
}
|
|
267
|
-
deviceEvents.sort((a, b) => new Date(a.position.fixTime) - new Date(b.position.fixTime))
|
|
268
265
|
}
|
|
269
266
|
}
|
|
270
267
|
}
|