fleetmap-reports 1.0.252 → 1.0.253
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 +13 -12
- package/package.json +1 -1
- package/src/kms-report.js +6 -4
- package/src/trip-report.js +13 -10
- package/src/util/trips.js +18 -0
package/.idea/workspace.xml
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
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$/lang/enGB.js" beforeDir="false" afterPath="$PROJECT_DIR$/lang/enGB.js" afterDir="false" />
|
|
6
|
-
<change beforePath="$PROJECT_DIR$/lang/esCL.js" beforeDir="false" afterPath="$PROJECT_DIR$/lang/esCL.js" afterDir="false" />
|
|
7
|
-
<change beforePath="$PROJECT_DIR$/lang/ptBR.js" beforeDir="false" afterPath="$PROJECT_DIR$/lang/ptBR.js" afterDir="false" />
|
|
8
|
-
<change beforePath="$PROJECT_DIR$/lang/ptPT.js" beforeDir="false" afterPath="$PROJECT_DIR$/lang/ptPT.js" afterDir="false" />
|
|
4
|
+
<list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="Trip and activity report with time period">
|
|
9
5
|
<change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" />
|
|
10
6
|
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
11
|
-
<change beforePath="$PROJECT_DIR$/src/activity-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/activity-report.js" afterDir="false" />
|
|
12
7
|
<change beforePath="$PROJECT_DIR$/src/index.test.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.test.js" afterDir="false" />
|
|
13
8
|
<change beforePath="$PROJECT_DIR$/src/kms-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/kms-report.js" afterDir="false" />
|
|
14
|
-
<change beforePath="$PROJECT_DIR$/src/speeding-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/speeding-report.js" afterDir="false" />
|
|
15
9
|
<change beforePath="$PROJECT_DIR$/src/trip-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/trip-report.js" afterDir="false" />
|
|
16
|
-
<change beforePath="$PROJECT_DIR$/src/util/traccar.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/util/traccar.js" afterDir="false" />
|
|
17
|
-
<change beforePath="$PROJECT_DIR$/src/util/utils.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/util/utils.js" afterDir="false" />
|
|
18
10
|
</list>
|
|
19
11
|
<option name="SHOW_DIALOG" value="false" />
|
|
20
12
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -220,7 +212,8 @@
|
|
|
220
212
|
<workItem from="1639591829775" duration="681000" />
|
|
221
213
|
<workItem from="1639592539998" duration="27141000" />
|
|
222
214
|
<workItem from="1639766010908" duration="4991000" />
|
|
223
|
-
<workItem from="1639872937953" duration="
|
|
215
|
+
<workItem from="1639872937953" duration="1438000" />
|
|
216
|
+
<workItem from="1639954341221" duration="7636000" />
|
|
224
217
|
</task>
|
|
225
218
|
<task id="LOCAL-00001" summary="Fix getStyle">
|
|
226
219
|
<created>1636983717385</created>
|
|
@@ -313,7 +306,14 @@
|
|
|
313
306
|
<option name="project" value="LOCAL" />
|
|
314
307
|
<updated>1639248407782</updated>
|
|
315
308
|
</task>
|
|
316
|
-
<
|
|
309
|
+
<task id="LOCAL-00014" summary="Trip and activity report with time period">
|
|
310
|
+
<created>1639873766070</created>
|
|
311
|
+
<option name="number" value="00014" />
|
|
312
|
+
<option name="presentableId" value="LOCAL-00014" />
|
|
313
|
+
<option name="project" value="LOCAL" />
|
|
314
|
+
<updated>1639873766072</updated>
|
|
315
|
+
</task>
|
|
316
|
+
<option name="localTasksCounter" value="15" />
|
|
317
317
|
<servers />
|
|
318
318
|
</component>
|
|
319
319
|
<component name="TypeScriptGeneratedFilesManager">
|
|
@@ -344,6 +344,7 @@
|
|
|
344
344
|
<MESSAGE value="kms report - show every selected day" />
|
|
345
345
|
<MESSAGE value="speeding report with customSpeed" />
|
|
346
346
|
<MESSAGE value="fix speeding report" />
|
|
347
|
-
<
|
|
347
|
+
<MESSAGE value="Trip and activity report with time period" />
|
|
348
|
+
<option name="LAST_COMMIT_MESSAGE" value="Trip and activity report with time period" />
|
|
348
349
|
</component>
|
|
349
350
|
</project>
|
package/package.json
CHANGED
package/src/kms-report.js
CHANGED
|
@@ -6,6 +6,7 @@ const {headerFromUser,addTable} = require("./util/pdfDocument");
|
|
|
6
6
|
const {getUserPartner} = require("fleetmap-partners");
|
|
7
7
|
const traccar = require("./util/traccar");
|
|
8
8
|
const {getDates} = require("./util/utils");
|
|
9
|
+
const trips = require("./util/trips");
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
let traccarInstance
|
|
@@ -25,12 +26,13 @@ async function createKmsReportByDevice(from, to) {
|
|
|
25
26
|
|
|
26
27
|
devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
27
28
|
const route = userData.allWeek ? [] : await traccar.getRoute(traccarInstance, from, to, devicesToProcess)
|
|
28
|
-
const
|
|
29
|
+
const tripsData = await traccar.getTrips(traccarInstance, from, to, devicesToProcess)
|
|
29
30
|
|
|
30
|
-
console.log('trips:' +
|
|
31
|
+
console.log('trips:' + tripsData.length)
|
|
31
32
|
|
|
32
|
-
if (
|
|
33
|
-
|
|
33
|
+
if (tripsData.length > 0) {
|
|
34
|
+
await trips.checkTripsKms(traccarInstance, from, to, route, tripsData, devicesToProcess)
|
|
35
|
+
allData.devices = processDevices(from, to, devicesToProcess, route, tripsData)
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
return allData
|
package/src/trip-report.js
CHANGED
|
@@ -9,37 +9,40 @@ const {getUserPartner} = require("fleetmap-partners")
|
|
|
9
9
|
const {headerFromUser, addTable} = require("./util/pdfDocument")
|
|
10
10
|
const {getStyle} = require("./reportStyle")
|
|
11
11
|
const traccar = require("./util/traccar")
|
|
12
|
+
const trips = require("./util/trips");
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
let traccarInstance
|
|
16
|
+
let userData
|
|
15
17
|
|
|
16
18
|
const fileName = 'TripReport'
|
|
17
19
|
|
|
18
|
-
async function createTripReport(from, to,
|
|
20
|
+
async function createTripReport(from, to, reportUserData, traccar) {
|
|
19
21
|
console.log('Create TripReport')
|
|
22
|
+
userData = reportUserData
|
|
20
23
|
traccarInstance = traccar
|
|
21
24
|
const reportData = []
|
|
22
25
|
|
|
23
26
|
if(userData.byDriver){
|
|
24
|
-
const allData = await createTripReportByDriver(from, to
|
|
27
|
+
const allData = await createTripReportByDriver(from, to)
|
|
25
28
|
reportData.push(allData)
|
|
26
29
|
}
|
|
27
30
|
else if(userData.byGroup){
|
|
28
31
|
console.log("ByGroup")
|
|
29
|
-
const allData = await createTripReportByGroup(from, to
|
|
32
|
+
const allData = await createTripReportByGroup(from, to)
|
|
30
33
|
reportData.push(...allData)
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
const groupIds = userData.groups.map(g => g.id)
|
|
34
37
|
const withoutGroupDevices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
35
38
|
|
|
36
|
-
const allData = await createTripReportByDevice(from, to,
|
|
39
|
+
const allData = await createTripReportByDevice(from, to, withoutGroupDevices)
|
|
37
40
|
reportData.push(allData)
|
|
38
41
|
|
|
39
42
|
return reportData
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
async function createTripReportByDevice(from, to,
|
|
45
|
+
async function createTripReportByDevice(from, to, devices) {
|
|
43
46
|
const allData = {
|
|
44
47
|
devices: [],
|
|
45
48
|
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
@@ -54,14 +57,14 @@ async function createTripReportByDevice(from, to, userData, devices) {
|
|
|
54
57
|
console.log('Trips:' + data.length)
|
|
55
58
|
|
|
56
59
|
if (data.length > 0) {
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
await trips.checkTripsKms(traccarInstance, from, to,[], data, devices)
|
|
61
|
+
allData.devices = processDevices(from, to, devices, data, stopsData)
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
return allData
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
async function createTripReportByGroup(from, to
|
|
67
|
+
async function createTripReportByGroup(from, to) {
|
|
65
68
|
const reportData = []
|
|
66
69
|
for (const g of userData.groups) {
|
|
67
70
|
const devices = userData.devices.filter(d => d.groupId === g.id)
|
|
@@ -93,7 +96,7 @@ async function createTripReportByGroup(from, to, userData) {
|
|
|
93
96
|
return reportData
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
async function createTripReportByDriver(from, to
|
|
99
|
+
async function createTripReportByDriver(from, to){
|
|
97
100
|
const deviceIds = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
98
101
|
console.log(deviceIds.length)
|
|
99
102
|
|
|
@@ -112,7 +115,7 @@ async function createTripReportByDriver(from, to, userData){
|
|
|
112
115
|
return allData
|
|
113
116
|
}
|
|
114
117
|
|
|
115
|
-
function processDevices(from, to, devices, data, stopsData
|
|
118
|
+
function processDevices(from, to, devices, data, stopsData) {
|
|
116
119
|
const devicesResult = []
|
|
117
120
|
|
|
118
121
|
devices.forEach(d => {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const traccar = require("./traccar");
|
|
2
|
+
|
|
3
|
+
async function checkTripsKms(traccarInstance, from, to, routeData, tripsData, devices) {
|
|
4
|
+
console.log('checkTripsKms')
|
|
5
|
+
const trips = tripsData.filter(t => t.distance === 0 && t.averageSpeed > 10)
|
|
6
|
+
if(trips.length > 0) {
|
|
7
|
+
//Vehicles with imported positions. calculate trip distance with route positions
|
|
8
|
+
const route = routeData.length === 0 ? await traccar.getRoute(traccarInstance, from, to, devices) : routeData
|
|
9
|
+
trips.forEach(t => {
|
|
10
|
+
const tripRoute = route.filter(p => p.deviceId === t.deviceId
|
|
11
|
+
&& new Date(p.fixTime).getTime() > new Date(t.startTime).getTime()
|
|
12
|
+
&& new Date(p.fixTime).getTime() < new Date(t.endTime).getTime())
|
|
13
|
+
t.distance = tripRoute.reduce((a, b) => a + b.attributes.distance, 0)
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.checkTripsKms = checkTripsKms
|