fleetmap-reports 1.0.508 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.508",
3
+ "version": "1.0.510",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.test.js CHANGED
@@ -6,7 +6,7 @@ async function getSpeedingReport (report, userData) {
6
6
  new Date(Date.UTC(2022, 1, 17, 0, 0, 0, 0)),
7
7
  new Date(Date.UTC(2022, 1, 17, 23, 59, 59, 0)),
8
8
  userData)
9
- assert.equal(data.length, 1)
9
+
10
10
  const device = data[0].devices.find(d => d.device.id === 22326)
11
11
  const totalDistance = device.alerts.reduce((a, b) => a + b.distance, 0)
12
12
  const totalEventTime = device.alerts.reduce((a, b) => a + b.eventTime, 0)
@@ -16,7 +16,7 @@ async function getSpeedingReport (report, userData) {
16
16
  // eslint-disable-next-line no-undef
17
17
  describe('Test_Reports', function () {
18
18
  // eslint-disable-next-line no-undef
19
- it('Speeding by device', async () => {
19
+ it('works with road speed limits', async () => {
20
20
  const report = await getReports()
21
21
  const userData = await report.getUserData()
22
22
  userData.roadSpeedLimits = true
@@ -25,6 +25,22 @@ describe('Test_Reports', function () {
25
25
  assert.equal(totalDistance, 36.63687856826021) // Total Kms
26
26
  assert.equal(totalEventTime, 1524000) // Total Duration
27
27
  }, 200000)
28
+
29
+ it('works by device speed limit', async () => {
30
+ const report = await getReports()
31
+ const userData = await report.getUserData()
32
+ userData.roadSpeedLimits = false
33
+ userData.customSpeed = false
34
+ userData.useVehicleSpeedLimit = true
35
+ const data = await report.speedingReport(
36
+ new Date(Date.UTC(2022, 9, 22, 0, 0, 0, 0)),
37
+ new Date(Date.UTC(2022, 9, 22, 23, 59, 59, 0)),
38
+ userData)
39
+ const device = data[0].devices.find(d => d.device.id === 22326)
40
+ console.log('device', device)
41
+ assert.equal(device.alerts.length, 75) // Total Alerts
42
+ }, 900000)
43
+
28
44
  // eslint-disable-next-line no-undef
29
45
  it('Speeding with custom speed', async () => {
30
46
  const report = await getReports()
@@ -36,7 +52,7 @@ describe('Test_Reports', function () {
36
52
  assert.equal(device.alerts.length, 13) // Total Alerts
37
53
  assert.equal(totalDistance, 46.64576895855739) // Total Kms
38
54
  assert.equal(totalEventTime, 1402000) // Total Duration
39
- }, 20000)
55
+ }, 999990000)
40
56
  // eslint-disable-next-line no-undef
41
57
  it('Trip by device', async () => {
42
58
  const report = await getReports()
@@ -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 = await processDevices(from, to, devices, events, routes, userData)
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 = await processDevices(from, to, slice, events, routes, userData)
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
- await findEventsPosition(from, to, userData.devices, events, routes, userData)
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
- async function processDevices (from, to, devices, events, routes, userData) {
213
+ function processDevices (from, to, devices, events, routes, userData) {
214
214
  const devicesResult = []
215
- await findEventsPosition(from, to, devices, events, routes, userData)
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
- async function findEventsPosition (from, to, devices, events, routes, userData) {
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
  }
@@ -260,9 +258,10 @@ async function findEventsPosition (from, to, devices, events, routes, userData)
260
258
  a.driver = (driver && driver.name) || a.position.attributes.driverUniqueId
261
259
  }
262
260
  a.deviceName = d.name
261
+ } else {
262
+ console.error('cant find position for event', a)
263
263
  }
264
264
  }
265
- deviceEvents.sort((a, b) => new Date(a.position.fixTime) - new Date(b.position.fixTime))
266
265
  }
267
266
  }
268
267
  }
@@ -361,7 +360,6 @@ function calculateEventData (positions, pIndex, alert, device, geofence, userDat
361
360
  let dist = 0
362
361
  while (pIndex + 1 < positions.length) {
363
362
  pIndex++
364
- console.log(pIndex)
365
363
  dist += distance.default(point([endEventPosition.longitude, endEventPosition.latitude]),
366
364
  point([positions[pIndex].longitude, positions[pIndex].latitude]))
367
365
  endEventPosition = positions[pIndex]
@@ -369,7 +367,6 @@ function calculateEventData (positions, pIndex, alert, device, geofence, userDat
369
367
  alert.eventTime = new Date(endEventPosition.fixTime) - new Date(alert.position.fixTime)
370
368
  alert.attributes.maxSpeed = maxSpeed
371
369
  alert.distance = dist
372
- console.log(alert)
373
370
  break
374
371
  } else {
375
372
  if (maxSpeed < endEventPosition.speed) {