fleetmap-reports 1.0.932 → 1.0.934

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.932",
3
+ "version": "1.0.934",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -13,6 +13,11 @@ async function createGPSJumpReport (from, to, userData, traccar, minDistance) {
13
13
  for (const slice of sliced) {
14
14
  const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, false, false, false, deviceCount, devices.length)
15
15
 
16
+ allInOne.route.forEach(p => {
17
+ p.distance = p.attributes.distance
18
+ delete p.attributes
19
+ })
20
+
16
21
  slice.forEach(d => {
17
22
  const deviceData = getDeviceData(allInOne, d, userData.user, minDistance)
18
23
  reportData = reportData.concat(deviceData)
@@ -30,22 +35,22 @@ function getDeviceData (allInOne, d, user, minDistance) {
30
35
  return deviceRoute.map((pA, index) => {
31
36
  if (index < deviceRoute.length - 1) {
32
37
  const pB = deviceRoute[index + 1]
33
- let distanceValue = pA.attributes.distance
34
- if ((minDistance * 1000) >= pA.attributes.distance) {
35
- distanceValue = distance.default([pA.longitude, pA.latitude], [pB.longitude, pB.latitude], { units: 'meters' })
36
- }
37
-
38
- return {
39
- device: d.name,
40
- dateA: convertToLocaleString(pA.fixTime, user.attributes.lang, user.attributes.timezone, user),
41
- addressA: pA.address,
42
- dateB: convertToLocaleString(pB.fixTime, user.attributes.lang, user.attributes.timezone, user),
43
- addressB: pB.address,
44
- distance: distanceValue
38
+ if ((minDistance * 1000) < pA.distance) {
39
+ const distanceValue = distance.default([pA.longitude, pA.latitude], [pB.longitude, pB.latitude], { units: 'meters' })
40
+ if ((minDistance * 1000) < distanceValue) {
41
+ return {
42
+ device: d.name,
43
+ dateA: convertToLocaleString(pA.fixTime, user.attributes.lang, user.attributes.timezone, user),
44
+ addressA: pA.address,
45
+ dateB: convertToLocaleString(pB.fixTime, user.attributes.lang, user.attributes.timezone, user),
46
+ addressB: pB.address,
47
+ distance: distanceValue
48
+ }
49
+ }
45
50
  }
46
51
  }
47
52
  return undefined
48
- }).filter(a => a && (minDistance * 1000) < a.distance)
53
+ }).filter(a => a)
49
54
  }
50
55
 
51
56
  exports.createGPSJumpReport = createGPSJumpReport
@@ -0,0 +1,23 @@
1
+ const { getReports } = require('./index')
2
+ const assert = require('assert')
3
+ const { convertMS } = require('../util/utils')
4
+ const { createGPSJumpReport } = require('../partnerReports/gpsjump-report')
5
+
6
+ // eslint-disable-next-line no-undef
7
+ describe('gpsjump', function () {
8
+ // eslint-disable-next-line no-undef
9
+ it('gpsjump report', async () => {
10
+ const report = await getReports()
11
+ const userData = await report.getUserData()
12
+ userData.devices = userData.devices.filter(d => d.id === 22326)
13
+ const data = await createGPSJumpReport(
14
+ new Date(Date.UTC(2023, 6, 1, 0, 0, 0, 0)),
15
+ new Date(Date.UTC(2023, 6, 17, 23, 59, 59, 0)),
16
+ userData,
17
+ report.traccar)
18
+ console.log(data)
19
+ assert.equal(data[0].consumption, 19.799999999999997)
20
+ assert.equal(data[0].distance, 326.7657)
21
+ assert.equal(convertMS(data[1].time * 1000, false), '08:19')
22
+ }, 8000000)
23
+ })