fleetmap-reports 1.0.401 → 1.0.404

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.
@@ -1,100 +1,99 @@
1
- const automaticReports = require("../automaticReports");
1
+ const automaticReports = require('../automaticReports')
2
2
 
3
- async function getRoute(traccar, from, to, devices){
4
- const devicesToSlice = devices.slice()
3
+ async function getRoute (traccar, from, to, devices) {
4
+ const devicesToSlice = devices.slice()
5
5
 
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
- }
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
- const result = await Promise.all(requests)
14
- return result.map(r => r.data).flat()
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
- 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
- }
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
- const result = await Promise.all(requests)
27
- return result.map(r => r.data).flat()
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
- 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
- }
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
- const result = await Promise.all(requests)
40
- return result.map(r => r.data).flat()
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
- 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()
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
- 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
- }
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
- const result = await Promise.all(requests)
65
- return result.map(r => r.data).flat()
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
- 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`
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
- 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
-
86
- deviceCount = deviceCount + 1
87
- console.log(`PROGRESS_PERC:${deviceCount / totalDevices * 100}`)
88
- return x
89
- }))
90
- result.push(...(await Promise.all(requests)))
91
- }
92
- return {
93
- route: result.filter(t => t.route).map(r => r.route).flat(),
94
- trips: result.filter(t => t.trips).map(r => r.trips).flat(),
95
- stops: result.filter(t => t.stops).map(r => r.stops).flat(),
96
- summary: result.filter(t => t.summary).map(r => r.summary).flat(),
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
@@ -175,7 +175,7 @@ function getInAndOutEvents(devices, route, userData) {
175
175
  }
176
176
  }
177
177
  if(g.geometry.type === 'Point') {
178
- if (distance(p, g, {units: 'meters'}) < g.properties.distance) {
178
+ if (distance.default(p, g, {units: 'meters'}) < g.properties.distance) {
179
179
  if (!entryMap.includes(g)) {
180
180
  events.push(createEvent('geofenceEnter',d.id,p,g))
181
181
  entryMap.push(g)