fleetmap-reports 1.0.407 → 1.0.410

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.407",
3
+ "version": "1.0.410",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -77,30 +77,33 @@ async function getAllInOne (
77
77
  currentDeviceCount = 0,
78
78
  totalDevices = devices.length,
79
79
  sliceSize = 5,
80
- vehiclesByRequest = 1) {
80
+ devicesPerRequest = 1,
81
+ counter = undefined) {
81
82
  let url = `/reports/allinone?from=${from.toISOString()}&to=${to.toISOString()}`
82
83
  if (getRoutes) url += '&type=route'
83
84
  if (getTrips) url += '&type=trips'
84
85
  if (getStops) url += '&type=stops'
85
86
  if (getSummary) url += '&type=summary'
86
87
 
87
- console.log('getAllInOn', devices.map(d => d.id))
88
-
89
88
  const sliced = automaticReports.sliceArray(devices, sliceSize)
90
89
  const result = []
91
90
  for (const chunk of sliced) {
92
91
  const requests = []
93
- for (const _chunk of automaticReports.sliceArray(chunk, vehiclesByRequest)) {
92
+ for (const _chunk of automaticReports.sliceArray(chunk, devicesPerRequest)) {
94
93
  const u = url + '&' + _chunk.map(d => `deviceId=${d.id}`).join('&')
95
- console.log(u)
96
94
  requests.push(
97
95
  traccar.axios.get(u, {
98
96
  jar: traccar.cookieJar,
99
97
  withCredentials: true
100
98
  }).then(r => r.data).then(x => {
101
99
  console.log('LOADING_MESSAGE:' + _chunk[0].name)
102
- currentDeviceCount += vehiclesByRequest
103
- console.log(`PROGRESS_PERC:${currentDeviceCount / totalDevices * 100}`)
100
+ if (counter) {
101
+ counter.count += devicesPerRequest
102
+ console.log(`PROGRESS_PERC:${counter.count / totalDevices * 100}`)
103
+ } else {
104
+ currentDeviceCount += devicesPerRequest
105
+ console.log(`PROGRESS_PERC:${currentDeviceCount / totalDevices * 100}`)
106
+ }
104
107
  return x
105
108
  }))
106
109
  }
@@ -30,7 +30,7 @@ async function createZoneReport (from, to, userData, traccar) {
30
30
  group: g,
31
31
  xpert: devices.filter(d => d.attributes.xpert).length > 0
32
32
  }
33
-
33
+ console.log('LOADING_MESSAGE:' + 'Eventos...')
34
34
  const response = await traccar.reports.reportsEventsGet(from, to, null, [g.id], types)
35
35
  const data = response.data
36
36
 
@@ -53,22 +53,26 @@ async function createZoneReport (from, to, userData, traccar) {
53
53
  xpert: devices.filter(d => d.attributes.xpert).length > 0
54
54
  }
55
55
 
56
- const sliced = automaticReports.sliceArray(devices, 5)
56
+ const sliced = automaticReports.sliceArray(devices, 30)
57
57
 
58
- let deviceCount = 0
58
+ const deviceCount = { count: 0 }
59
+ const promises = []
59
60
  for (const slice of sliced) {
60
- const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, false, false, false, deviceCount, devices.length, 30, 10)
61
- const routeData = allInOne.route
61
+ promises.push(traccarHelper.getAllInOne(
62
+ traccar, from, to, slice, true, false, false, false,
63
+ deviceCount, devices.length, 20, 5, deviceCount).then(async allInOne => {
64
+ const routeData = allInOne.route
62
65
 
63
- const data = getInAndOutEvents(slice, routeData, userData)
66
+ const data = getInAndOutEvents(slice, routeData, userData)
64
67
 
65
- console.log('Geofence Enter/Exit Alerts:' + data.length)
68
+ console.log('Geofence Enter/Exit Alerts:' + data.length)
66
69
 
67
- if (data.length) {
68
- allData.devices.push(...await processDevices(from, to, devices, userData.drivers, userData.geofences, data, traccar))
69
- }
70
- deviceCount = deviceCount + slice.length
70
+ if (data.length) {
71
+ allData.devices.push(...await processDevices(from, to, devices, userData.drivers, userData.geofences, data, traccar))
72
+ }
73
+ }))
71
74
  }
75
+ await Promise.all(promises)
72
76
 
73
77
  reportData.push(allData)
74
78