fleetmap-reports 1.0.370 → 1.0.374
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 +1 -1
- package/src/automaticReports.js +1 -2
- package/src/util/traccar.js +16 -14
package/package.json
CHANGED
package/src/automaticReports.js
CHANGED
|
@@ -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));
|
package/src/util/traccar.js
CHANGED
|
@@ -3,7 +3,7 @@ const automaticReports = require("../automaticReports");
|
|
|
3
3
|
async function getRoute(traccar, from, to, devices){
|
|
4
4
|
const devicesToSlice = devices.slice()
|
|
5
5
|
|
|
6
|
-
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
|
|
6
|
+
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice, 50)
|
|
7
7
|
let requests = []
|
|
8
8
|
for (const a of arrayOfArrays) {
|
|
9
9
|
const promise = traccar.reports.reportsRouteGet(from, to, a.map(d => d.id))
|
|
@@ -11,13 +11,12 @@ async function getRoute(traccar, from, to, devices){
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const result = await Promise.all(requests)
|
|
14
|
-
|
|
15
14
|
return result.map(r => r.data).flat()
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
async function getTrips(traccar, from, to, devices){
|
|
19
18
|
const devicesToSlice = devices.slice()
|
|
20
|
-
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
|
|
19
|
+
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice, 50)
|
|
21
20
|
let requests = []
|
|
22
21
|
for (const a of arrayOfArrays) {
|
|
23
22
|
const promise = traccar.reports.reportsTripsGet(from, to, a.map(d => d.id))
|
|
@@ -30,7 +29,7 @@ async function getTrips(traccar, from, to, devices){
|
|
|
30
29
|
|
|
31
30
|
async function getStops(traccar, from, to, devices){
|
|
32
31
|
const devicesToSlice = devices.slice()
|
|
33
|
-
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
|
|
32
|
+
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice,50)
|
|
34
33
|
let requests = []
|
|
35
34
|
for (const a of arrayOfArrays) {
|
|
36
35
|
const promise = traccar.reports.reportsStopsGet(from, to, a.map(d => d.id))
|
|
@@ -43,7 +42,7 @@ async function getStops(traccar, from, to, devices){
|
|
|
43
42
|
|
|
44
43
|
async function getEvents(traccar, from, to, devices, events){
|
|
45
44
|
const devicesToSlice = devices.slice()
|
|
46
|
-
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
|
|
45
|
+
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice, 50)
|
|
47
46
|
let requests = []
|
|
48
47
|
for (const a of arrayOfArrays) {
|
|
49
48
|
const promise = traccar.reports.reportsEventsGet(from, to, a.map(d => d.id), null, events)
|
|
@@ -55,7 +54,7 @@ async function getEvents(traccar, from, to, devices, events){
|
|
|
55
54
|
|
|
56
55
|
async function getSummary(traccar, from, to, devices){
|
|
57
56
|
const devicesToSlice = devices.slice()
|
|
58
|
-
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
|
|
57
|
+
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice, 50)
|
|
59
58
|
let requests = []
|
|
60
59
|
for (const a of arrayOfArrays) {
|
|
61
60
|
const promise = traccar.reports.reportsSummaryGet(from, to, a.map(d => d.id))
|
|
@@ -74,15 +73,18 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
|
|
|
74
73
|
if(getSummary) url += `&type=summary`
|
|
75
74
|
console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
|
|
76
75
|
|
|
77
|
-
const sliced = automaticReports.sliceArray(devices)
|
|
76
|
+
const sliced = automaticReports.sliceArray(devices, 5)
|
|
78
77
|
let deviceCount = 0
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
const result = []
|
|
79
|
+
for(const chunk of sliced) {
|
|
80
|
+
const requests = chunk.map(d =>
|
|
81
|
+
traccar.axios.get(url + '&' + `deviceId=${d.id}`).then(r => r.data).then(x => {
|
|
82
|
+
console.log('LOADING_MESSAGE:' + d.name)
|
|
83
|
+
console.log(`PROGRESS_PERC:${++deviceCount / devices.length * 100}`)
|
|
84
|
+
return x
|
|
85
|
+
}))
|
|
86
|
+
result.push(...(await Promise.all(requests)))
|
|
87
|
+
}
|
|
86
88
|
return {
|
|
87
89
|
route: result.filter(t => t.route).map(r => r.route).flat(),
|
|
88
90
|
trips: result.filter(t => t.trips).map(r => r.trips).flat(),
|