fleetmap-reports 2.0.201 → 2.0.204

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": "2.0.201",
3
+ "version": "2.0.204",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -72,24 +72,28 @@ async function getSummary (traccar, from, to, devices) {
72
72
 
73
73
  async function getItems (traccar, u, _chunk, counter, devicesPerRequest, ignorePercentage,
74
74
  totalDevices, currentDeviceCount, routeOnly) {
75
- const x = routeOnly
76
- ? await streamJson(traccar, u)
77
- : await traccar.axios.get(u, {
78
- jar: traccar.cookieJar,
79
- withCredentials: true,
80
- timeout: 900000
81
- }).then(r => r.data)
82
-
83
- console.log('LOADING_MESSAGE:' + _chunk[0].name)
84
- if (counter) {
85
- counter.count += devicesPerRequest
86
- ignorePercentage || console.log(`PROGRESS_PERC:${Math.round(counter.count / totalDevices * 100)}`)
87
- } else {
88
- currentDeviceCount += devicesPerRequest
89
- ignorePercentage || console.log(`PROGRESS_PERC:${Math.round(currentDeviceCount / totalDevices * 100)}`)
75
+ try {
76
+ const x = routeOnly
77
+ ? await streamJson(traccar, u)
78
+ : await traccar.axios.get(u, {
79
+ jar: traccar.cookieJar,
80
+ withCredentials: true
81
+ }).then(r => r.data)
82
+
83
+ console.log('LOADING_MESSAGE:' + _chunk[0].name)
84
+ if (counter) {
85
+ counter.count += devicesPerRequest
86
+ ignorePercentage || console.log(`PROGRESS_PERC:${Math.round(counter.count / totalDevices * 100)}`)
87
+ } else {
88
+ currentDeviceCount += devicesPerRequest
89
+ ignorePercentage || console.log(`PROGRESS_PERC:${Math.round(currentDeviceCount / totalDevices * 100)}`)
90
+ }
91
+ console.log('done devices', _chunk.map(d => d.id), 'position count', x.route && x.route.length)
92
+ return x
93
+ } catch (e) {
94
+ console.error(e)
95
+ return {}
90
96
  }
91
- console.log('done devices', _chunk.map(d => d.id), 'position count', x.route && x.route.length)
92
- return x
93
97
  }
94
98
 
95
99
  async function streamJson (traccar, u) {
@@ -97,27 +101,19 @@ async function streamJson (traccar, u) {
97
101
  const response = await traccar.axios.get(u, {
98
102
  responseType: 'stream',
99
103
  jar: traccar.cookieJar,
100
- withCredentials: true,
101
- timeout: 900000
104
+ withCredentials: true
102
105
  })
103
106
 
104
- const result = {
105
- route: []
106
- }
107
+ const result = { route: [] }
107
108
 
108
- console.log('waiting for data')
109
109
  return new Promise((resolve, reject) => {
110
110
  const pipeline = chain([
111
- response.data, // Axios stream (Node readable)
112
- parser(), // Tokenize
113
- pick({ filter: 'route' }), // Pick 'route', 'summary', etc.
111
+ response.data,
112
+ parser(),
113
+ pick({ filter: 'route' }),
114
114
  streamArray() // Stream each item in the array
115
115
  ])
116
-
117
- pipeline.on('data', ({ value }) => {
118
- result.route.push(value) // Or stream to a DB/file/processor
119
- console.log('pushed to', result.route.length)
120
- })
116
+ pipeline.on('data', ({ value }) => result.route.push(value))
121
117
  pipeline.on('end', () => resolve(result))
122
118
  pipeline.on('error', reject)
123
119
  })
@@ -66,7 +66,7 @@ async function createZoneReport (from, to, userData, traccar) {
66
66
  }
67
67
 
68
68
  const reportRangeDays = (new Date(to).getTime() - new Date(from).getTime()) / (1000 * 60 * 60 * 24)
69
- const devicesPerRequest = reportRangeDays > 31 ? 1 : sliceSize
69
+ const devicesPerRequest = reportRangeDays > 28 ? 1 : sliceSize
70
70
  const sliced = automaticReports.sliceArray(devices, devicesPerRequest)
71
71
 
72
72
  let deviceCount = 0