fleetmap-reports 1.0.244 → 1.0.248
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/.idea/workspace.xml +69 -24
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/index.test.js +27 -2
- package/src/kms-report.js +74 -25
- package/src/speeding-report.js +20 -33
- package/src/trip-report.js +49 -47
- package/src/util/driver.js +3 -9
- package/src/util/traccar.js +27 -1
- package/.idea/shelf/Uncommitted_changes_before_Update_at_25_11_2021,_13_06_[Changes]/shelved.patch +0 -302
- package/.idea/shelf/Uncommitted_changes_before_Update_at_25_11_2021,_13_10_[Changes]/shelved.patch +0 -233
- package/.idea/shelf/Uncommitted_changes_before_Update_at_25_11_2021__13_06__Changes_.xml +0 -4
- package/.idea/shelf/Uncommitted_changes_before_Update_at_25_11_2021__13_10__Changes_.xml +0 -4
package/.idea/workspace.xml
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<project version="4">
|
|
3
3
|
<component name="ChangeListManager">
|
|
4
|
-
<list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="
|
|
5
|
-
<change beforePath="$PROJECT_DIR$/
|
|
4
|
+
<list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="refactor speeding and trip report">
|
|
5
|
+
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
6
6
|
<change beforePath="$PROJECT_DIR$/src/index.test.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.test.js" afterDir="false" />
|
|
7
7
|
<change beforePath="$PROJECT_DIR$/src/kms-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/kms-report.js" afterDir="false" />
|
|
8
|
-
<change beforePath="$PROJECT_DIR$/src/util/
|
|
8
|
+
<change beforePath="$PROJECT_DIR$/src/util/utils.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/util/utils.js" afterDir="false" />
|
|
9
9
|
</list>
|
|
10
10
|
<option name="SHOW_DIALOG" value="false" />
|
|
11
11
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -37,34 +37,44 @@
|
|
|
37
37
|
<property name="ts.external.directory.path" value="$APPLICATION_HOME_DIR$/plugins/JavaScriptLanguage/jsLanguageServicesImpl/external" />
|
|
38
38
|
<property name="vue.rearranger.settings.migration" value="true" />
|
|
39
39
|
</component>
|
|
40
|
-
<component name="RunManager" selected="Mocha.
|
|
41
|
-
<configuration name="report" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
|
|
40
|
+
<component name="RunManager" selected="Mocha.Reports.test event report">
|
|
41
|
+
<configuration name="Reports.test event report" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
|
|
42
42
|
<node-interpreter>project</node-interpreter>
|
|
43
43
|
<node-options />
|
|
44
44
|
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
|
|
45
45
|
<working-directory>$PROJECT_DIR$</working-directory>
|
|
46
46
|
<pass-parent-env>true</pass-parent-env>
|
|
47
|
+
<envs>
|
|
48
|
+
<env name="email" value="jppenas@gmail.com" />
|
|
49
|
+
<env name="password" value="penas46881" />
|
|
50
|
+
</envs>
|
|
47
51
|
<ui>bdd</ui>
|
|
48
52
|
<extra-mocha-options />
|
|
49
|
-
<test-kind>
|
|
53
|
+
<test-kind>TEST</test-kind>
|
|
50
54
|
<test-file>$PROJECT_DIR$/src/index.test.js</test-file>
|
|
51
55
|
<test-names>
|
|
52
|
-
<name value="
|
|
56
|
+
<name value="Reports" />
|
|
57
|
+
<name value="test event report" />
|
|
53
58
|
</test-names>
|
|
54
59
|
<method v="2" />
|
|
55
60
|
</configuration>
|
|
56
|
-
<configuration name="
|
|
61
|
+
<configuration name="Reports.test trip report" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
|
|
57
62
|
<node-interpreter>project</node-interpreter>
|
|
58
63
|
<node-options />
|
|
59
64
|
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
|
|
60
65
|
<working-directory>$PROJECT_DIR$</working-directory>
|
|
61
66
|
<pass-parent-env>true</pass-parent-env>
|
|
67
|
+
<envs>
|
|
68
|
+
<env name="email" value="jppenas@gmail.com" />
|
|
69
|
+
<env name="password" value="penas46881" />
|
|
70
|
+
</envs>
|
|
62
71
|
<ui>bdd</ui>
|
|
63
72
|
<extra-mocha-options />
|
|
64
73
|
<test-kind>TEST</test-kind>
|
|
65
74
|
<test-file>$PROJECT_DIR$/src/index.test.js</test-file>
|
|
66
75
|
<test-names>
|
|
67
|
-
<name value="
|
|
76
|
+
<name value="Reports" />
|
|
77
|
+
<name value="test trip report" />
|
|
68
78
|
</test-names>
|
|
69
79
|
<method v="2" />
|
|
70
80
|
</configuration>
|
|
@@ -88,7 +98,7 @@
|
|
|
88
98
|
</test-names>
|
|
89
99
|
<method v="2" />
|
|
90
100
|
</configuration>
|
|
91
|
-
<configuration name="test
|
|
101
|
+
<configuration name="speedingReport.test speeding" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
|
|
92
102
|
<node-interpreter>project</node-interpreter>
|
|
93
103
|
<node-options />
|
|
94
104
|
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
|
|
@@ -100,43 +110,47 @@
|
|
|
100
110
|
</envs>
|
|
101
111
|
<ui>bdd</ui>
|
|
102
112
|
<extra-mocha-options />
|
|
103
|
-
<test-kind>
|
|
113
|
+
<test-kind>TEST</test-kind>
|
|
104
114
|
<test-file>$PROJECT_DIR$/src/index.test.js</test-file>
|
|
105
115
|
<test-names>
|
|
106
|
-
<name value="
|
|
116
|
+
<name value="speedingReport" />
|
|
117
|
+
<name value="test speeding" />
|
|
107
118
|
</test-names>
|
|
108
119
|
<method v="2" />
|
|
109
120
|
</configuration>
|
|
110
|
-
<configuration name="test reports
|
|
121
|
+
<configuration name="test reports" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
|
|
111
122
|
<node-interpreter>project</node-interpreter>
|
|
112
123
|
<node-options />
|
|
113
124
|
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
|
|
114
125
|
<working-directory>$PROJECT_DIR$</working-directory>
|
|
115
126
|
<pass-parent-env>true</pass-parent-env>
|
|
127
|
+
<envs>
|
|
128
|
+
<env name="email" value="jppenas@gmail.com" />
|
|
129
|
+
<env name="password" value="penas46881" />
|
|
130
|
+
</envs>
|
|
116
131
|
<ui>bdd</ui>
|
|
117
132
|
<extra-mocha-options />
|
|
118
|
-
<test-kind>
|
|
133
|
+
<test-kind>SUITE</test-kind>
|
|
119
134
|
<test-file>$PROJECT_DIR$/src/index.test.js</test-file>
|
|
120
135
|
<test-names>
|
|
121
136
|
<name value="test reports" />
|
|
122
|
-
<name value="test queue" />
|
|
123
137
|
</test-names>
|
|
124
138
|
<method v="2" />
|
|
125
139
|
</configuration>
|
|
126
140
|
<list>
|
|
127
|
-
<item itemvalue="Mocha.report" />
|
|
128
|
-
<item itemvalue="Mocha.speedingReport" />
|
|
129
141
|
<item itemvalue="Mocha.test reports" />
|
|
130
|
-
<item itemvalue="Mocha.test reports.test queue" />
|
|
131
142
|
<item itemvalue="Mocha.speedingReport.test kmsReport by day" />
|
|
143
|
+
<item itemvalue="Mocha.speedingReport.test speeding" />
|
|
144
|
+
<item itemvalue="Mocha.Reports.test trip report" />
|
|
145
|
+
<item itemvalue="Mocha.Reports.test event report" />
|
|
132
146
|
</list>
|
|
133
147
|
<recent_temporary>
|
|
134
148
|
<list>
|
|
149
|
+
<item itemvalue="Mocha.Reports.test event report" />
|
|
150
|
+
<item itemvalue="Mocha.Reports.test trip report" />
|
|
151
|
+
<item itemvalue="Mocha.speedingReport.test speeding" />
|
|
135
152
|
<item itemvalue="Mocha.speedingReport.test kmsReport by day" />
|
|
136
153
|
<item itemvalue="Mocha.test reports" />
|
|
137
|
-
<item itemvalue="Mocha.test reports.test queue" />
|
|
138
|
-
<item itemvalue="Mocha.speedingReport" />
|
|
139
|
-
<item itemvalue="Mocha.report" />
|
|
140
154
|
</list>
|
|
141
155
|
</recent_temporary>
|
|
142
156
|
</component>
|
|
@@ -171,7 +185,14 @@
|
|
|
171
185
|
<workItem from="1637868513425" duration="1650000" />
|
|
172
186
|
<workItem from="1637928687573" duration="37000" />
|
|
173
187
|
<workItem from="1637931438656" duration="621000" />
|
|
174
|
-
<workItem from="1637952151523" duration="
|
|
188
|
+
<workItem from="1637952151523" duration="17766000" />
|
|
189
|
+
<workItem from="1638270786569" duration="6960000" />
|
|
190
|
+
<workItem from="1638455902437" duration="120000" />
|
|
191
|
+
<workItem from="1638486745343" duration="4126000" />
|
|
192
|
+
<workItem from="1638792860278" duration="2140000" />
|
|
193
|
+
<workItem from="1638839462028" duration="50000" />
|
|
194
|
+
<workItem from="1638840110567" duration="597000" />
|
|
195
|
+
<workItem from="1638888787940" duration="18005000" />
|
|
175
196
|
</task>
|
|
176
197
|
<task id="LOCAL-00001" summary="Fix getStyle">
|
|
177
198
|
<created>1636983717385</created>
|
|
@@ -215,7 +236,28 @@
|
|
|
215
236
|
<option name="project" value="LOCAL" />
|
|
216
237
|
<updated>1637858604089</updated>
|
|
217
238
|
</task>
|
|
218
|
-
<
|
|
239
|
+
<task id="LOCAL-00007" summary="Kms Report - Calculate distance with traccar trips">
|
|
240
|
+
<created>1638179219255</created>
|
|
241
|
+
<option name="number" value="00007" />
|
|
242
|
+
<option name="presentableId" value="LOCAL-00007" />
|
|
243
|
+
<option name="project" value="LOCAL" />
|
|
244
|
+
<updated>1638179219256</updated>
|
|
245
|
+
</task>
|
|
246
|
+
<task id="LOCAL-00008" summary="fix speeding report">
|
|
247
|
+
<created>1638186780966</created>
|
|
248
|
+
<option name="number" value="00008" />
|
|
249
|
+
<option name="presentableId" value="LOCAL-00008" />
|
|
250
|
+
<option name="project" value="LOCAL" />
|
|
251
|
+
<updated>1638186780967</updated>
|
|
252
|
+
</task>
|
|
253
|
+
<task id="LOCAL-00009" summary="refactor speeding and trip report">
|
|
254
|
+
<created>1638288337133</created>
|
|
255
|
+
<option name="number" value="00009" />
|
|
256
|
+
<option name="presentableId" value="LOCAL-00009" />
|
|
257
|
+
<option name="project" value="LOCAL" />
|
|
258
|
+
<updated>1638288337135</updated>
|
|
259
|
+
</task>
|
|
260
|
+
<option name="localTasksCounter" value="10" />
|
|
219
261
|
<servers />
|
|
220
262
|
</component>
|
|
221
263
|
<component name="TypeScriptGeneratedFilesManager">
|
|
@@ -240,6 +282,9 @@
|
|
|
240
282
|
<MESSAGE value="Kms report grouped by day" />
|
|
241
283
|
<MESSAGE value="Fix pdf logo" />
|
|
242
284
|
<MESSAGE value="kms report with parallel requests" />
|
|
243
|
-
<
|
|
285
|
+
<MESSAGE value="Kms Report - Calculate distance with traccar trips" />
|
|
286
|
+
<MESSAGE value="fix speeding report" />
|
|
287
|
+
<MESSAGE value="refactor speeding and trip report" />
|
|
288
|
+
<option name="LAST_COMMIT_MESSAGE" value="refactor speeding and trip report" />
|
|
244
289
|
</component>
|
|
245
290
|
</project>
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -23,7 +23,7 @@ function Reports(config, axios) {
|
|
|
23
23
|
return require('./speeding-report').createSpeedingReport(from, to, userData, this.traccar, roadSpeedLimits)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
this.speedingReportToPDF =
|
|
26
|
+
this.speedingReportToPDF = (userData, reportData) => {
|
|
27
27
|
return require('./speeding-report').exportSpeedingReportToPDF(userData, reportData)
|
|
28
28
|
}
|
|
29
29
|
|
package/src/index.test.js
CHANGED
|
@@ -1,14 +1,39 @@
|
|
|
1
1
|
const {getReports} = require("./tests");
|
|
2
2
|
|
|
3
|
-
describe('
|
|
3
|
+
describe('Reports', function() {
|
|
4
4
|
this.timeout(500000)
|
|
5
5
|
it('test speeding', async () => {
|
|
6
6
|
const report = await getReports()
|
|
7
7
|
const userData = await report.getUserData()
|
|
8
8
|
|
|
9
|
-
await report.speedingReport(new Date(2021, 2, 30, 0, 0, 0, 0),
|
|
9
|
+
const reportData = await report.speedingReport(new Date(2021, 2, 30, 0, 0, 0, 0),
|
|
10
10
|
new Date(2021, 2, 30, 23, 59, 59, 0),
|
|
11
11
|
userData)
|
|
12
|
+
|
|
13
|
+
console.log(reportData)
|
|
14
|
+
|
|
15
|
+
})
|
|
16
|
+
it('test trip report', async () => {
|
|
17
|
+
const report = await getReports()
|
|
18
|
+
const userData = await report.getUserData()
|
|
19
|
+
userData.byGroup = true
|
|
20
|
+
const reportData = await report.tripReport(new Date(2021, 2, 30, 0, 0, 0, 0),
|
|
21
|
+
new Date(2021, 2, 30, 23, 59, 59, 0),
|
|
22
|
+
userData)
|
|
23
|
+
|
|
24
|
+
console.log(reportData)
|
|
25
|
+
|
|
26
|
+
})
|
|
27
|
+
it('test event report', async () => {
|
|
28
|
+
const report = await getReports()
|
|
29
|
+
const userData = await report.getUserData()
|
|
30
|
+
userData.eventTypes = []
|
|
31
|
+
const reportData = await report.eventsReport(new Date(2021, 10, 20, 0, 0, 0, 0),
|
|
32
|
+
new Date(2021, 10, 30, 23, 59, 59, 0),
|
|
33
|
+
userData)
|
|
34
|
+
|
|
35
|
+
console.log(reportData)
|
|
36
|
+
|
|
12
37
|
})
|
|
13
38
|
it('test kmsReport by day', async () => {
|
|
14
39
|
const reports = await getReports()
|
package/src/kms-report.js
CHANGED
|
@@ -9,10 +9,11 @@ const traccar = require("./util/traccar");
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
let traccarInstance
|
|
12
|
+
let userData
|
|
12
13
|
|
|
13
14
|
const fileName = 'KmsReport'
|
|
14
15
|
|
|
15
|
-
async function createKmsReportByDevice(from, to
|
|
16
|
+
async function createKmsReportByDevice(from, to) {
|
|
16
17
|
const groupIds = userData.groups.map(g => g.id)
|
|
17
18
|
const devicesToProcess = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
18
19
|
|
|
@@ -23,54 +24,99 @@ async function createKmsReportByDevice(from, to, userData) {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
26
|
-
|
|
27
|
-
const
|
|
27
|
+
const route = userData.allWeek ? [] : await traccar.getRoute(traccarInstance, from, to, devicesToProcess)
|
|
28
|
+
const trips = await traccar.getTrips(traccarInstance, from, to, devicesToProcess)
|
|
28
29
|
|
|
29
|
-
console.log('trips:' +
|
|
30
|
+
console.log('trips:' + trips.length)
|
|
30
31
|
|
|
31
|
-
if (
|
|
32
|
-
allData.devices = processDevices(from, to, devicesToProcess,
|
|
32
|
+
if (trips.length > 0) {
|
|
33
|
+
allData.devices = processDevices(from, to, devicesToProcess, route, trips)
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
return allData
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
async function createKmsReportByDriver(from, to
|
|
39
|
+
async function createKmsReportByDriver(from, to) {
|
|
39
40
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
async function createKmsReportByGroup(from, to
|
|
43
|
+
async function createKmsReportByGroup(from, to) {
|
|
43
44
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
function processDevices(from, to, devices,
|
|
47
|
+
function processDevices(from, to, devices, route, trips) {
|
|
47
48
|
const devicesResult = []
|
|
48
49
|
|
|
49
50
|
for (const d of devices) {
|
|
50
|
-
const
|
|
51
|
+
const deviceTrips = trips.filter(t => t.deviceId === d.id)
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const groupedTrips =
|
|
53
|
+
if (deviceTrips.length > 0) {
|
|
54
|
+
deviceTrips.forEach(t => t.tripDay = new Date(t.startTime).toISOString().split('T')[0] + ' 12:00 PM')
|
|
55
|
+
const groupedTrips = deviceTrips.reduce(
|
|
55
56
|
(entryMap, e) => entryMap.set(e.tripDay, [...entryMap.get(e.tripDay)||[], e]),
|
|
56
57
|
new Map()
|
|
57
58
|
)
|
|
58
59
|
|
|
59
60
|
const days = []
|
|
60
61
|
const keys = Array.from(groupedTrips.keys())
|
|
61
|
-
|
|
62
62
|
keys.forEach(key => {
|
|
63
|
-
const
|
|
63
|
+
const currentDate = new Date(key)
|
|
64
|
+
let dayTrips = groupedTrips.get(key)
|
|
64
65
|
const day = {
|
|
65
|
-
date:
|
|
66
|
-
kms:
|
|
66
|
+
date: currentDate,
|
|
67
|
+
kms: 0
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if(userData.allWeek){
|
|
71
|
+
day.kms = dayTrips.reduce((a, b) => a + b.distance, 0) || 0
|
|
72
|
+
} else {
|
|
73
|
+
if((currentDate.getDay() === 0 && userData.weekDays.sunday) ||
|
|
74
|
+
(currentDate.getDay() === 1 && userData.weekDays.monday) ||
|
|
75
|
+
(currentDate.getDay() === 2 && userData.weekDays.tuesday) ||
|
|
76
|
+
(currentDate.getDay() === 3 && userData.weekDays.wednesday) ||
|
|
77
|
+
(currentDate.getDay() === 4 && userData.weekDays.thursday) ||
|
|
78
|
+
(currentDate.getDay() === 5 && userData.weekDays.friday) ||
|
|
79
|
+
(currentDate.getDay() === 6 && userData.weekDays.saturday)) {
|
|
80
|
+
|
|
81
|
+
const startDate = new Date(new Date(key).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
|
|
82
|
+
const endDate = new Date(new Date(key).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
|
|
83
|
+
|
|
84
|
+
console.log(key, startDate, endDate)
|
|
85
|
+
|
|
86
|
+
//Trips inside time period
|
|
87
|
+
const filteredTrips = dayTrips.filter(t => new Date(t.startTime).getTime() > startDate.getTime()
|
|
88
|
+
&& new Date(t.endTime).getTime() < endDate.getTime())
|
|
89
|
+
|
|
90
|
+
//Trip starts outside time period and ends inside time period
|
|
91
|
+
const startIncompleteTrip = dayTrips.filter(t => new Date(t.startTime).getTime() < startDate.getTime()
|
|
92
|
+
&& new Date(t.endTime).getTime() > startDate.getTime())
|
|
93
|
+
|
|
94
|
+
//Trip starts inside time period and ends outside time period
|
|
95
|
+
const endIncompleteTrip = dayTrips.filter(t => new Date(t.startTime).getTime() < endDate.getTime()
|
|
96
|
+
&& new Date(t.endTime).getTime() > endDate.getTime())
|
|
97
|
+
|
|
98
|
+
day.kms = filteredTrips.reduce((a, b) => a + b.distance, 0) || 0
|
|
99
|
+
console.log('Inside trips:'+day.kms)
|
|
100
|
+
|
|
101
|
+
if(startIncompleteTrip.length){
|
|
102
|
+
const routeInside = route.filter(p => new Date(p.fixTime).getTime() > startDate.getTime() && new Date(p.fixTime).getTime() < new Date(startIncompleteTrip[0].endTime).getTime())
|
|
103
|
+
day.kms = day.kms + (routeInside.reduce((a, b) => a + b.distance, 0) || 0)
|
|
104
|
+
console.log('startIncompleteTrip:'+day.kms)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if(endIncompleteTrip.length){
|
|
108
|
+
const routeInside = route.filter(p => new Date(p.fixTime).getTime() < endDate.getTime() && new Date(p.fixTime).getTime() > new Date(endIncompleteTrip[0].startTime).getTime())
|
|
109
|
+
day.kms = day.kms + (routeInside.reduce((a, b) => a + b.distance, 0) || 0)
|
|
110
|
+
console.log('endIncompleteTrip:'+day.kms)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
67
113
|
}
|
|
114
|
+
|
|
68
115
|
days.push(day)
|
|
69
116
|
})
|
|
70
|
-
|
|
71
117
|
devicesResult.push({
|
|
72
|
-
|
|
73
|
-
|
|
118
|
+
device: d,
|
|
119
|
+
days: days
|
|
74
120
|
})
|
|
75
121
|
}
|
|
76
122
|
}
|
|
@@ -78,23 +124,26 @@ function processDevices(from, to, devices, data) {
|
|
|
78
124
|
return devicesResult
|
|
79
125
|
}
|
|
80
126
|
|
|
81
|
-
async function createKmsReport(from, to,
|
|
127
|
+
async function createKmsReport(from, to, reportUserData, traccar) {
|
|
82
128
|
console.log('Create KmsReport')
|
|
129
|
+
|
|
130
|
+
console.log(from, to)
|
|
83
131
|
traccarInstance = traccar
|
|
132
|
+
userData = reportUserData
|
|
84
133
|
if(userData.groupByDay){
|
|
85
134
|
const reportData = []
|
|
86
135
|
|
|
87
136
|
if(userData.byDriver){
|
|
88
|
-
const allData = await createKmsReportByDriver(from, to
|
|
137
|
+
const allData = await createKmsReportByDriver(from, to)
|
|
89
138
|
reportData.push(allData)
|
|
90
139
|
}
|
|
91
140
|
else if(userData.byGroup){
|
|
92
|
-
const allGroupsData = await createKmsReportByGroup(from, to
|
|
141
|
+
const allGroupsData = await createKmsReportByGroup(from, to)
|
|
93
142
|
allGroupsData.forEach(data => reportData.push(data))
|
|
94
|
-
const withoutGroupDevices = await createKmsReportByDevice(from, to
|
|
143
|
+
const withoutGroupDevices = await createKmsReportByDevice(from, to)
|
|
95
144
|
reportData.push(withoutGroupDevices)
|
|
96
145
|
} else {
|
|
97
|
-
const allData = await createKmsReportByDevice(from, to
|
|
146
|
+
const allData = await createKmsReportByDevice(from, to)
|
|
98
147
|
reportData.push(allData)
|
|
99
148
|
}
|
|
100
149
|
|
package/src/speeding-report.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const automaticReports = require("./automaticReports")
|
|
2
1
|
const messages = require('../lang')
|
|
3
2
|
const jsPDF = require('jspdf')
|
|
4
3
|
const {convertMS} = require("./util/utils")
|
|
@@ -11,6 +10,7 @@ const drivers = require("./util/driver")
|
|
|
11
10
|
const {distance, point} = require('turf')
|
|
12
11
|
const here = require('./here')
|
|
13
12
|
const {getUserPartner} = require("fleetmap-partners");
|
|
13
|
+
const traccar = require("./util/traccar");
|
|
14
14
|
|
|
15
15
|
let traccarInstance
|
|
16
16
|
|
|
@@ -37,7 +37,8 @@ async function createSpeedingReport(from, to, userData, traccar, roadSpeedLimits
|
|
|
37
37
|
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const
|
|
40
|
+
const events = ['deviceOverspeed']
|
|
41
|
+
const data = await traccar.getEvents(traccarInstance, from, to, devices, events)
|
|
41
42
|
|
|
42
43
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
43
44
|
|
|
@@ -64,7 +65,8 @@ async function createSpeedingReportByDevice(from, to, userData, roadSpeedLimits)
|
|
|
64
65
|
|
|
65
66
|
withoutGroupDevices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
66
67
|
|
|
67
|
-
const
|
|
68
|
+
const events = ['deviceOverspeed']
|
|
69
|
+
const data = await traccar.getEvents(traccarInstance, from, to, withoutGroupDevices, events)
|
|
68
70
|
|
|
69
71
|
const allData = { devices: [] }
|
|
70
72
|
|
|
@@ -78,23 +80,20 @@ async function createSpeedingReportByDevice(from, to, userData, roadSpeedLimits)
|
|
|
78
80
|
|
|
79
81
|
async function createSpeedingReportByDriver(from, to, userData) {
|
|
80
82
|
const deviceIds = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
81
|
-
console.log(deviceIds.length)
|
|
83
|
+
console.log('Devices with driver',deviceIds.length)
|
|
82
84
|
|
|
83
85
|
let eventsData = []
|
|
84
86
|
if(deviceIds.length > 0) {
|
|
85
|
-
console.log('getReportData', deviceIds.length)
|
|
86
87
|
const devices = userData.devices.filter(d => deviceIds.includes(d.id))
|
|
87
|
-
eventsData = await
|
|
88
|
+
eventsData = await traccar.getEvents(traccarInstance, from, to, devices,['deviceOverspeed'])
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
const allData = {
|
|
91
92
|
drivers: []
|
|
92
93
|
}
|
|
93
|
-
|
|
94
94
|
console.log(eventsData.length)
|
|
95
95
|
|
|
96
96
|
await getEventsPosition(from , to, userData.devices, userData.geofences, userData.drivers, eventsData)
|
|
97
|
-
|
|
98
97
|
allData.drivers = await processDrivers(from, to, userData.drivers, eventsData)
|
|
99
98
|
console.log(allData.drivers.length)
|
|
100
99
|
return allData
|
|
@@ -125,29 +124,13 @@ async function processDrivers(from, to, drivers, data) {
|
|
|
125
124
|
return driversResult
|
|
126
125
|
}
|
|
127
126
|
|
|
128
|
-
async function getReportData(from, to, devices) {
|
|
129
|
-
const types = ['deviceOverspeed']
|
|
130
|
-
let data = []
|
|
131
|
-
const arrayOfArrays = automaticReports.sliceArray(devices)
|
|
132
|
-
for (const a of arrayOfArrays) {
|
|
133
|
-
try {
|
|
134
|
-
const devices = a.map(d => d.id)
|
|
135
|
-
console.log('reportsEventsGet', from, to, devices, null, types)
|
|
136
|
-
const response = await traccarInstance.reports.reportsEventsGet(from, to, devices, null, types)
|
|
137
|
-
data = data.concat(response.data)
|
|
138
|
-
} catch (e) {
|
|
139
|
-
console.error(e)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
console.log('Alerts:', data.length)
|
|
143
|
-
return data
|
|
144
|
-
}
|
|
145
|
-
|
|
146
127
|
async function processDevices(from, to, devices, geofences, drivers, data, roadSpeedLimits) {
|
|
147
128
|
const devicesResult = []
|
|
148
129
|
|
|
149
130
|
await getEventsPosition(from , to, devices, geofences, drivers, data, roadSpeedLimits)
|
|
150
131
|
|
|
132
|
+
console.log(data)
|
|
133
|
+
|
|
151
134
|
for (const d of devices) {
|
|
152
135
|
const alerts = data.filter(t => t.deviceId === d.id)
|
|
153
136
|
|
|
@@ -168,14 +151,18 @@ async function processDevices(from, to, devices, geofences, drivers, data, roadS
|
|
|
168
151
|
return devicesResult
|
|
169
152
|
}
|
|
170
153
|
|
|
171
|
-
async function getEventsPosition(from, to, devices, geofences, drivers,
|
|
172
|
-
for (const d of devices) {
|
|
154
|
+
async function getEventsPosition(from, to, devices, geofences, drivers, events, roadSpeedLimits){
|
|
173
155
|
|
|
174
|
-
|
|
156
|
+
const deviceIds = [...new Set(events.map(e => e.deviceId))]
|
|
157
|
+
const routeData = await traccar.getRoute(traccarInstance, from, to, deviceIds.map(id => { return { id: id } } ))
|
|
158
|
+
|
|
159
|
+
console.log(events)
|
|
160
|
+
|
|
161
|
+
for (const d of devices) {
|
|
162
|
+
let alerts = events.filter(t => t.deviceId === d.id)
|
|
175
163
|
|
|
176
164
|
if (alerts.length > 0 || roadSpeedLimits) {
|
|
177
|
-
const
|
|
178
|
-
const positions = response.data
|
|
165
|
+
const positions = routeData.filter(p => p.deviceId === d.id)
|
|
179
166
|
|
|
180
167
|
if (roadSpeedLimits && positions.length) {
|
|
181
168
|
try {
|
|
@@ -201,8 +188,8 @@ async function getEventsPosition(from, to, devices, geofences, drivers, data, ro
|
|
|
201
188
|
}
|
|
202
189
|
return acc
|
|
203
190
|
})
|
|
204
|
-
|
|
205
|
-
alerts =
|
|
191
|
+
events.push(...reduced)
|
|
192
|
+
alerts = events.filter(t => t.deviceId === d.id)
|
|
206
193
|
} catch (e) {
|
|
207
194
|
console.error(e)
|
|
208
195
|
}
|