fleetmap-reports 1.0.245 → 1.0.246
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 +27 -15
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/index.test.js +4 -1
- package/src/speeding-report.js +13 -8
- package/src/util/traccar.js +13 -1
package/.idea/workspace.xml
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
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 - Calculate distance with traccar trips">
|
|
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
|
-
<change beforePath="$PROJECT_DIR$/src/
|
|
7
|
+
<change beforePath="$PROJECT_DIR$/src/speeding-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/speeding-report.js" afterDir="false" />
|
|
9
8
|
<change beforePath="$PROJECT_DIR$/src/util/traccar.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/util/traccar.js" afterDir="false" />
|
|
10
9
|
</list>
|
|
11
10
|
<option name="SHOW_DIALOG" value="false" />
|
|
@@ -38,8 +37,8 @@
|
|
|
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.speedingReport.test
|
|
42
|
-
<configuration name="
|
|
40
|
+
<component name="RunManager" selected="Mocha.speedingReport.test speeding">
|
|
41
|
+
<configuration name="speedingReport" 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>
|
|
@@ -47,29 +46,34 @@
|
|
|
47
46
|
<pass-parent-env>true</pass-parent-env>
|
|
48
47
|
<ui>bdd</ui>
|
|
49
48
|
<extra-mocha-options />
|
|
50
|
-
<test-kind>
|
|
49
|
+
<test-kind>TEST</test-kind>
|
|
51
50
|
<test-file>$PROJECT_DIR$/src/index.test.js</test-file>
|
|
52
51
|
<test-names>
|
|
53
|
-
<name value="
|
|
52
|
+
<name value="speedingReport" />
|
|
54
53
|
</test-names>
|
|
55
54
|
<method v="2" />
|
|
56
55
|
</configuration>
|
|
57
|
-
<configuration name="speedingReport" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
|
|
56
|
+
<configuration name="speedingReport.test kmsReport by day" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
|
|
58
57
|
<node-interpreter>project</node-interpreter>
|
|
59
58
|
<node-options />
|
|
60
59
|
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
|
|
61
60
|
<working-directory>$PROJECT_DIR$</working-directory>
|
|
62
61
|
<pass-parent-env>true</pass-parent-env>
|
|
62
|
+
<envs>
|
|
63
|
+
<env name="email" value="jppenas@gmail.com" />
|
|
64
|
+
<env name="password" value="penas46881" />
|
|
65
|
+
</envs>
|
|
63
66
|
<ui>bdd</ui>
|
|
64
67
|
<extra-mocha-options />
|
|
65
68
|
<test-kind>TEST</test-kind>
|
|
66
69
|
<test-file>$PROJECT_DIR$/src/index.test.js</test-file>
|
|
67
70
|
<test-names>
|
|
68
71
|
<name value="speedingReport" />
|
|
72
|
+
<name value="test kmsReport by day" />
|
|
69
73
|
</test-names>
|
|
70
74
|
<method v="2" />
|
|
71
75
|
</configuration>
|
|
72
|
-
<configuration name="speedingReport.test
|
|
76
|
+
<configuration name="speedingReport.test speeding" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
|
|
73
77
|
<node-interpreter>project</node-interpreter>
|
|
74
78
|
<node-options />
|
|
75
79
|
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
|
|
@@ -85,7 +89,7 @@
|
|
|
85
89
|
<test-file>$PROJECT_DIR$/src/index.test.js</test-file>
|
|
86
90
|
<test-names>
|
|
87
91
|
<name value="speedingReport" />
|
|
88
|
-
<name value="test
|
|
92
|
+
<name value="test speeding" />
|
|
89
93
|
</test-names>
|
|
90
94
|
<method v="2" />
|
|
91
95
|
</configuration>
|
|
@@ -125,19 +129,19 @@
|
|
|
125
129
|
<method v="2" />
|
|
126
130
|
</configuration>
|
|
127
131
|
<list>
|
|
128
|
-
<item itemvalue="Mocha.report" />
|
|
129
132
|
<item itemvalue="Mocha.speedingReport" />
|
|
130
133
|
<item itemvalue="Mocha.test reports" />
|
|
131
134
|
<item itemvalue="Mocha.test reports.test queue" />
|
|
132
135
|
<item itemvalue="Mocha.speedingReport.test kmsReport by day" />
|
|
136
|
+
<item itemvalue="Mocha.speedingReport.test speeding" />
|
|
133
137
|
</list>
|
|
134
138
|
<recent_temporary>
|
|
135
139
|
<list>
|
|
140
|
+
<item itemvalue="Mocha.speedingReport.test speeding" />
|
|
136
141
|
<item itemvalue="Mocha.speedingReport.test kmsReport by day" />
|
|
137
142
|
<item itemvalue="Mocha.test reports" />
|
|
138
143
|
<item itemvalue="Mocha.test reports.test queue" />
|
|
139
144
|
<item itemvalue="Mocha.speedingReport" />
|
|
140
|
-
<item itemvalue="Mocha.report" />
|
|
141
145
|
</list>
|
|
142
146
|
</recent_temporary>
|
|
143
147
|
</component>
|
|
@@ -172,7 +176,7 @@
|
|
|
172
176
|
<workItem from="1637868513425" duration="1650000" />
|
|
173
177
|
<workItem from="1637928687573" duration="37000" />
|
|
174
178
|
<workItem from="1637931438656" duration="621000" />
|
|
175
|
-
<workItem from="1637952151523" duration="
|
|
179
|
+
<workItem from="1637952151523" duration="9616000" />
|
|
176
180
|
</task>
|
|
177
181
|
<task id="LOCAL-00001" summary="Fix getStyle">
|
|
178
182
|
<created>1636983717385</created>
|
|
@@ -216,7 +220,14 @@
|
|
|
216
220
|
<option name="project" value="LOCAL" />
|
|
217
221
|
<updated>1637858604089</updated>
|
|
218
222
|
</task>
|
|
219
|
-
<
|
|
223
|
+
<task id="LOCAL-00007" summary="Kms Report - Calculate distance with traccar trips">
|
|
224
|
+
<created>1638179219255</created>
|
|
225
|
+
<option name="number" value="00007" />
|
|
226
|
+
<option name="presentableId" value="LOCAL-00007" />
|
|
227
|
+
<option name="project" value="LOCAL" />
|
|
228
|
+
<updated>1638179219256</updated>
|
|
229
|
+
</task>
|
|
230
|
+
<option name="localTasksCounter" value="8" />
|
|
220
231
|
<servers />
|
|
221
232
|
</component>
|
|
222
233
|
<component name="TypeScriptGeneratedFilesManager">
|
|
@@ -241,6 +252,7 @@
|
|
|
241
252
|
<MESSAGE value="Kms report grouped by day" />
|
|
242
253
|
<MESSAGE value="Fix pdf logo" />
|
|
243
254
|
<MESSAGE value="kms report with parallel requests" />
|
|
244
|
-
<
|
|
255
|
+
<MESSAGE value="Kms Report - Calculate distance with traccar trips" />
|
|
256
|
+
<option name="LAST_COMMIT_MESSAGE" value="Kms Report - Calculate distance with traccar trips" />
|
|
245
257
|
</component>
|
|
246
258
|
</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
|
@@ -6,9 +6,12 @@ describe('speedingReport', function() {
|
|
|
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
|
+
|
|
12
15
|
})
|
|
13
16
|
it('test kmsReport by day', async () => {
|
|
14
17
|
const reports = await getReports()
|
package/src/speeding-report.js
CHANGED
|
@@ -11,6 +11,7 @@ const drivers = require("./util/driver")
|
|
|
11
11
|
const {distance, point} = require('turf')
|
|
12
12
|
const here = require('./here')
|
|
13
13
|
const {getUserPartner} = require("fleetmap-partners");
|
|
14
|
+
const traccar = require("./util/traccar");
|
|
14
15
|
|
|
15
16
|
let traccarInstance
|
|
16
17
|
|
|
@@ -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
|
|
|
@@ -168,14 +170,17 @@ async function processDevices(from, to, devices, geofences, drivers, data, roadS
|
|
|
168
170
|
return devicesResult
|
|
169
171
|
}
|
|
170
172
|
|
|
171
|
-
async function getEventsPosition(from, to, devices, geofences, drivers,
|
|
172
|
-
|
|
173
|
+
async function getEventsPosition(from, to, devices, geofences, drivers, events, roadSpeedLimits){
|
|
174
|
+
|
|
175
|
+
const deviceIds = [...new Set(events.map(e => e.deviceId))]
|
|
176
|
+
console.log('deviceIds',deviceIds)
|
|
177
|
+
const routeData = await traccar.getRoute(traccarInstance, from, to, deviceIds.map(id => { return { id: id } } ))
|
|
173
178
|
|
|
174
|
-
|
|
179
|
+
for (const d of devices) {
|
|
180
|
+
let alerts = events.filter(t => t.deviceId === d.id)
|
|
175
181
|
|
|
176
182
|
if (alerts.length > 0 || roadSpeedLimits) {
|
|
177
|
-
const
|
|
178
|
-
const positions = response.data
|
|
183
|
+
const positions = routeData.filter(p => p.deviceId === d.id)
|
|
179
184
|
|
|
180
185
|
if (roadSpeedLimits && positions.length) {
|
|
181
186
|
try {
|
|
@@ -201,8 +206,8 @@ async function getEventsPosition(from, to, devices, geofences, drivers, data, ro
|
|
|
201
206
|
}
|
|
202
207
|
return acc
|
|
203
208
|
})
|
|
204
|
-
|
|
205
|
-
alerts =
|
|
209
|
+
events.push(...reduced)
|
|
210
|
+
alerts = events.filter(t => t.deviceId === d.id)
|
|
206
211
|
} catch (e) {
|
|
207
212
|
console.error(e)
|
|
208
213
|
}
|
package/src/util/traccar.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const automaticReports = require("../automaticReports");
|
|
2
|
-
const moment = require('moment')
|
|
3
2
|
|
|
4
3
|
async function getRoute(traccar, from, to, devices){
|
|
5
4
|
const devicesToSlice = devices.slice()
|
|
@@ -28,5 +27,18 @@ async function getTrips(traccar, from, to, devices){
|
|
|
28
27
|
return result.map(r => r.data).flat()
|
|
29
28
|
}
|
|
30
29
|
|
|
30
|
+
async function getEvents(traccar, from, to, devices, events){
|
|
31
|
+
const devicesToSlice = devices.slice()
|
|
32
|
+
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
|
|
33
|
+
let requests = []
|
|
34
|
+
for (const a of arrayOfArrays) {
|
|
35
|
+
const promise = traccar.reports.reportsEventsGet(from, to, a.map(d => d.id), null, events)
|
|
36
|
+
requests = requests.concat(promise)
|
|
37
|
+
}
|
|
38
|
+
const result = await Promise.all(requests)
|
|
39
|
+
return result.map(r => r.data).flat()
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
exports.getRoute = getRoute
|
|
32
43
|
exports.getTrips = getTrips
|
|
44
|
+
exports.getEvents = getEvents
|