fleetmap-reports 1.0.337 → 1.0.342
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 +2 -1
- package/src/activity-report.js +9 -13
- package/src/index.test.js +170 -13
- package/src/util/traccar.js +6 -7
- package/src/here.test.js +0 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleetmap-reports",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.342",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"axios-debug-log": "^0.8.4",
|
|
31
|
+
"jest": "^27.5.0",
|
|
31
32
|
"mocha": "^9.0.3",
|
|
32
33
|
"webpack": "^5.24.3",
|
|
33
34
|
"webpack-cli": "^4.5.0"
|
package/src/activity-report.js
CHANGED
|
@@ -9,7 +9,7 @@ const {getStyle} = require("./reportStyle")
|
|
|
9
9
|
const {getUserPartner} = require("fleetmap-partners")
|
|
10
10
|
const traccar = require("./util/traccar")
|
|
11
11
|
const {isInsideTimetable, isPartialInsideTimetable} = require("./util/trips");
|
|
12
|
-
const
|
|
12
|
+
const tripHelper = require("./util/trips");
|
|
13
13
|
|
|
14
14
|
const fileName = 'ActivityReport'
|
|
15
15
|
|
|
@@ -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
|
}
|
|
@@ -86,16 +86,13 @@ async function createActivityReportByDevice(from, to, userData, traccarInstance)
|
|
|
86
86
|
devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
87
87
|
|
|
88
88
|
let summaries = []
|
|
89
|
-
|
|
90
|
-
const allInOne = await traccar.getAllInOne(traccarInstance, from, to, devicesToProcess, userData.groupByDay && !userData.allWeek, true, false, !userData.groupByDay)
|
|
91
|
-
const tripsData = allInOne.trips
|
|
89
|
+
const {trips, route, summary} = await traccar.getAllInOne(traccarInstance, from, to, devicesToProcess, userData.groupByDay && !userData.allWeek, true, false, !userData.groupByDay)
|
|
92
90
|
|
|
93
91
|
if(userData.groupByDay) {
|
|
94
|
-
|
|
95
|
-
console.log('trips:' + tripsData.length)
|
|
92
|
+
console.log('trips:' + trips.length)
|
|
96
93
|
|
|
97
|
-
if (
|
|
98
|
-
|
|
94
|
+
if (trips.length) {
|
|
95
|
+
tripHelper.checkTripsKms(traccarInstance, from, to, devicesToProcess, {trips, route})
|
|
99
96
|
}
|
|
100
97
|
|
|
101
98
|
const dates = getDates(from, to)
|
|
@@ -110,14 +107,14 @@ async function createActivityReportByDevice(from, to, userData, traccarInstance)
|
|
|
110
107
|
}
|
|
111
108
|
}
|
|
112
109
|
} else {
|
|
113
|
-
summaries =
|
|
110
|
+
summaries = summary
|
|
114
111
|
}
|
|
115
112
|
|
|
116
113
|
console.log('Summary:' + summaries.length)
|
|
117
114
|
|
|
118
115
|
//Process report data
|
|
119
|
-
if (summaries.length ||
|
|
120
|
-
allData.devices = processDevices(from, to, devicesToProcess, {summaries: summaries, trips
|
|
116
|
+
if (summaries.length || trips.length) {
|
|
117
|
+
allData.devices = processDevices(from, to, devicesToProcess, {summaries: summaries, trips, route}, userData)
|
|
121
118
|
}
|
|
122
119
|
|
|
123
120
|
return allData
|
|
@@ -179,7 +176,6 @@ function processDevices(from, to, devices, data, userData) {
|
|
|
179
176
|
})
|
|
180
177
|
} else {
|
|
181
178
|
const summaryCurrentDay = data.summaries.filter(s => {
|
|
182
|
-
console.log(s.date.getTime(), date.getTime(), s.date.getTime() === date.getTime())
|
|
183
179
|
return s.deviceId === d.id && s.date.getTime() === date.getTime()})
|
|
184
180
|
|
|
185
181
|
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
|
+
}, 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
|
+
}, 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
|
+
}, 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
|
+
},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
|
+
},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
|
+
},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
|
+
},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
|
+
},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
|
+
},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
|
+
}, 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
|
+
}, 40000)
|
|
22
178
|
it('test allinone', async() => {
|
|
23
179
|
console.log('Start')
|
|
24
180
|
const reports = await getReports()
|
|
@@ -31,6 +187,7 @@ describe('speedingReport', function() {
|
|
|
31
187
|
true,
|
|
32
188
|
true,
|
|
33
189
|
false)
|
|
34
|
-
|
|
35
|
-
|
|
190
|
+
assert.equal(r.trips.length, 10)
|
|
191
|
+
assert.equal(r.stops.length, 11)
|
|
192
|
+
}, 20000)
|
|
36
193
|
})
|
package/src/util/traccar.js
CHANGED
|
@@ -72,10 +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
|
-
|
|
76
|
-
const devicesToSlice = devices.slice()
|
|
77
|
-
const sliced = automaticReports.sliceArray(devicesToSlice)
|
|
78
75
|
console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
|
|
76
|
+
|
|
77
|
+
const sliced = automaticReports.sliceArray(devices)
|
|
79
78
|
const requests = sliced.map(a =>
|
|
80
79
|
traccar.axios.get(url + '&' + a.map(d => `deviceId=${d.id}`).join('&')).then(r => r.data).then(x => {
|
|
81
80
|
console.log('LOADING_MESSAGE:' + a.map(d => d.name).join(', '))
|
|
@@ -83,10 +82,10 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
|
|
|
83
82
|
}))
|
|
84
83
|
const result = await Promise.all(requests)
|
|
85
84
|
return {
|
|
86
|
-
route: result.map(r => r.route).flat(),
|
|
87
|
-
trips: result.map(r => r.trips).flat(),
|
|
88
|
-
stops: result.map(r => r.stops).flat(),
|
|
89
|
-
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.stops).map(r => r.stops).flat(),
|
|
88
|
+
summary: result.filter(t => t.summary).map(r => r.summary).flat(),
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
91
|
|
package/src/here.test.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const here = require('./here')
|
|
2
|
-
|
|
3
|
-
require('axios-debug-log')({
|
|
4
|
-
request: function (debug, config) {
|
|
5
|
-
console.log('Req headers:', config.headers.common)
|
|
6
|
-
},
|
|
7
|
-
response: function (debug, response) {
|
|
8
|
-
console.log(
|
|
9
|
-
'Response Headers:', response.headers,
|
|
10
|
-
'from', response.config.url
|
|
11
|
-
)
|
|
12
|
-
},
|
|
13
|
-
error: function (debug, error) {
|
|
14
|
-
// Read https://www.npmjs.com/package/axios#handling-errors for more info
|
|
15
|
-
console.error('Boom', error)
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
describe('here', async () => {
|
|
20
|
-
it('here', async () => {
|
|
21
|
-
console.log(process.env.HERE_API_KEY)
|
|
22
|
-
const rows = [{latitude:0, longitude:0, fixtime:new Date().toISOString(), speed:0, course:0}]
|
|
23
|
-
console.dir(await here.routeMatch(rows), {depth: null})
|
|
24
|
-
})
|
|
25
|
-
})
|