fleetmap-reports 1.0.403 → 1.0.406

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.403",
3
+ "version": "1.0.406",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -10,9 +10,9 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
+ "@turf/boolean-point-in-polygon": "^6.5.0",
13
14
  "@turf/distance": "^6.5.0",
14
15
  "@turf/helpers": "^6.5.0",
15
- "@turf/point-on-feature": "^6.5.0",
16
16
  "@turf/point-to-line-distance": "^6.5.0",
17
17
  "axios": "^0.21.1",
18
18
  "axios-cookiejar-support": "^1.0.1",
package/src/index.test.js CHANGED
@@ -338,7 +338,8 @@ describe('Test_Reports', function () {
338
338
  const device = data[0].devices.find(d => d.device.id === 25508)
339
339
  assert.equal(device.days.length, 25)
340
340
  }, 30000)
341
- /* it('Zone Report', async () => {
341
+ // eslint-disable-next-line no-undef
342
+ it('Zone Report', async () => {
342
343
  const report = await getReports()
343
344
  const userData = await report.getUserData()
344
345
  const data = await report.zoneReport(new Date(2022, 3, 25, 0, 0, 0, 0),
@@ -347,10 +348,10 @@ describe('Test_Reports', function () {
347
348
 
348
349
  assert.equal(data.length, 1)
349
350
  const device = data[0].devices.find(d => d.device.id===22326)
350
- assert.equal(device.geofences.length, 11)
351
- assert.equal(device.geofences[0].inTime.fixTime, '2022-04-25T23:48:05.000+0000')
351
+ assert.equal(device.geofences.length, 19)
352
+ assert.equal(device.geofences[0].inTime.fixTime, '2022-04-25T23:47:58.000+0000')
352
353
  assert.equal(device.geofences[0].outTime.fixTime, '2022-04-26T07:47:35.000+0000')
353
- assert.equal(device.geofences[0].totalTime, '28770')
354
+ assert.equal(device.geofences[0].totalTime, '28777')
354
355
  assert.equal(device.geofences[0].geofenceName, 'Casa João')
355
- }, 30000) */
356
+ }, 30000)
356
357
  })
@@ -65,16 +65,15 @@ async function getSummary (traccar, from, to, devices) {
65
65
  return result.map(r => r.data).flat()
66
66
  }
67
67
 
68
- async function getAllInOne (traccar, from, to, devices, getRoutes, getTrips, getStops, getSummary, currentDeviceCount = 0, totalDevices = devices.length) {
68
+ async function getAllInOne (traccar, from, to, devices, getRoutes, getTrips, getStops, getSummary, currentDeviceCount = 0, totalDevices = devices.length, sliceSize= 5) {
69
69
  let url = `/reports/allinone?&from=${from.toISOString()}&to=${to.toISOString()}`
70
70
  if (getRoutes) url += '&type=route'
71
71
  if (getTrips) url += '&type=trips'
72
72
  if (getStops) url += '&type=stops'
73
73
  if (getSummary) url += '&type=summary'
74
74
 
75
- const sliced = automaticReports.sliceArray(devices, 5)
75
+ const sliced = automaticReports.sliceArray(devices, sliceSize)
76
76
  const result = []
77
- let deviceCount = currentDeviceCount
78
77
  for (const chunk of sliced) {
79
78
  const requests = chunk.map(d =>
80
79
  traccar.axios.get(url + '&' + `deviceId=${d.id}`, {
@@ -82,8 +81,7 @@ async function getAllInOne (traccar, from, to, devices, getRoutes, getTrips, get
82
81
  withCredentials: true
83
82
  }).then(r => r.data).then(x => {
84
83
  console.log('LOADING_MESSAGE:' + d.name)
85
- deviceCount = deviceCount + 1
86
- console.log(`PROGRESS_PERC:${deviceCount / totalDevices * 100}`)
84
+ console.log(`PROGRESS_PERC:${currentDeviceCount++ / totalDevices * 100}`)
87
85
  return x
88
86
  }))
89
87
  result.push(...(await Promise.all(requests)))
@@ -9,7 +9,7 @@ const {getUserPartner} = require("fleetmap-partners")
9
9
  const {devicesToProcess} = require("./util/device")
10
10
  const traccarHelper = require("./util/traccar")
11
11
  const pointToLineDistance = require("@turf/point-to-line-distance")
12
- const pointOnFeature = require("@turf/point-on-feature")
12
+ const booleanPointInPolygon = require("@turf/boolean-point-in-polygon")
13
13
  const distance = require("@turf/distance")
14
14
 
15
15
  const fileName = 'ZoneReport'
@@ -58,7 +58,7 @@ async function createZoneReport(from, to, userData, traccar) {
58
58
 
59
59
  let deviceCount = 0
60
60
  for(const slice of sliced) {
61
- const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, false, false, false, deviceCount, devices.length)
61
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, false, false, false, deviceCount, devices.length, 20)
62
62
  const routeData = allInOne.route
63
63
 
64
64
  const data = getInAndOutEvents(slice, routeData, userData)
@@ -161,7 +161,7 @@ function getInAndOutEvents(devices, route, userData) {
161
161
  routePoints.forEach(p => {
162
162
  geofencesFeatures.forEach(g => {
163
163
  if(g.geometry.type === 'Polygon') {
164
- if (pointOnFeature(p, g)) {
164
+ if (booleanPointInPolygon.default(p, g)) {
165
165
  if (!entryMap.includes(g)) {
166
166
  events.push(createEvent('geofenceEnter',d.id,p,g))
167
167
  entryMap.push(g)
@@ -175,7 +175,7 @@ function getInAndOutEvents(devices, route, userData) {
175
175
  }
176
176
  }
177
177
  if(g.geometry.type === 'Point') {
178
- if (distance(p, g, {units: 'meters'}) < g.properties.distance) {
178
+ if (distance.default(p, g, {units: 'meters'}) < g.properties.distance) {
179
179
  if (!entryMap.includes(g)) {
180
180
  events.push(createEvent('geofenceEnter',d.id,p,g))
181
181
  entryMap.push(g)
@@ -189,7 +189,7 @@ function getInAndOutEvents(devices, route, userData) {
189
189
  }
190
190
  }
191
191
  if(g.geometry.type === 'LineString') {
192
- if (pointToLineDistance(p, g,{units: 'meters'}) < (g.properties.geofence.attributes.polylineDistance || 25)) {
192
+ if (pointToLineDistance.default(p, g,{units: 'meters'}) < (g.properties.geofence.attributes.polylineDistance || 25)) {
193
193
  if (!entryMap.includes(g)) {
194
194
  events.push(createEvent('geofenceEnter',d.id,p,g))
195
195
  entryMap.push(g)