fleetmap-reports 1.0.699 → 1.0.701

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.699",
3
+ "version": "1.0.701",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,5 +1,8 @@
1
1
  const { getReports } = require('./index')
2
+ const assert = require('assert')
3
+ // eslint-disable-next-line no-undef
2
4
  describe('zones', function () {
5
+ // eslint-disable-next-line no-undef
3
6
  it('works with ellca', async () => {
4
7
  const report = await getReports()
5
8
  const userData = await report.getUserData()
@@ -16,16 +19,19 @@ describe('zones', function () {
16
19
  console.log('result', result)
17
20
  }, 4000000)
18
21
 
19
- it('works with afriquia', async () => {
20
- const report = await getReports('moviflotte@gmail.com', 'moviflotte@gmail.com')
22
+ // eslint-disable-next-line no-undef
23
+ it('works with casais', async () => {
24
+ const report = await getReports('mario.andre.moreira@casais.gi', 'Casais.23')
21
25
  const userData = await report.getUserData()
22
- console.log(userData.devices.length)
23
- console.log(userData.devices.map(d => d.id))
24
- console.log(userData.geofences)
26
+ userData.devices = userData.devices.filter(d => d.name === 'G-1101-E Clio')
27
+ userData.geofences = userData.geofences.filter(g => g.name === 'baliza raio verde ')
25
28
  const result = await report.zoneReport(
26
- new Date(Date.UTC(2023, 5, 11, 0, 0, 0, 0)),
27
- new Date(Date.UTC(2023, 5, 11, 23, 59, 59, 0)),
29
+ new Date(Date.UTC(2023, 0, 1, 0, 0, 0, 0)),
30
+ new Date(Date.UTC(2023, 0, 31, 23, 59, 59, 0)),
28
31
  userData)
29
- console.log('result', result)
32
+ const first = result[0].devices[0].geofences[0]
33
+ console.log(first)
34
+ assert.equal(first.inTime.fixTime, '2023-01-03T21:23:24.000+0000')
35
+ assert.equal(first.outTime.fixTime, '2023-01-07T12:22:53.000+0000')
30
36
  }, 4000000)
31
37
  })
package/src/util/utils.js CHANGED
@@ -245,4 +245,4 @@ exports.calculateDistance = (positions) => {
245
245
  }, 0) || 0
246
246
  }
247
247
 
248
- exports.sortPositions = (a, b) => new Date(a).getTime() - new Date(b).getTime()
248
+ exports.sortPositions = (a, b) => new Date(a.fixTime).getTime() - new Date(b.fixTime).getTime()
@@ -15,7 +15,7 @@ const axios = require('axios')
15
15
  const { processServerSide } = require('./util')
16
16
  const { filterPositions } = require('./util/route')
17
17
  const { checkGeofenceIn } = require('./util/geofence')
18
- const sliceSize = 400
18
+ const sliceSize = 100
19
19
  const deviceChunk = 5
20
20
  const fileName = 'ZoneReport'
21
21
 
@@ -29,7 +29,17 @@ async function createZoneReport (from, to, userData, traccar) {
29
29
 
30
30
  if (processServerSide(userData)) {
31
31
  const url = `https://${process.env.SERVER_HOST}/reports/zone-report`
32
- return axios.post(url, { from, to, userData }, { withCredentials: true }).then(d => d.data)
32
+ const sliced = automaticReports.sliceArray(devices, sliceSize)
33
+ const promises = []
34
+ for (const slice of sliced) {
35
+ promises.push(axios.post(url, { from, to, userData: { ...userData, devices: slice } }, { withCredentials: true })
36
+ .then(d => d.data)
37
+ .then(data => allData.devices.push(...(data[0].devices)))
38
+ )
39
+ }
40
+ await Promise.all(promises)
41
+ reportData.push(allData)
42
+ return reportData
33
43
  }
34
44
  const types = ['geofenceEnter', 'geofenceExit']
35
45
 
@@ -315,7 +325,7 @@ function getInAndOutEvents (devices, route, userData) {
315
325
  if (!checkGeofenceIn(p, g)) {
316
326
  deviceEvents.push(createEvent('geofenceExit', d.id, p, g))
317
327
  } else {
318
- previous.inside[id] = true
328
+ p.inside[id] = true
319
329
  }
320
330
  } else {
321
331
  if (checkGeofenceIn(p, g)) {