fleetmap-reports 1.0.336 → 1.0.340
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 +6 -8
- package/src/index.test.js +169 -13
- package/src/util/traccar.js +6 -6
package/package.json
CHANGED
package/src/activity-report.js
CHANGED
|
@@ -58,7 +58,7 @@ async function createActivityReportByGroup(from, to, userData, traccarInstance){
|
|
|
58
58
|
if (summaries.length > 0) {
|
|
59
59
|
|
|
60
60
|
console.log('Summary:' + summaries.length)
|
|
61
|
-
groupData.devices = processDevices(from, to, devices, {summaries: summaries, trips: trips})
|
|
61
|
+
groupData.devices = processDevices(from, to, devices, {summaries: summaries, trips: trips}, userData)
|
|
62
62
|
|
|
63
63
|
reportData.push(groupData)
|
|
64
64
|
}
|
|
@@ -85,13 +85,12 @@ async function createActivityReportByDevice(from, to, userData, traccarInstance)
|
|
|
85
85
|
//Get report data from traccar
|
|
86
86
|
devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
87
87
|
|
|
88
|
-
let summaries = []
|
|
89
88
|
let routeData = []
|
|
90
|
-
|
|
91
|
-
const tripsData =
|
|
89
|
+
let summaries = []
|
|
90
|
+
const tripsData = await traccar.getTrips(traccarInstance, from, to, devicesToProcess)
|
|
92
91
|
|
|
93
92
|
if(userData.groupByDay) {
|
|
94
|
-
routeData =
|
|
93
|
+
routeData = await traccar.getRoute(traccarInstance, from, to, devicesToProcess)
|
|
95
94
|
console.log('trips:' + tripsData.length)
|
|
96
95
|
|
|
97
96
|
if (tripsData.length > 0) {
|
|
@@ -110,14 +109,14 @@ async function createActivityReportByDevice(from, to, userData, traccarInstance)
|
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
} else {
|
|
113
|
-
summaries =
|
|
112
|
+
summaries = await traccar.getSummary(traccarInstance, from, to, devicesToProcess)
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
console.log('Summary:' + summaries.length)
|
|
117
116
|
|
|
118
117
|
//Process report data
|
|
119
118
|
if (summaries.length || tripsData.length) {
|
|
120
|
-
allData.devices = processDevices(from, to, devicesToProcess, {summaries: summaries, trips: tripsData, route: routeData})
|
|
119
|
+
allData.devices = processDevices(from, to, devicesToProcess, {summaries: summaries, trips: tripsData, route: routeData}, userData)
|
|
121
120
|
}
|
|
122
121
|
|
|
123
122
|
return allData
|
|
@@ -179,7 +178,6 @@ function processDevices(from, to, devices, data, userData) {
|
|
|
179
178
|
})
|
|
180
179
|
} else {
|
|
181
180
|
const summaryCurrentDay = data.summaries.filter(s => {
|
|
182
|
-
console.log(s.date.getTime(), date.getTime(), s.date.getTime() === date.getTime())
|
|
183
181
|
return s.deviceId === d.id && s.date.getTime() === date.getTime()})
|
|
184
182
|
|
|
185
183
|
if (summaryCurrentDay.length) {
|
package/src/index.test.js
CHANGED
|
@@ -1,24 +1,180 @@
|
|
|
1
1
|
const {getReports} = require("./tests");
|
|
2
|
+
const assert = require("assert");
|
|
2
3
|
|
|
3
|
-
describe('
|
|
4
|
-
|
|
5
|
-
it('test speeding', async () => {
|
|
4
|
+
describe('Test_Reports', function() {
|
|
5
|
+
it('Speeding by device', async () => {
|
|
6
6
|
const report = await getReports()
|
|
7
7
|
const userData = await report.getUserData()
|
|
8
8
|
|
|
9
|
-
await report.speedingReport(new Date(2021,
|
|
10
|
-
new Date(2021,
|
|
9
|
+
const data = await report.speedingReport(new Date(2021, 11, 6, 0, 0, 0, 0),
|
|
10
|
+
new Date(2021, 11, 8, 23, 59, 59, 0),
|
|
11
11
|
userData)
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
assert.equal(data.length, 1)
|
|
13
|
+
const device = data[0].devices.find(d => d.device.id===22326)
|
|
14
|
+
const totalDistance = device.alerts.reduce((a, b) => a + b.distance, 0)
|
|
15
|
+
const totalEventTime = device.alerts.reduce((a, b) => a + b.eventTime, 0)
|
|
16
|
+
assert.equal(device.alerts.length, 15) // Total Alerts
|
|
17
|
+
assert.equal(totalDistance, 19.605972526552154) // Total Kms
|
|
18
|
+
assert.equal(totalEventTime, 562000) // Total Duration
|
|
19
|
+
}).timeout(20000)
|
|
20
|
+
it('Speeding by device with custom speed', async () => {
|
|
21
|
+
const report = await getReports()
|
|
22
|
+
const userData = await report.getUserData()
|
|
23
|
+
|
|
24
|
+
userData.useVehicleSpeedLimit = false
|
|
25
|
+
userData.customSpeed = 100
|
|
26
|
+
|
|
27
|
+
const data = await report.speedingReport(new Date(2021, 11, 6, 0, 0, 0, 0),
|
|
28
|
+
new Date(2021, 11, 8, 23, 59, 59, 0),
|
|
29
|
+
userData)
|
|
30
|
+
assert.equal(data.length, 1)
|
|
31
|
+
const device = data[0].devices.find(d => d.device.id===22326)
|
|
32
|
+
const totalDistance = device.alerts.reduce((a, b) => a + b.distance, 0)
|
|
33
|
+
const totalEventTime = device.alerts.reduce((a, b) => a + b.eventTime, 0)
|
|
34
|
+
assert.equal(device.alerts.length, 24) // Total Alerts
|
|
35
|
+
assert.equal(totalDistance, 49.49653008204987) // Total Kms
|
|
36
|
+
assert.equal(totalEventTime, 1523000) // Total Duration
|
|
37
|
+
}).timeout(20000)
|
|
38
|
+
it('Trip by device', async () => {
|
|
39
|
+
const report = await getReports()
|
|
40
|
+
const userData = await report.getUserData()
|
|
41
|
+
|
|
42
|
+
const data = await report.tripReport(new Date(2022, 0, 3, 0, 0, 0, 0),
|
|
43
|
+
new Date(2022, 0, 4, 23, 59, 59, 0),
|
|
44
|
+
userData)
|
|
45
|
+
|
|
46
|
+
assert.equal(data.length, 1)
|
|
47
|
+
const device = data[0].devices.find(d => d.device.id===22326)
|
|
48
|
+
assert.equal(device.trips.length, 7) // Total Trips
|
|
49
|
+
assert.equal(device.totalDistance, 339204.53999999166) // Total Kms
|
|
50
|
+
}).timeout(20000)
|
|
51
|
+
it('Trip by device with time period ', async () => {
|
|
52
|
+
const report = await getReports()
|
|
53
|
+
const userData = await report.getUserData()
|
|
54
|
+
|
|
55
|
+
userData.allWeek = false
|
|
56
|
+
userData.weekDays = {
|
|
57
|
+
sunday: true,
|
|
58
|
+
monday: true,
|
|
59
|
+
tuesday: true,
|
|
60
|
+
wednesday: true,
|
|
61
|
+
thursday: true,
|
|
62
|
+
friday: true,
|
|
63
|
+
saturday: true
|
|
64
|
+
}
|
|
65
|
+
userData.dayHours = {
|
|
66
|
+
startTime: '15:00',
|
|
67
|
+
endTime: '19:00'
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const data = await report.tripReport(new Date(2022, 0, 3, 0, 0, 0, 0),
|
|
71
|
+
new Date(2022, 0, 4, 23, 59, 59, 0),
|
|
72
|
+
userData)
|
|
73
|
+
|
|
74
|
+
assert.equal(data.length, 1)
|
|
75
|
+
const device = data[0].devices.find(d => d.device.id===22326)
|
|
76
|
+
assert.equal(device.trips.length, 4) // Total Trips
|
|
77
|
+
assert.equal(device.totalDistance, 265155.1099999994) // Total Kms
|
|
78
|
+
}).timeout(20000)
|
|
79
|
+
it('Trip by device with time period 2', async () => {
|
|
80
|
+
const report = await getReports()
|
|
81
|
+
const userData = await report.getUserData()
|
|
82
|
+
|
|
83
|
+
userData.allWeek = false
|
|
84
|
+
userData.weekDays = {
|
|
85
|
+
sunday: true,
|
|
86
|
+
monday: true,
|
|
87
|
+
tuesday: true,
|
|
88
|
+
wednesday: true,
|
|
89
|
+
thursday: true,
|
|
90
|
+
friday: true,
|
|
91
|
+
saturday: true
|
|
92
|
+
}
|
|
93
|
+
userData.dayHours = {
|
|
94
|
+
startTime: '18:00',
|
|
95
|
+
endTime: '09:00'
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const data = await report.tripReport(new Date(2022, 0, 10, 0, 0, 0, 0),
|
|
99
|
+
new Date(2022, 0, 14, 23, 59, 59, 0),
|
|
100
|
+
userData)
|
|
101
|
+
|
|
102
|
+
assert.equal(data.length, 1)
|
|
103
|
+
const device = data[0].devices.find(d => d.device.id===22326)
|
|
104
|
+
assert.equal(device.trips.length, 18) // Total Trips
|
|
105
|
+
assert.equal(device.totalDistance, 133505.6100000143) // Total Kms
|
|
106
|
+
}).timeout(20000)
|
|
107
|
+
it('Location by device', async () => {
|
|
108
|
+
const report = await getReports()
|
|
109
|
+
const userData = await report.getUserData()
|
|
110
|
+
|
|
111
|
+
const data = await report.locationReport(new Date(2022, 0, 4, 0, 0, 0, 0),
|
|
112
|
+
new Date(2022, 0, 4, 23, 59, 59, 0),
|
|
113
|
+
userData)
|
|
114
|
+
|
|
115
|
+
assert.equal(data.length, 1)
|
|
116
|
+
const device = data[0].devices.find(d => d.device.id===22326)
|
|
117
|
+
assert.equal(device.positions.length, 708) // Total Positions
|
|
118
|
+
}).timeout(20000)
|
|
119
|
+
it('KmsReport by device', async () => {
|
|
14
120
|
const reports = await getReports()
|
|
15
121
|
const userData = await reports.getUserData()
|
|
122
|
+
const data = await reports.kmsReport(new Date(2021, 10, 1, 0, 0,0), new Date(2021, 10, 31, 23, 59, 59),
|
|
123
|
+
userData)
|
|
124
|
+
assert.equal(data.length, 1)
|
|
125
|
+
assert.equal(data.length, 1)
|
|
126
|
+
const device = data[0].devices.find(d => d.device.id===22326)
|
|
127
|
+
assert.equal(device.summary.distance, 1193284.3100000024) // Total Kms
|
|
128
|
+
}).timeout(20000)
|
|
129
|
+
it('KmsReport byDevice groupByDay', async () => {
|
|
130
|
+
const reports = await getReports()
|
|
131
|
+
const userData = await reports.getUserData()
|
|
132
|
+
userData.groupByDay = true
|
|
133
|
+
const data = await reports.kmsReport(new Date(2021, 10, 1, 0, 0,0), new Date(2021, 10, 10, 23, 59, 59),
|
|
134
|
+
userData)
|
|
135
|
+
assert.equal(data.length, 1)
|
|
136
|
+
assert.equal(data.length, 1)
|
|
137
|
+
const device = data[0].devices.find(d => d.device.id===22326)
|
|
138
|
+
assert.equal(device.days.length, 10) // Total Kms
|
|
139
|
+
assert.equal(device.days[5].kms, 23183.010000005364) // Total Kms
|
|
140
|
+
}).timeout(20000)
|
|
141
|
+
it('Idle by device', async () => {
|
|
142
|
+
const report = await getReports()
|
|
143
|
+
const userData = await report.getUserData()
|
|
144
|
+
userData.minimumIdleMinutes = 2
|
|
145
|
+
const data = await report.idleReport(new Date(2022, 0, 3, 0, 0, 0, 0),
|
|
146
|
+
new Date(2022, 0, 7, 23, 59, 59, 0),
|
|
147
|
+
userData)
|
|
148
|
+
assert.equal(data.length, 1)
|
|
149
|
+
const device = data[0].devices.find(d => d.device.id===22326)
|
|
150
|
+
const totalIdleTime = device.idleEvents.reduce((a, b) => a + b.idleTime, 0)
|
|
151
|
+
assert.equal(device.idleEvents.length, 8) // Total Alerts
|
|
152
|
+
assert.equal(totalIdleTime, 1294000) // Total Duration
|
|
153
|
+
}).timeout(20000)
|
|
154
|
+
it('Activity by device', async () => {
|
|
155
|
+
const report = await getReports()
|
|
156
|
+
const userData = await report.getUserData()
|
|
157
|
+
|
|
158
|
+
const data = await report.activityReport(new Date(2022, 0, 1, 0, 0, 0, 0),
|
|
159
|
+
new Date(2022, 0, 31, 23, 59, 59, 0),
|
|
160
|
+
userData)
|
|
161
|
+
assert.equal(data.length, 1)
|
|
162
|
+
const device = data[0].devices.find(d => d.device.id===22326)
|
|
163
|
+
assert.equal(device.summary[0].startOdometer, 122502742.59)
|
|
164
|
+
assert.equal(device.summary[0].distance, 1386519.1300000101)
|
|
165
|
+
}).timeout(20000)
|
|
166
|
+
it('Activity byDevice groupByDay', async () => {
|
|
167
|
+
const report = await getReports()
|
|
168
|
+
const userData = await report.getUserData()
|
|
16
169
|
userData.groupByDay = true
|
|
17
|
-
const
|
|
170
|
+
const data = await report.activityReport(new Date(2022, 0, 1, 0, 0, 0, 0),
|
|
171
|
+
new Date(2022, 0, 20, 23, 59, 59, 0),
|
|
18
172
|
userData)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
173
|
+
assert.equal(data.length, 1)
|
|
174
|
+
const device = data[0].devices.find(d => d.device.id===22326)
|
|
175
|
+
assert.equal(device.summary[5].startOdometer, 122923290.95)
|
|
176
|
+
assert.equal(device.summary[5].distance, 77020.37999999523)
|
|
177
|
+
}).timeout(40000)
|
|
22
178
|
it('test allinone', async() => {
|
|
23
179
|
console.log('Start')
|
|
24
180
|
const reports = await getReports()
|
|
@@ -31,6 +187,6 @@ describe('speedingReport', function() {
|
|
|
31
187
|
true,
|
|
32
188
|
true,
|
|
33
189
|
false)
|
|
34
|
-
|
|
35
|
-
})
|
|
190
|
+
assert.equal(r.trips.length, 10)
|
|
191
|
+
}).timeout(20000)
|
|
36
192
|
})
|
package/src/util/traccar.js
CHANGED
|
@@ -72,9 +72,9 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
|
|
|
72
72
|
if(getTrips) url += `&type=trips`
|
|
73
73
|
if(getStops) url += `&type=stops`
|
|
74
74
|
if(getSummary) url += `&type=summary`
|
|
75
|
+
console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
|
|
75
76
|
|
|
76
|
-
const
|
|
77
|
-
const sliced = automaticReports.sliceArray(devicesToSlice)
|
|
77
|
+
const sliced = automaticReports.sliceArray(devices)
|
|
78
78
|
const requests = sliced.map(a =>
|
|
79
79
|
traccar.axios.get(url + '&' + a.map(d => `deviceId=${d.id}`).join('&')).then(r => r.data).then(x => {
|
|
80
80
|
console.log('LOADING_MESSAGE:' + a.map(d => d.name).join(', '))
|
|
@@ -82,10 +82,10 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
|
|
|
82
82
|
}))
|
|
83
83
|
const result = await Promise.all(requests)
|
|
84
84
|
return {
|
|
85
|
-
route: result.map(r => r.route).flat(),
|
|
86
|
-
trips: result.map(r => r.trips).flat(),
|
|
87
|
-
stops: result.map(r => r.stops).flat(),
|
|
88
|
-
summary: result.map(r => r.summary).flat(),
|
|
85
|
+
route: result.filter(t => t.route).map(r => r.route).flat(),
|
|
86
|
+
trips: result.filter(t => t.trips).map(r => r.trips).flat(),
|
|
87
|
+
stops: result.filter(t => t.result).map(r => r.stops).flat(),
|
|
88
|
+
summary: result.filter(t => t.summay).map(r => r.summary).flat(),
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|