fleetmap-reports 1.0.370 → 1.0.371

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.370",
3
+ "version": "1.0.371",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,9 +1,8 @@
1
1
  const moment = require('moment')
2
2
 
3
- function sliceArray(longArray) {
3
+ function sliceArray(longArray, size = 1) {
4
4
  const arrayToSlice = longArray.slice()
5
5
 
6
- const size = 1
7
6
  const arrayOfArrays = []
8
7
  for (let i=0; i<arrayToSlice.length; i+=size) {
9
8
  arrayOfArrays.push(arrayToSlice.slice(i,i+size));
@@ -74,15 +74,18 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
74
74
  if(getSummary) url += `&type=summary`
75
75
  console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
76
76
 
77
- const sliced = automaticReports.sliceArray(devices)
77
+ const sliced = automaticReports.sliceArray(devices, 50)
78
78
  let deviceCount = 0
79
- const requests = sliced.map(a =>
80
- traccar.axios.get(url + '&' + a.map(d => `deviceId=${d.id}`).join('&')).then(r => r.data).then(x => {
81
- console.log('LOADING_MESSAGE:' + a.map(d => d.name).join(', '))
82
- console.log(`PROGRESS_PERC:${++deviceCount/sliced.length*100}`)
83
- return x
84
- }))
85
- const result = await Promise.all(requests)
79
+ const result = []
80
+ for(const chunk of sliced) {
81
+ const requests = chunk.map(d =>
82
+ traccar.axios.get(url + '&' + `deviceId=${d.id}`).then(r => r.data).then(x => {
83
+ console.log('LOADING_MESSAGE:' + d.name)
84
+ console.log(`PROGRESS_PERC:${++deviceCount / devices.length * 100}`)
85
+ return x
86
+ }))
87
+ result.push(...(await Promise.all(requests)))
88
+ }
86
89
  return {
87
90
  route: result.filter(t => t.route).map(r => r.route).flat(),
88
91
  trips: result.filter(t => t.trips).map(r => r.trips).flat(),