fleetmap-reports 1.0.245 → 1.0.249
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 +79 -24
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/index.test.js +27 -2
- package/src/kms-report.js +88 -27
- 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/src/util/utils.js +16 -0
- 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,12 +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="
|
|
4
|
+
<list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="Kms report with time period">
|
|
5
5
|
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
6
|
-
<change beforePath="$PROJECT_DIR$/src/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.js" afterDir="false" />
|
|
7
6
|
<change beforePath="$PROJECT_DIR$/src/index.test.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.test.js" afterDir="false" />
|
|
8
7
|
<change beforePath="$PROJECT_DIR$/src/kms-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/kms-report.js" afterDir="false" />
|
|
9
|
-
<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" />
|
|
10
9
|
</list>
|
|
11
10
|
<option name="SHOW_DIALOG" value="false" />
|
|
12
11
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -38,34 +37,44 @@
|
|
|
38
37
|
<property name="ts.external.directory.path" value="$APPLICATION_HOME_DIR$/plugins/JavaScriptLanguage/jsLanguageServicesImpl/external" />
|
|
39
38
|
<property name="vue.rearranger.settings.migration" value="true" />
|
|
40
39
|
</component>
|
|
41
|
-
<component name="RunManager" selected="Mocha.
|
|
42
|
-
<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">
|
|
43
42
|
<node-interpreter>project</node-interpreter>
|
|
44
43
|
<node-options />
|
|
45
44
|
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
|
|
46
45
|
<working-directory>$PROJECT_DIR$</working-directory>
|
|
47
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>
|
|
48
51
|
<ui>bdd</ui>
|
|
49
52
|
<extra-mocha-options />
|
|
50
|
-
<test-kind>
|
|
53
|
+
<test-kind>TEST</test-kind>
|
|
51
54
|
<test-file>$PROJECT_DIR$/src/index.test.js</test-file>
|
|
52
55
|
<test-names>
|
|
53
|
-
<name value="
|
|
56
|
+
<name value="Reports" />
|
|
57
|
+
<name value="test event report" />
|
|
54
58
|
</test-names>
|
|
55
59
|
<method v="2" />
|
|
56
60
|
</configuration>
|
|
57
|
-
<configuration name="
|
|
61
|
+
<configuration name="Reports.test trip report" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
|
|
58
62
|
<node-interpreter>project</node-interpreter>
|
|
59
63
|
<node-options />
|
|
60
64
|
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
|
|
61
65
|
<working-directory>$PROJECT_DIR$</working-directory>
|
|
62
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>
|
|
63
71
|
<ui>bdd</ui>
|
|
64
72
|
<extra-mocha-options />
|
|
65
73
|
<test-kind>TEST</test-kind>
|
|
66
74
|
<test-file>$PROJECT_DIR$/src/index.test.js</test-file>
|
|
67
75
|
<test-names>
|
|
68
|
-
<name value="
|
|
76
|
+
<name value="Reports" />
|
|
77
|
+
<name value="test trip report" />
|
|
69
78
|
</test-names>
|
|
70
79
|
<method v="2" />
|
|
71
80
|
</configuration>
|
|
@@ -89,7 +98,7 @@
|
|
|
89
98
|
</test-names>
|
|
90
99
|
<method v="2" />
|
|
91
100
|
</configuration>
|
|
92
|
-
<configuration name="test
|
|
101
|
+
<configuration name="speedingReport.test speeding" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
|
|
93
102
|
<node-interpreter>project</node-interpreter>
|
|
94
103
|
<node-options />
|
|
95
104
|
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
|
|
@@ -101,43 +110,47 @@
|
|
|
101
110
|
</envs>
|
|
102
111
|
<ui>bdd</ui>
|
|
103
112
|
<extra-mocha-options />
|
|
104
|
-
<test-kind>
|
|
113
|
+
<test-kind>TEST</test-kind>
|
|
105
114
|
<test-file>$PROJECT_DIR$/src/index.test.js</test-file>
|
|
106
115
|
<test-names>
|
|
107
|
-
<name value="
|
|
116
|
+
<name value="speedingReport" />
|
|
117
|
+
<name value="test speeding" />
|
|
108
118
|
</test-names>
|
|
109
119
|
<method v="2" />
|
|
110
120
|
</configuration>
|
|
111
|
-
<configuration name="test reports
|
|
121
|
+
<configuration name="test reports" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
|
|
112
122
|
<node-interpreter>project</node-interpreter>
|
|
113
123
|
<node-options />
|
|
114
124
|
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
|
|
115
125
|
<working-directory>$PROJECT_DIR$</working-directory>
|
|
116
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>
|
|
117
131
|
<ui>bdd</ui>
|
|
118
132
|
<extra-mocha-options />
|
|
119
|
-
<test-kind>
|
|
133
|
+
<test-kind>SUITE</test-kind>
|
|
120
134
|
<test-file>$PROJECT_DIR$/src/index.test.js</test-file>
|
|
121
135
|
<test-names>
|
|
122
136
|
<name value="test reports" />
|
|
123
|
-
<name value="test queue" />
|
|
124
137
|
</test-names>
|
|
125
138
|
<method v="2" />
|
|
126
139
|
</configuration>
|
|
127
140
|
<list>
|
|
128
|
-
<item itemvalue="Mocha.report" />
|
|
129
|
-
<item itemvalue="Mocha.speedingReport" />
|
|
130
141
|
<item itemvalue="Mocha.test reports" />
|
|
131
|
-
<item itemvalue="Mocha.test reports.test queue" />
|
|
132
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" />
|
|
133
146
|
</list>
|
|
134
147
|
<recent_temporary>
|
|
135
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" />
|
|
136
152
|
<item itemvalue="Mocha.speedingReport.test kmsReport by day" />
|
|
137
153
|
<item itemvalue="Mocha.test reports" />
|
|
138
|
-
<item itemvalue="Mocha.test reports.test queue" />
|
|
139
|
-
<item itemvalue="Mocha.speedingReport" />
|
|
140
|
-
<item itemvalue="Mocha.report" />
|
|
141
154
|
</list>
|
|
142
155
|
</recent_temporary>
|
|
143
156
|
</component>
|
|
@@ -172,7 +185,17 @@
|
|
|
172
185
|
<workItem from="1637868513425" duration="1650000" />
|
|
173
186
|
<workItem from="1637928687573" duration="37000" />
|
|
174
187
|
<workItem from="1637931438656" duration="621000" />
|
|
175
|
-
<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="19894000" />
|
|
196
|
+
<workItem from="1639074912454" duration="257000" />
|
|
197
|
+
<workItem from="1639090037682" duration="2514000" />
|
|
198
|
+
<workItem from="1639135460686" duration="2390000" />
|
|
176
199
|
</task>
|
|
177
200
|
<task id="LOCAL-00001" summary="Fix getStyle">
|
|
178
201
|
<created>1636983717385</created>
|
|
@@ -216,7 +239,35 @@
|
|
|
216
239
|
<option name="project" value="LOCAL" />
|
|
217
240
|
<updated>1637858604089</updated>
|
|
218
241
|
</task>
|
|
219
|
-
<
|
|
242
|
+
<task id="LOCAL-00007" summary="Kms Report - Calculate distance with traccar trips">
|
|
243
|
+
<created>1638179219255</created>
|
|
244
|
+
<option name="number" value="00007" />
|
|
245
|
+
<option name="presentableId" value="LOCAL-00007" />
|
|
246
|
+
<option name="project" value="LOCAL" />
|
|
247
|
+
<updated>1638179219256</updated>
|
|
248
|
+
</task>
|
|
249
|
+
<task id="LOCAL-00008" summary="fix speeding report">
|
|
250
|
+
<created>1638186780966</created>
|
|
251
|
+
<option name="number" value="00008" />
|
|
252
|
+
<option name="presentableId" value="LOCAL-00008" />
|
|
253
|
+
<option name="project" value="LOCAL" />
|
|
254
|
+
<updated>1638186780967</updated>
|
|
255
|
+
</task>
|
|
256
|
+
<task id="LOCAL-00009" summary="refactor speeding and trip report">
|
|
257
|
+
<created>1638288337133</created>
|
|
258
|
+
<option name="number" value="00009" />
|
|
259
|
+
<option name="presentableId" value="LOCAL-00009" />
|
|
260
|
+
<option name="project" value="LOCAL" />
|
|
261
|
+
<updated>1638288337135</updated>
|
|
262
|
+
</task>
|
|
263
|
+
<task id="LOCAL-00010" summary="Kms report with time period">
|
|
264
|
+
<created>1639057192380</created>
|
|
265
|
+
<option name="number" value="00010" />
|
|
266
|
+
<option name="presentableId" value="LOCAL-00010" />
|
|
267
|
+
<option name="project" value="LOCAL" />
|
|
268
|
+
<updated>1639057192382</updated>
|
|
269
|
+
</task>
|
|
270
|
+
<option name="localTasksCounter" value="11" />
|
|
220
271
|
<servers />
|
|
221
272
|
</component>
|
|
222
273
|
<component name="TypeScriptGeneratedFilesManager">
|
|
@@ -241,6 +292,10 @@
|
|
|
241
292
|
<MESSAGE value="Kms report grouped by day" />
|
|
242
293
|
<MESSAGE value="Fix pdf logo" />
|
|
243
294
|
<MESSAGE value="kms report with parallel requests" />
|
|
244
|
-
<
|
|
295
|
+
<MESSAGE value="Kms Report - Calculate distance with traccar trips" />
|
|
296
|
+
<MESSAGE value="fix speeding report" />
|
|
297
|
+
<MESSAGE value="refactor speeding and trip report" />
|
|
298
|
+
<MESSAGE value="Kms report with time period" />
|
|
299
|
+
<option name="LAST_COMMIT_MESSAGE" value="Kms report with time period" />
|
|
245
300
|
</component>
|
|
246
301
|
</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
|
@@ -6,13 +6,15 @@ const {getStyle} = require("./reportStyle");
|
|
|
6
6
|
const {headerFromUser,addTable} = require("./util/pdfDocument");
|
|
7
7
|
const {getUserPartner} = require("fleetmap-partners");
|
|
8
8
|
const traccar = require("./util/traccar");
|
|
9
|
+
const {getDates} = require("./util/utils");
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
let traccarInstance
|
|
13
|
+
let userData
|
|
12
14
|
|
|
13
15
|
const fileName = 'KmsReport'
|
|
14
16
|
|
|
15
|
-
async function createKmsReportByDevice(from, to
|
|
17
|
+
async function createKmsReportByDevice(from, to) {
|
|
16
18
|
const groupIds = userData.groups.map(g => g.id)
|
|
17
19
|
const devicesToProcess = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
18
20
|
|
|
@@ -23,54 +25,110 @@ async function createKmsReportByDevice(from, to, userData) {
|
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
+
const route = userData.allWeek ? [] : await traccar.getRoute(traccarInstance, from, to, devicesToProcess)
|
|
29
|
+
const trips = await traccar.getTrips(traccarInstance, from, to, devicesToProcess)
|
|
28
30
|
|
|
29
|
-
console.log('trips:' +
|
|
31
|
+
console.log('trips:' + trips.length)
|
|
30
32
|
|
|
31
|
-
if (
|
|
32
|
-
allData.devices = processDevices(from, to, devicesToProcess,
|
|
33
|
+
if (trips.length > 0) {
|
|
34
|
+
allData.devices = processDevices(from, to, devicesToProcess, route, trips)
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
return allData
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
async function createKmsReportByDriver(from, to
|
|
40
|
+
async function createKmsReportByDriver(from, to) {
|
|
39
41
|
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
async function createKmsReportByGroup(from, to
|
|
44
|
+
async function createKmsReportByGroup(from, to) {
|
|
43
45
|
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
function processDevices(from, to, devices,
|
|
48
|
+
function processDevices(from, to, devices, route, trips) {
|
|
47
49
|
const devicesResult = []
|
|
48
50
|
|
|
49
51
|
for (const d of devices) {
|
|
50
|
-
const
|
|
52
|
+
const deviceTrips = trips.filter(t => t.deviceId === d.id)
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const groupedTrips =
|
|
54
|
+
if (deviceTrips.length > 0) {
|
|
55
|
+
deviceTrips.forEach(t => t.tripDay = new Date(t.startTime).toISOString().split('T')[0] + ' 12:00 PM')
|
|
56
|
+
const groupedTrips = deviceTrips.reduce(
|
|
55
57
|
(entryMap, e) => entryMap.set(e.tripDay, [...entryMap.get(e.tripDay)||[], e]),
|
|
56
58
|
new Map()
|
|
57
59
|
)
|
|
58
60
|
|
|
59
|
-
const
|
|
60
|
-
const keys = Array.from(groupedTrips.keys())
|
|
61
|
+
const allDates = getDates(from, to)
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
const days = []
|
|
64
|
+
let keys = Array.from(groupedTrips.keys())
|
|
65
|
+
allDates.forEach(d => {
|
|
66
|
+
const day = d.toISOString().split('T')[0] + ' 12:00 PM'
|
|
67
|
+
if(!keys.includes(day)){
|
|
68
|
+
groupedTrips.set(day, [])
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
keys = Array.from(groupedTrips.keys())
|
|
73
|
+
keys.sort((a,b)=>new Date(a).getTime()-new Date(b).getTime());
|
|
74
|
+
keys.forEach(key => {
|
|
75
|
+
const currentDate = new Date(key)
|
|
76
|
+
let dayTrips = groupedTrips.get(key)
|
|
64
77
|
const day = {
|
|
65
|
-
date:
|
|
66
|
-
kms:
|
|
78
|
+
date: currentDate,
|
|
79
|
+
kms: 0
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if(userData.allWeek){
|
|
83
|
+
day.kms = dayTrips.reduce((a, b) => a + b.distance, 0) || 0
|
|
84
|
+
} else {
|
|
85
|
+
if((currentDate.getDay() === 0 && userData.weekDays.sunday) ||
|
|
86
|
+
(currentDate.getDay() === 1 && userData.weekDays.monday) ||
|
|
87
|
+
(currentDate.getDay() === 2 && userData.weekDays.tuesday) ||
|
|
88
|
+
(currentDate.getDay() === 3 && userData.weekDays.wednesday) ||
|
|
89
|
+
(currentDate.getDay() === 4 && userData.weekDays.thursday) ||
|
|
90
|
+
(currentDate.getDay() === 5 && userData.weekDays.friday) ||
|
|
91
|
+
(currentDate.getDay() === 6 && userData.weekDays.saturday)) {
|
|
92
|
+
|
|
93
|
+
const startDate = new Date(new Date(key).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
|
|
94
|
+
const endDate = new Date(new Date(key).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
|
|
95
|
+
|
|
96
|
+
console.log(key, startDate, endDate)
|
|
97
|
+
|
|
98
|
+
//Trips inside time period
|
|
99
|
+
const filteredTrips = dayTrips.filter(t => new Date(t.startTime).getTime() > startDate.getTime()
|
|
100
|
+
&& new Date(t.endTime).getTime() < endDate.getTime())
|
|
101
|
+
|
|
102
|
+
//Trip starts outside time period and ends inside time period
|
|
103
|
+
const startIncompleteTrip = dayTrips.filter(t => new Date(t.startTime).getTime() < startDate.getTime()
|
|
104
|
+
&& new Date(t.endTime).getTime() > startDate.getTime())
|
|
105
|
+
|
|
106
|
+
//Trip starts inside time period and ends outside time period
|
|
107
|
+
const endIncompleteTrip = dayTrips.filter(t => new Date(t.startTime).getTime() < endDate.getTime()
|
|
108
|
+
&& new Date(t.endTime).getTime() > endDate.getTime())
|
|
109
|
+
|
|
110
|
+
day.kms = filteredTrips.reduce((a, b) => a + b.distance, 0) || 0
|
|
111
|
+
console.log('Inside trips:'+day.kms)
|
|
112
|
+
|
|
113
|
+
if(startIncompleteTrip.length){
|
|
114
|
+
const routeInside = route.filter(p => new Date(p.fixTime).getTime() > startDate.getTime() && new Date(p.fixTime).getTime() < new Date(startIncompleteTrip[0].endTime).getTime())
|
|
115
|
+
day.kms = day.kms + (routeInside.reduce((a, b) => a + b.distance, 0) || 0)
|
|
116
|
+
console.log('startIncompleteTrip:'+day.kms)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if(endIncompleteTrip.length){
|
|
120
|
+
const routeInside = route.filter(p => new Date(p.fixTime).getTime() < endDate.getTime() && new Date(p.fixTime).getTime() > new Date(endIncompleteTrip[0].startTime).getTime())
|
|
121
|
+
day.kms = day.kms + (routeInside.reduce((a, b) => a + b.distance, 0) || 0)
|
|
122
|
+
console.log('endIncompleteTrip:'+day.kms)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
67
125
|
}
|
|
126
|
+
|
|
68
127
|
days.push(day)
|
|
69
128
|
})
|
|
70
|
-
|
|
71
129
|
devicesResult.push({
|
|
72
|
-
|
|
73
|
-
|
|
130
|
+
device: d,
|
|
131
|
+
days: days
|
|
74
132
|
})
|
|
75
133
|
}
|
|
76
134
|
}
|
|
@@ -78,23 +136,26 @@ function processDevices(from, to, devices, data) {
|
|
|
78
136
|
return devicesResult
|
|
79
137
|
}
|
|
80
138
|
|
|
81
|
-
async function createKmsReport(from, to,
|
|
139
|
+
async function createKmsReport(from, to, reportUserData, traccar) {
|
|
82
140
|
console.log('Create KmsReport')
|
|
141
|
+
|
|
142
|
+
console.log(from, to)
|
|
83
143
|
traccarInstance = traccar
|
|
144
|
+
userData = reportUserData
|
|
84
145
|
if(userData.groupByDay){
|
|
85
146
|
const reportData = []
|
|
86
147
|
|
|
87
148
|
if(userData.byDriver){
|
|
88
|
-
const allData = await createKmsReportByDriver(from, to
|
|
149
|
+
const allData = await createKmsReportByDriver(from, to)
|
|
89
150
|
reportData.push(allData)
|
|
90
151
|
}
|
|
91
152
|
else if(userData.byGroup){
|
|
92
|
-
const allGroupsData = await createKmsReportByGroup(from, to
|
|
153
|
+
const allGroupsData = await createKmsReportByGroup(from, to)
|
|
93
154
|
allGroupsData.forEach(data => reportData.push(data))
|
|
94
|
-
const withoutGroupDevices = await createKmsReportByDevice(from, to
|
|
155
|
+
const withoutGroupDevices = await createKmsReportByDevice(from, to)
|
|
95
156
|
reportData.push(withoutGroupDevices)
|
|
96
157
|
} else {
|
|
97
|
-
const allData = await createKmsReportByDevice(from, to
|
|
158
|
+
const allData = await createKmsReportByDevice(from, to)
|
|
98
159
|
reportData.push(allData)
|
|
99
160
|
}
|
|
100
161
|
|
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
|
}
|