fleetmap-reports 1.0.401 → 1.0.402
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/activity-report.js +697 -687
- package/src/trip-report.js +384 -385
- package/src/util/traccar.js +79 -80
package/src/util/traccar.js
CHANGED
|
@@ -1,100 +1,99 @@
|
|
|
1
|
-
const automaticReports = require(
|
|
1
|
+
const automaticReports = require('../automaticReports')
|
|
2
2
|
|
|
3
|
-
async function getRoute(traccar, from, to, devices){
|
|
4
|
-
|
|
3
|
+
async function getRoute (traccar, from, to, devices) {
|
|
4
|
+
const devicesToSlice = devices.slice()
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice, 50)
|
|
7
|
+
let requests = []
|
|
8
|
+
for (const a of arrayOfArrays) {
|
|
9
|
+
const promise = traccar.reports.reportsRouteGet(from, to, a.map(d => d.id))
|
|
10
|
+
requests = requests.concat(promise)
|
|
11
|
+
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const result = await Promise.all(requests)
|
|
14
|
+
return result.map(r => r.data).flat()
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
async function getTrips(traccar, from, to, devices){
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
async function getTrips (traccar, from, to, devices) {
|
|
18
|
+
const devicesToSlice = devices.slice()
|
|
19
|
+
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice, 50)
|
|
20
|
+
let requests = []
|
|
21
|
+
for (const a of arrayOfArrays) {
|
|
22
|
+
const promise = traccar.reports.reportsTripsGet(from, to, a.map(d => d.id))
|
|
23
|
+
requests = requests.concat(promise)
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const result = await Promise.all(requests)
|
|
27
|
+
return result.map(r => r.data).flat()
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
async function getStops(traccar, from, to, devices){
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
async function getStops (traccar, from, to, devices) {
|
|
31
|
+
const devicesToSlice = devices.slice()
|
|
32
|
+
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice, 50)
|
|
33
|
+
let requests = []
|
|
34
|
+
for (const a of arrayOfArrays) {
|
|
35
|
+
const promise = traccar.reports.reportsStopsGet(from, to, a.map(d => d.id))
|
|
36
|
+
requests = requests.concat(promise)
|
|
37
|
+
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const result = await Promise.all(requests)
|
|
40
|
+
return result.map(r => r.data).flat()
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
async function getEvents(traccar, from, to, devices, events){
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
async function getEvents (traccar, from, to, devices, events) {
|
|
44
|
+
const devicesToSlice = devices.slice()
|
|
45
|
+
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice, 50)
|
|
46
|
+
let requests = []
|
|
47
|
+
for (const a of arrayOfArrays) {
|
|
48
|
+
const promise = traccar.reports.reportsEventsGet(from, to, a.map(d => d.id), null, events)
|
|
49
|
+
requests = requests.concat(promise)
|
|
50
|
+
}
|
|
51
|
+
const result = await Promise.all(requests)
|
|
52
|
+
return result.map(r => r.data).flat()
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
async function getSummary(traccar, from, to, devices){
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
async function getSummary (traccar, from, to, devices) {
|
|
56
|
+
const devicesToSlice = devices.slice()
|
|
57
|
+
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice, 50)
|
|
58
|
+
let requests = []
|
|
59
|
+
for (const a of arrayOfArrays) {
|
|
60
|
+
const promise = traccar.reports.reportsSummaryGet(from, to, a.map(d => d.id))
|
|
61
|
+
requests = requests.concat(promise)
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const result = await Promise.all(requests)
|
|
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){
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
async function getAllInOne (traccar, from, to, devices, getRoutes, getTrips, getStops, getSummary, currentDeviceCount = 0, totalDevices = devices.length) {
|
|
69
|
+
let url = `/reports/allinone?&from=${from.toISOString()}&to=${to.toISOString()}`
|
|
70
|
+
if (getRoutes) url += '&type=route'
|
|
71
|
+
if (getTrips) url += '&type=trips'
|
|
72
|
+
if (getStops) url += '&type=stops'
|
|
73
|
+
if (getSummary) url += '&type=summary'
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
75
|
+
const sliced = automaticReports.sliceArray(devices, 5)
|
|
76
|
+
const result = []
|
|
77
|
+
let deviceCount = currentDeviceCount
|
|
78
|
+
for (const chunk of sliced) {
|
|
79
|
+
const requests = chunk.map(d =>
|
|
80
|
+
traccar.axios.get(url + '&' + `deviceId=${d.id}`, {
|
|
81
|
+
jar: traccar.cookieJar,
|
|
82
|
+
withCredentials: true
|
|
83
|
+
}).then(r => r.data).then(x => {
|
|
84
|
+
console.log('LOADING_MESSAGE:' + d.name)
|
|
85
|
+
deviceCount = deviceCount + 1
|
|
86
|
+
console.log(`PROGRESS_PERC:${deviceCount / totalDevices * 100}`)
|
|
87
|
+
return x
|
|
88
|
+
}))
|
|
89
|
+
result.push(...(await Promise.all(requests)))
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
route: result.filter(t => t.route).map(r => r.route).flat(),
|
|
93
|
+
trips: result.filter(t => t.trips).map(r => r.trips).flat(),
|
|
94
|
+
stops: result.filter(t => t.stops).map(r => r.stops).flat(),
|
|
95
|
+
summary: result.filter(t => t.summary).map(r => r.summary).flat()
|
|
96
|
+
}
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
exports.getRoute = getRoute
|