fleetmap-reports 1.0.308 → 1.0.312
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/runConfigurations.xml +10 -0
- package/package.json +1 -1
- package/src/activity-report.js +32 -38
- package/src/events-report.js +3 -6
- package/src/fuelconsumption-report.js +5 -10
- package/src/idle-report.js +6 -13
- package/src/kms-report.js +13 -18
- package/src/speeding-report.js +25 -30
- package/src/trip-report.js +25 -31
- package/.idea/codeStyles/Project.xml +0 -7
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/jsLibraryMappings.xml +0 -6
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="RunConfigurationProducerService">
|
|
4
|
+
<option name="ignoredProducers">
|
|
5
|
+
<set>
|
|
6
|
+
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
|
7
|
+
</set>
|
|
8
|
+
</option>
|
|
9
|
+
</component>
|
|
10
|
+
</project>
|
package/package.json
CHANGED
package/src/activity-report.js
CHANGED
|
@@ -11,33 +11,28 @@ const traccar = require("./util/traccar")
|
|
|
11
11
|
const {isInsideTimetable, isPartialInsideTimetable} = require("./util/trips");
|
|
12
12
|
const trips = require("./util/trips");
|
|
13
13
|
|
|
14
|
-
let traccarInstance
|
|
15
|
-
let userData
|
|
16
|
-
|
|
17
14
|
const fileName = 'ActivityReport'
|
|
18
15
|
|
|
19
|
-
async function createActivityReport(from, to,
|
|
16
|
+
async function createActivityReport(from, to, userData, traccarInstance) {
|
|
20
17
|
console.log('Create ActivityReport')
|
|
21
|
-
traccarInstance = traccar
|
|
22
|
-
userData = reportUserData
|
|
23
18
|
const reportData = []
|
|
24
19
|
|
|
25
20
|
if(userData.byDriver){
|
|
26
|
-
const allData = await createActivityReportByDriver(from, to)
|
|
21
|
+
const allData = await createActivityReportByDriver(from, to, userData, traccarInstance)
|
|
27
22
|
reportData.push(allData)
|
|
28
23
|
}
|
|
29
24
|
else if(userData.byGroup){
|
|
30
|
-
const allData = await createActivityReportByGroup(from, to)
|
|
25
|
+
const allData = await createActivityReportByGroup(from, to, userData, traccarInstance)
|
|
31
26
|
reportData.push(...allData)
|
|
32
27
|
} else {
|
|
33
|
-
const allData = await createActivityReportByDevice(from, to)
|
|
28
|
+
const allData = await createActivityReportByDevice(from, to, userData, traccarInstance)
|
|
34
29
|
reportData.push(allData)
|
|
35
30
|
}
|
|
36
31
|
|
|
37
32
|
return reportData
|
|
38
33
|
}
|
|
39
34
|
|
|
40
|
-
async function createActivityReportByGroup(from, to){
|
|
35
|
+
async function createActivityReportByGroup(from, to, userData, traccarInstance){
|
|
41
36
|
console.log("ByGroup")
|
|
42
37
|
const reportData = []
|
|
43
38
|
for (const g of userData.groups) {
|
|
@@ -76,7 +71,7 @@ async function createActivityReportByGroup(from, to){
|
|
|
76
71
|
return reportData
|
|
77
72
|
}
|
|
78
73
|
|
|
79
|
-
async function createActivityReportByDevice(from, to){
|
|
74
|
+
async function createActivityReportByDevice(from, to, userData, traccarInstance){
|
|
80
75
|
const groupIds = userData.groups.map(g => g.id)
|
|
81
76
|
const devicesToProcess = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
82
77
|
|
|
@@ -127,7 +122,7 @@ async function createActivityReportByDevice(from, to){
|
|
|
127
122
|
return allData
|
|
128
123
|
}
|
|
129
124
|
|
|
130
|
-
async function createActivityReportByDriver(from, to){
|
|
125
|
+
async function createActivityReportByDriver(from, to, userData, traccarInstance){
|
|
131
126
|
const devices = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
132
127
|
|
|
133
128
|
let tripsData = []
|
|
@@ -143,13 +138,13 @@ async function createActivityReportByDriver(from, to){
|
|
|
143
138
|
to: to
|
|
144
139
|
}
|
|
145
140
|
|
|
146
|
-
allData.drivers = processDrivers(from, to, userData.drivers, {trips: tripsData, route: routeData})
|
|
141
|
+
allData.drivers = processDrivers(from, to, userData.drivers, {trips: tripsData, route: routeData}, userData)
|
|
147
142
|
|
|
148
143
|
return allData
|
|
149
144
|
}
|
|
150
145
|
|
|
151
146
|
|
|
152
|
-
function processDevices(from, to, devices, data) {
|
|
147
|
+
function processDevices(from, to, devices, data, userData) {
|
|
153
148
|
const devicesResult = []
|
|
154
149
|
|
|
155
150
|
devices.forEach(d => {
|
|
@@ -216,7 +211,7 @@ function processDevices(from, to, devices, data) {
|
|
|
216
211
|
return devicesResult
|
|
217
212
|
}
|
|
218
213
|
|
|
219
|
-
function processDrivers(from, to, drivers, data) {
|
|
214
|
+
function processDrivers(from, to, drivers, data, userData) {
|
|
220
215
|
console.log(data)
|
|
221
216
|
const driversResult = []
|
|
222
217
|
drivers.forEach(d => {
|
|
@@ -269,20 +264,20 @@ async function exportActivityReportToPDF(userData, reportData) {
|
|
|
269
264
|
await headerFromUser(doc, translations.report.titleActivityReport, userData.user)
|
|
270
265
|
|
|
271
266
|
if(userData.groupByDay && userData.byDriver) {
|
|
272
|
-
exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData)
|
|
267
|
+
exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData, userData)
|
|
273
268
|
} else if(userData.groupByDay) {
|
|
274
|
-
exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData)
|
|
269
|
+
exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData, userData)
|
|
275
270
|
} else if(userData.byDriver) {
|
|
276
|
-
exportActivityReportToPDF_Driver(doc, translations, reportData)
|
|
271
|
+
exportActivityReportToPDF_Driver(doc, translations, reportData, userData)
|
|
277
272
|
} else {
|
|
278
|
-
exportActivityReportToPDF_Vehicle(doc, translations, reportData)
|
|
273
|
+
exportActivityReportToPDF_Vehicle(doc, translations, reportData, userData)
|
|
279
274
|
}
|
|
280
275
|
|
|
281
276
|
return doc
|
|
282
277
|
}
|
|
283
278
|
}
|
|
284
279
|
|
|
285
|
-
function exportActivityReportToPDF_Driver(doc, translations, reportData) {
|
|
280
|
+
function exportActivityReportToPDF_Driver(doc, translations, reportData, userData) {
|
|
286
281
|
const headers = [translations.report.driver,
|
|
287
282
|
translations.report.distance,
|
|
288
283
|
translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)',
|
|
@@ -314,7 +309,7 @@ function exportActivityReportToPDF_Driver(doc, translations, reportData) {
|
|
|
314
309
|
addTable(doc, headers, data, footValues, style, 35)
|
|
315
310
|
}
|
|
316
311
|
|
|
317
|
-
function exportActivityReportToPDF_Vehicle(doc, translations, reportData) {
|
|
312
|
+
function exportActivityReportToPDF_Vehicle(doc, translations, reportData, userData) {
|
|
318
313
|
const headers = [translations.report.vehicle,
|
|
319
314
|
translations.report.group,
|
|
320
315
|
translations.report.distance,
|
|
@@ -359,7 +354,7 @@ function exportActivityReportToPDF_Vehicle(doc, translations, reportData) {
|
|
|
359
354
|
addTable(doc, headers, data, footValues, style, 35)
|
|
360
355
|
}
|
|
361
356
|
|
|
362
|
-
function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData) {
|
|
357
|
+
function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData, userData) {
|
|
363
358
|
const headers = [translations.report.date,
|
|
364
359
|
translations.report.distance,
|
|
365
360
|
translations.report.start + ' ' + translations.report.odometer,
|
|
@@ -425,17 +420,17 @@ function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportD
|
|
|
425
420
|
const footValues = ['Total:' + d.summary.length,
|
|
426
421
|
(d.summary.reduce((a, b) => a + b.distance, 0) / 1000).toFixed(0),
|
|
427
422
|
'', '',
|
|
428
|
-
getSumAvgSpeed(d.summary),
|
|
429
|
-
getSumMaxSpeed(d.summary),
|
|
423
|
+
getSumAvgSpeed(d.summary, userData),
|
|
424
|
+
getSumMaxSpeed(d.summary, userData),
|
|
430
425
|
convertMS(d.summary.reduce((a, b) => a + b.engineHours, 0)),
|
|
431
|
-
getSumSpentFuel(d.summary)]
|
|
426
|
+
getSumSpentFuel(d.summary, userData)]
|
|
432
427
|
|
|
433
428
|
const style = getStyle(getUserPartner(userData.user))
|
|
434
429
|
addTable(doc, headers, data, footValues, style, 40)
|
|
435
430
|
})
|
|
436
431
|
}
|
|
437
432
|
|
|
438
|
-
function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations, reportData) {
|
|
433
|
+
function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations, reportData, userData) {
|
|
439
434
|
const headers = [{label: translations.report.vehicle, value: 'name'},
|
|
440
435
|
{label: translations.report.group, value: 'group'},
|
|
441
436
|
{label: translations.report.date, value: 'date'},
|
|
@@ -489,7 +484,7 @@ function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations,
|
|
|
489
484
|
}
|
|
490
485
|
}
|
|
491
486
|
|
|
492
|
-
function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData) {
|
|
487
|
+
function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData, userData) {
|
|
493
488
|
const headers = [translations.report.date,
|
|
494
489
|
translations.report.distance,
|
|
495
490
|
translations.report.avgSpeed + ' (Km/h)',
|
|
@@ -557,7 +552,7 @@ function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportDa
|
|
|
557
552
|
})
|
|
558
553
|
}
|
|
559
554
|
|
|
560
|
-
function exportActivityReportToExcel_Driver_GroupByDay(settings, translations, reportData) {
|
|
555
|
+
function exportActivityReportToExcel_Driver_GroupByDay(settings, translations, reportData, userData) {
|
|
561
556
|
const headers = [{label: translations.report.driver, value: 'name'},
|
|
562
557
|
{label: translations.report.group, value: 'group'},
|
|
563
558
|
{label: translations.report.date, value: 'date'},
|
|
@@ -632,7 +627,7 @@ function exportActivityReportToExcel_Driver(settings, translations, reportData)
|
|
|
632
627
|
}
|
|
633
628
|
}
|
|
634
629
|
|
|
635
|
-
function exportActivityReportToExcel_Vehicle(settings, translations, reportData) {
|
|
630
|
+
function exportActivityReportToExcel_Vehicle(settings, translations, reportData, userData) {
|
|
636
631
|
const headers = [{label: translations.report.vehicle, value: 'name'},
|
|
637
632
|
{label: translations.report.group, value: 'group'},
|
|
638
633
|
{label: translations.report.distance, value: 'distance'},
|
|
@@ -669,9 +664,8 @@ function exportActivityReportToExcel_Vehicle(settings, translations, reportData)
|
|
|
669
664
|
}
|
|
670
665
|
}
|
|
671
666
|
|
|
672
|
-
function exportActivityReportToExcel(
|
|
667
|
+
function exportActivityReportToExcel(userData, reportData) {
|
|
673
668
|
console.log('Export to Excel')
|
|
674
|
-
userData = reportUserData
|
|
675
669
|
const lang = userData.user.attributes.lang
|
|
676
670
|
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
677
671
|
|
|
@@ -681,17 +675,17 @@ function exportActivityReportToExcel(reportUserData, reportData) {
|
|
|
681
675
|
}
|
|
682
676
|
|
|
683
677
|
if(userData.groupByDay && userData.byDriver){
|
|
684
|
-
return exportActivityReportToExcel_Driver_GroupByDay(settings, translations, reportData)
|
|
678
|
+
return exportActivityReportToExcel_Driver_GroupByDay(settings, translations, reportData, userData)
|
|
685
679
|
} else if(userData.groupByDay){
|
|
686
|
-
return exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations, reportData)
|
|
680
|
+
return exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations, reportData, userData)
|
|
687
681
|
} else if(userData.byDriver){
|
|
688
|
-
return exportActivityReportToExcel_Driver(settings, translations, reportData)
|
|
682
|
+
return exportActivityReportToExcel_Driver(settings, translations, reportData, userData)
|
|
689
683
|
} else {
|
|
690
|
-
return exportActivityReportToExcel_Vehicle(settings, translations, reportData)
|
|
684
|
+
return exportActivityReportToExcel_Vehicle(settings, translations, reportData, userData)
|
|
691
685
|
}
|
|
692
686
|
}
|
|
693
687
|
|
|
694
|
-
function getSumAvgSpeed(data){
|
|
688
|
+
function getSumAvgSpeed(data, userData){
|
|
695
689
|
const values = data.map(item => {
|
|
696
690
|
if(userData.groupByDay){
|
|
697
691
|
return Math.round(item.averageSpeed * 1.85200)
|
|
@@ -702,7 +696,7 @@ function getSumAvgSpeed(data){
|
|
|
702
696
|
return Math.round((values.reduce((a, b) => a + b, 0)) / values.length)
|
|
703
697
|
}
|
|
704
698
|
|
|
705
|
-
function getSumMaxSpeed(data){
|
|
699
|
+
function getSumMaxSpeed(data, userData){
|
|
706
700
|
const values = data.map(item => {
|
|
707
701
|
if(userData.groupByDay){
|
|
708
702
|
return item.maxSpeed
|
|
@@ -716,7 +710,7 @@ function getSumMaxSpeed(data){
|
|
|
716
710
|
return Math.round(max * 1.85200)
|
|
717
711
|
}
|
|
718
712
|
|
|
719
|
-
function getSumSpentFuel(data){
|
|
713
|
+
function getSumSpentFuel(data, userData){
|
|
720
714
|
const values = data.map(item => {
|
|
721
715
|
if(userData.groupByDay){
|
|
722
716
|
return item.convertedSpentFuel >= 0 ? item.convertedSpentFuel : 0
|
package/src/events-report.js
CHANGED
|
@@ -9,10 +9,7 @@ const {convertToLocaleString} = require("./util/utils");
|
|
|
9
9
|
|
|
10
10
|
const fileName = 'EventReport'
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
async function createEventsReport(from, to, userData, traccarInstance) {
|
|
15
|
-
traccar = traccarInstance
|
|
12
|
+
async function createEventsReport(from, to, userData, traccar) {
|
|
16
13
|
console.log('Create EventsReport')
|
|
17
14
|
const reportData = []
|
|
18
15
|
|
|
@@ -45,7 +42,7 @@ async function createEventsReport(from, to, userData, traccarInstance) {
|
|
|
45
42
|
|
|
46
43
|
withoutGroupDevices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
47
44
|
|
|
48
|
-
const data = await getReportData(from, to, withoutGroupDevices, userData.eventTypes)
|
|
45
|
+
const data = await getReportData(from, to, withoutGroupDevices, userData.eventTypes, traccar)
|
|
49
46
|
|
|
50
47
|
if(data.length > 0) {
|
|
51
48
|
reportData.push({
|
|
@@ -57,7 +54,7 @@ async function createEventsReport(from, to, userData, traccarInstance) {
|
|
|
57
54
|
return reportData
|
|
58
55
|
}
|
|
59
56
|
|
|
60
|
-
async function getReportData(from, to, devices, types) {
|
|
57
|
+
async function getReportData(from, to, devices, types, traccar) {
|
|
61
58
|
let data = []
|
|
62
59
|
const arrayOfArrays = automaticReports.sliceArray(devices)
|
|
63
60
|
const traccarTypes = new Set(types.map(t => t.startsWith('alarm') ? 'alarm' : t))
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
const automaticReports = require("./automaticReports");
|
|
2
2
|
const refuelingReport = require("./refueling-report");
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
async function createFuelConsumptionReport(from, to, userData, traccarInstance) {
|
|
7
|
-
traccar = traccarInstance
|
|
4
|
+
async function createFuelConsumptionReport(from, to, userData, traccar) {
|
|
8
5
|
console.log('Create FuelConsumption Report')
|
|
9
6
|
|
|
10
7
|
const reportData = []
|
|
@@ -60,12 +57,10 @@ async function createFuelConsumptionReport(from, to, userData, traccarInstance)
|
|
|
60
57
|
const dayTrips = groupedTrips.get(key)
|
|
61
58
|
const dayRefueling = groupedRefuelings.get(key)
|
|
62
59
|
const distance = dayTrips.reduce((a, b) => a + b.distance, 0)
|
|
63
|
-
let spentFuel =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
spentFuel = automaticReports.calculateSpentFuel(dayTrips.reduce((a, b) => a + b.spentFuel, 0), d)
|
|
68
|
-
}
|
|
60
|
+
let spentFuel = d.attributes.xpert ?
|
|
61
|
+
automaticReports.calculateXpertSpentFuel(key, positions)
|
|
62
|
+
:
|
|
63
|
+
automaticReports.calculateSpentFuel(dayTrips.reduce((a, b) => a + b.spentFuel, 0), d)
|
|
69
64
|
|
|
70
65
|
const day = {
|
|
71
66
|
date: key,
|
package/src/idle-report.js
CHANGED
|
@@ -6,32 +6,26 @@ const {convertToLocaleString, convertMS} = require("./util/utils");
|
|
|
6
6
|
const {getStyle} = require("./reportStyle");
|
|
7
7
|
const {getUserPartner} = require("fleetmap-partners");
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
let traccarInstance
|
|
11
|
-
let userData
|
|
12
|
-
|
|
13
9
|
const fileName = 'IdleReport'
|
|
14
10
|
|
|
15
|
-
async function createIdleReport(from, to,
|
|
11
|
+
async function createIdleReport(from, to, userData, traccarInstance) {
|
|
16
12
|
console.log('Create IdleReport')
|
|
17
|
-
userData = reportUserData
|
|
18
|
-
traccarInstance = traccar
|
|
19
13
|
const reportData = []
|
|
20
14
|
|
|
21
15
|
if (userData.byGroup) {
|
|
22
16
|
console.log("ByGroup")
|
|
23
|
-
const allData = await createTripReportByGroup(from, to)
|
|
17
|
+
const allData = await createTripReportByGroup(from, to, userData, traccarInstance)
|
|
24
18
|
reportData.push(...allData)
|
|
25
19
|
} else {
|
|
26
20
|
console.log("ByDevice")
|
|
27
|
-
const report = await createTripReportByDevice(from, to)
|
|
21
|
+
const report = await createTripReportByDevice(from, to, userData, traccarInstance)
|
|
28
22
|
reportData.push(report)
|
|
29
23
|
}
|
|
30
24
|
|
|
31
25
|
return reportData
|
|
32
26
|
}
|
|
33
27
|
|
|
34
|
-
async function createTripReportByGroup(from, to) {
|
|
28
|
+
async function createTripReportByGroup(from, to, userData, traccarInstance) {
|
|
35
29
|
const reportData = []
|
|
36
30
|
for (const g of userData.groups) {
|
|
37
31
|
const devices = userData.devices.filter(d => d.groupId === g.id)
|
|
@@ -61,14 +55,13 @@ async function createTripReportByGroup(from, to) {
|
|
|
61
55
|
const groupIds = userData.groups.map(g => g.id)
|
|
62
56
|
const withoutGroupDevices = userData.devices.filter(d => !groupIds.includes(d.groupId))
|
|
63
57
|
|
|
64
|
-
const allData = await createTripReportByDevice(from, to, withoutGroupDevices)
|
|
58
|
+
const allData = await createTripReportByDevice(from, to, withoutGroupDevices, userData, traccarInstance)
|
|
65
59
|
reportData.push(allData)
|
|
66
60
|
|
|
67
61
|
return reportData
|
|
68
62
|
}
|
|
69
63
|
|
|
70
|
-
async function createTripReportByDevice(from, to) {
|
|
71
|
-
const devices = userData.devices
|
|
64
|
+
async function createTripReportByDevice(from, to, devices, userData, traccarInstance) {
|
|
72
65
|
const allData = {
|
|
73
66
|
devices: [],
|
|
74
67
|
from: from,
|
package/src/kms-report.js
CHANGED
|
@@ -11,37 +11,32 @@ const drivers = require("./util/driver")
|
|
|
11
11
|
const { isInsideTimetable, isPartialInsideTimetable} = require("./util/trips")
|
|
12
12
|
const word = require("./word");
|
|
13
13
|
|
|
14
|
-
let traccarInstance
|
|
15
|
-
let userData
|
|
16
|
-
|
|
17
14
|
const fileName = 'KmsReport'
|
|
18
15
|
|
|
19
|
-
async function createKmsReport(from, to,
|
|
16
|
+
async function createKmsReport(from, to, userData, traccarInstance) {
|
|
20
17
|
console.log('Create KmsReport')
|
|
21
18
|
|
|
22
19
|
console.log(from, to)
|
|
23
|
-
traccarInstance = traccar
|
|
24
|
-
userData = reportUserData
|
|
25
20
|
const reportData = []
|
|
26
21
|
if(userData.byDriver){
|
|
27
22
|
console.log("ByDriver")
|
|
28
|
-
const allData = await createKmsReportByDriver(from, to)
|
|
23
|
+
const allData = await createKmsReportByDriver(from, to, userData, traccarInstance)
|
|
29
24
|
reportData.push(allData)
|
|
30
25
|
}
|
|
31
26
|
else if(userData.byGroup){
|
|
32
27
|
console.log("ByGroup")
|
|
33
|
-
const allData = await createKmsReportByGroup(from, to)
|
|
28
|
+
const allData = await createKmsReportByGroup(from, to, userData, traccarInstance)
|
|
34
29
|
reportData.push(...allData)
|
|
35
30
|
} else {
|
|
36
31
|
console.log("ByDevice")
|
|
37
|
-
const allData = await createKmsReportByDevice(from, to)
|
|
32
|
+
const allData = await createKmsReportByDevice(from, to, userData, traccarInstance)
|
|
38
33
|
reportData.push(allData)
|
|
39
34
|
}
|
|
40
35
|
|
|
41
36
|
return reportData
|
|
42
37
|
}
|
|
43
38
|
|
|
44
|
-
async function createKmsReportByDevice(from, to) {
|
|
39
|
+
async function createKmsReportByDevice(from, to, userData, traccarInstance) {
|
|
45
40
|
const groupIds = userData.groups.map(g => g.id)
|
|
46
41
|
const devicesToProcess = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
47
42
|
|
|
@@ -59,13 +54,13 @@ async function createKmsReportByDevice(from, to) {
|
|
|
59
54
|
|
|
60
55
|
if (tripsData.length > 0) {
|
|
61
56
|
trips.checkTripsKms(traccarInstance, from, to, devicesToProcess, {trips: tripsData, route: route})
|
|
62
|
-
allData.devices = processDevices(from, to, devicesToProcess, {trips: tripsData, route: route})
|
|
57
|
+
allData.devices = processDevices(from, to, devicesToProcess, {trips: tripsData, route: route}, userData)
|
|
63
58
|
}
|
|
64
59
|
|
|
65
60
|
return allData
|
|
66
61
|
}
|
|
67
62
|
|
|
68
|
-
async function createKmsReportByDriver(from, to) {
|
|
63
|
+
async function createKmsReportByDriver(from, to, userData, traccarInstance) {
|
|
69
64
|
const devices = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
70
65
|
console.log(devices.length)
|
|
71
66
|
|
|
@@ -77,10 +72,10 @@ async function createKmsReportByDriver(from, to) {
|
|
|
77
72
|
const tripsData = await traccar.getTrips(traccarInstance, from, to, devices)
|
|
78
73
|
const routeData = await traccar.getTrips(traccarInstance, from, to, devices)
|
|
79
74
|
|
|
80
|
-
return { drivers: processDrivers(from, to, userData
|
|
75
|
+
return { drivers: processDrivers(from, to, userData, {trips: tripsData, route: routeData}) }
|
|
81
76
|
}
|
|
82
77
|
|
|
83
|
-
async function createKmsReportByGroup(from, to) {
|
|
78
|
+
async function createKmsReportByGroup(from, to, userData, traccarInstance) {
|
|
84
79
|
const reportData = []
|
|
85
80
|
for (const g of userData.groups) {
|
|
86
81
|
const devices = userData.devices.filter(d => d.groupId === g.id)
|
|
@@ -101,7 +96,7 @@ async function createKmsReportByGroup(from, to) {
|
|
|
101
96
|
|
|
102
97
|
if (tripsData.length > 0) {
|
|
103
98
|
trips.checkTripsKms(traccarInstance, from, to, devices, {trips: tripsData, route: route})
|
|
104
|
-
groupData.devices = processDevices(from, to, devices, {trips: tripsData, route: route})
|
|
99
|
+
groupData.devices = processDevices(from, to, devices, {trips: tripsData, route: route}, userData)
|
|
105
100
|
}
|
|
106
101
|
|
|
107
102
|
reportData.push(groupData)
|
|
@@ -114,10 +109,10 @@ async function createKmsReportByGroup(from, to) {
|
|
|
114
109
|
return reportData
|
|
115
110
|
}
|
|
116
111
|
|
|
117
|
-
function processDrivers(from, to,
|
|
112
|
+
function processDrivers(from, to, userData, data) {
|
|
118
113
|
console.log(data)
|
|
119
114
|
const driversResult = []
|
|
120
|
-
drivers.forEach(d => {
|
|
115
|
+
userData.drivers.forEach(d => {
|
|
121
116
|
const route = data.route.filter(p => p.attributes.driverUniqueId === d.uniqueId)
|
|
122
117
|
const trips = data.trips.filter(t => t.driverUniqueId === d.uniqueId
|
|
123
118
|
&& (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
|
|
@@ -152,7 +147,7 @@ function processDrivers(from, to, drivers, data) {
|
|
|
152
147
|
return driversResult
|
|
153
148
|
}
|
|
154
149
|
|
|
155
|
-
function processDevices(from, to, devices, data) {
|
|
150
|
+
function processDevices(from, to, devices, data, userData) {
|
|
156
151
|
const devicesResult = []
|
|
157
152
|
|
|
158
153
|
for (const d of devices) {
|
package/src/speeding-report.js
CHANGED
|
@@ -10,38 +10,33 @@ const drivers = require("./util/driver")
|
|
|
10
10
|
const {distance, point} = require('turf')
|
|
11
11
|
const here = require('./here')
|
|
12
12
|
const {getUserPartner} = require("fleetmap-partners");
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
let traccarInstance
|
|
16
|
-
let userData
|
|
13
|
+
const traccarHelper = require("./util/traccar");
|
|
17
14
|
|
|
18
15
|
const fileName = 'SpeedingReport'
|
|
19
16
|
const eventTypes = ['deviceOverspeed']
|
|
20
17
|
|
|
21
|
-
async function createSpeedingReport(from, to,
|
|
22
|
-
traccarInstance = traccar
|
|
23
|
-
userData = reportUserData
|
|
18
|
+
async function createSpeedingReport(from, to, userData, traccarInstance) {
|
|
24
19
|
const reportData = []
|
|
25
20
|
|
|
26
21
|
if (userData.byDriver) {
|
|
27
22
|
console.log("ByDriver")
|
|
28
|
-
const allData = await createSpeedingReportByDriver(from, to)
|
|
23
|
+
const allData = await createSpeedingReportByDriver(from, to, userData, traccarInstance)
|
|
29
24
|
reportData.push(allData)
|
|
30
25
|
}
|
|
31
26
|
else if (userData.byGroup) {
|
|
32
27
|
console.log("ByGroup")
|
|
33
|
-
const allData = await createSpeedingReportByGroup(from, to)
|
|
28
|
+
const allData = await createSpeedingReportByGroup(from, to, userData, traccarInstance)
|
|
34
29
|
reportData.push(...allData)
|
|
35
30
|
} else {
|
|
36
31
|
console.log("createSpeedingReportByDevice")
|
|
37
|
-
const allData = await createSpeedingReportByDevice(from, to, userData.devices)
|
|
32
|
+
const allData = await createSpeedingReportByDevice(from, to, userData.devices, userData, traccarInstance)
|
|
38
33
|
reportData.push(allData)
|
|
39
34
|
}
|
|
40
35
|
|
|
41
36
|
return reportData
|
|
42
37
|
}
|
|
43
38
|
|
|
44
|
-
async function createSpeedingReportByGroup(from, to){
|
|
39
|
+
async function createSpeedingReportByGroup(from, to, userData, traccarInstance){
|
|
45
40
|
const reportData = []
|
|
46
41
|
for (const g of userData.groups) {
|
|
47
42
|
const devices = userData.devices.filter(d => d.groupId === g.id)
|
|
@@ -53,8 +48,8 @@ async function createSpeedingReportByGroup(from, to){
|
|
|
53
48
|
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
54
49
|
}
|
|
55
50
|
|
|
56
|
-
const events = await
|
|
57
|
-
const routes = await
|
|
51
|
+
const events = await traccarHelper.getEvents(traccarInstance, from, to, devices, eventTypes)
|
|
52
|
+
const routes = await traccarHelper.getRoute(traccarInstance, from, to, devices)
|
|
58
53
|
|
|
59
54
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
60
55
|
|
|
@@ -74,15 +69,15 @@ async function createSpeedingReportByGroup(from, to){
|
|
|
74
69
|
return reportData
|
|
75
70
|
}
|
|
76
71
|
|
|
77
|
-
async function createSpeedingReportByDevice(from, to, devices) {
|
|
72
|
+
async function createSpeedingReportByDevice(from, to, devices, userData, traccarInstance) {
|
|
78
73
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
79
74
|
|
|
80
|
-
const routes = await
|
|
75
|
+
const routes = await traccarHelper.getRoute(traccarInstance, from, to, devices)
|
|
81
76
|
const events = []
|
|
82
77
|
if(!userData.useVehicleSpeedLimit && userData.customSpeed){
|
|
83
78
|
events.push(...await getCustomSpeedLimitEvents(devices, routes))
|
|
84
79
|
} else {
|
|
85
|
-
events.push(...await
|
|
80
|
+
events.push(...await traccarHelper.getEvents(traccarInstance, from, to, devices, eventTypes))
|
|
86
81
|
}
|
|
87
82
|
|
|
88
83
|
if(userData.roadSpeedLimits){
|
|
@@ -100,7 +95,7 @@ async function createSpeedingReportByDevice(from, to, devices) {
|
|
|
100
95
|
}
|
|
101
96
|
}
|
|
102
97
|
|
|
103
|
-
async function createSpeedingReportByDriver(from, to) {
|
|
98
|
+
async function createSpeedingReportByDriver(from, to, userData) {
|
|
104
99
|
const devices = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
105
100
|
console.log('Devices with driver',devices.length)
|
|
106
101
|
|
|
@@ -109,12 +104,12 @@ async function createSpeedingReportByDriver(from, to) {
|
|
|
109
104
|
return { drivers: [] }
|
|
110
105
|
}
|
|
111
106
|
|
|
112
|
-
const routes = await
|
|
107
|
+
const routes = await traccarHelper.getRoute(traccarInstance, from, to, devices)
|
|
113
108
|
const events = []
|
|
114
109
|
if(!userData.useVehicleSpeedLimit && userData.customSpeed){
|
|
115
|
-
events.push(...await getCustomSpeedLimitEvents(devices, routes))
|
|
110
|
+
events.push(...await getCustomSpeedLimitEvents(devices, routes, userData.customSpeed))
|
|
116
111
|
} else {
|
|
117
|
-
events.push(...await
|
|
112
|
+
events.push(...await traccarHelper.getEvents(traccarInstance, from, to, devices, eventTypes))
|
|
118
113
|
}
|
|
119
114
|
|
|
120
115
|
if(userData.roadSpeedLimits){
|
|
@@ -126,13 +121,13 @@ async function createSpeedingReportByDriver(from, to) {
|
|
|
126
121
|
return { drivers: [] }
|
|
127
122
|
}
|
|
128
123
|
|
|
129
|
-
return {drivers: await processDrivers(from, to, events, routes)}
|
|
124
|
+
return {drivers: await processDrivers(from, to, events, routes, userData)}
|
|
130
125
|
}
|
|
131
126
|
|
|
132
|
-
async function processDrivers(from, to, events, routes) {
|
|
127
|
+
async function processDrivers(from, to, events, routes, userData) {
|
|
133
128
|
const driversResult = []
|
|
134
129
|
|
|
135
|
-
await findEventsPosition(from, to, userData.devices, events, routes)
|
|
130
|
+
await findEventsPosition(from, to, userData.devices, events, routes, userData)
|
|
136
131
|
|
|
137
132
|
userData.drivers.forEach(d => {
|
|
138
133
|
const driverEvents = events.filter(e => e.position && e.position.attributes.driverUniqueId === d.uniqueId)
|
|
@@ -153,9 +148,9 @@ async function processDrivers(from, to, events, routes) {
|
|
|
153
148
|
return driversResult
|
|
154
149
|
}
|
|
155
150
|
|
|
156
|
-
async function processDevices(from, to, devices, events, routes) {
|
|
151
|
+
async function processDevices(from, to, devices, events, routes, userData) {
|
|
157
152
|
const devicesResult = []
|
|
158
|
-
await findEventsPosition(from, to, devices, events, routes)
|
|
153
|
+
await findEventsPosition(from, to, devices, events, routes, userData)
|
|
159
154
|
|
|
160
155
|
for (const d of devices) {
|
|
161
156
|
const deviceEvents = events.filter(e => e.deviceId === d.id && e.position)
|
|
@@ -176,7 +171,7 @@ async function processDevices(from, to, devices, events, routes) {
|
|
|
176
171
|
return devicesResult
|
|
177
172
|
}
|
|
178
173
|
|
|
179
|
-
async function findEventsPosition(from, to, devices, events, routes){
|
|
174
|
+
async function findEventsPosition(from, to, devices, events, routes, userData){
|
|
180
175
|
for (const d of devices) {
|
|
181
176
|
let deviceEvents = events.filter(e => e.deviceId === d.id && e.positionId)
|
|
182
177
|
if (deviceEvents.length > 0) {
|
|
@@ -195,7 +190,7 @@ async function findEventsPosition(from, to, devices, events, routes){
|
|
|
195
190
|
}
|
|
196
191
|
|
|
197
192
|
a.position = positions[pIndex]
|
|
198
|
-
pIndex = calculateEventData(positions, pIndex, a, d, geofence)
|
|
193
|
+
pIndex = calculateEventData(positions, pIndex, a, d, geofence, userData)
|
|
199
194
|
positions.slice(pIndex)
|
|
200
195
|
}
|
|
201
196
|
}
|
|
@@ -203,10 +198,10 @@ async function findEventsPosition(from, to, devices, events, routes){
|
|
|
203
198
|
}
|
|
204
199
|
}
|
|
205
200
|
|
|
206
|
-
async function getCustomSpeedLimitEvents(devices, routes){
|
|
201
|
+
async function getCustomSpeedLimitEvents(devices, routes, customSpeed){
|
|
207
202
|
console.log('custom speed limit events')
|
|
208
203
|
const events = []
|
|
209
|
-
const maxSpeed =
|
|
204
|
+
const maxSpeed = customSpeed / 1.85200
|
|
210
205
|
|
|
211
206
|
for (const d of devices) {
|
|
212
207
|
const positions = routes.filter(p => p.deviceId === d.id)
|
|
@@ -277,7 +272,7 @@ async function getHereEvents(devices, routes, threshold){
|
|
|
277
272
|
return events
|
|
278
273
|
}
|
|
279
274
|
|
|
280
|
-
function calculateEventData(positions, pIndex, alert, device, geofence){
|
|
275
|
+
function calculateEventData(positions, pIndex, alert, device, geofence, userData){
|
|
281
276
|
let endEventPosition = alert.position
|
|
282
277
|
let maxSpeed = alert.position.speed
|
|
283
278
|
let dist = 0
|
package/src/trip-report.js
CHANGED
|
@@ -7,41 +7,35 @@ const drivers = require("./util/driver")
|
|
|
7
7
|
const {getUserPartner} = require("fleetmap-partners")
|
|
8
8
|
const {headerFromUser, addTable} = require("./util/pdfDocument")
|
|
9
9
|
const {getStyle} = require("./reportStyle")
|
|
10
|
-
const
|
|
10
|
+
const traccarHelper = require("./util/traccar")
|
|
11
11
|
const trips = require("./util/trips");
|
|
12
12
|
const {isInsideTimetable, addNearestPOIs, isPartialInsideTimetable} = require("./util/trips")
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
let traccarInstance
|
|
16
|
-
let userData
|
|
17
|
-
|
|
18
14
|
const fileName = 'TripReport'
|
|
19
15
|
|
|
20
|
-
async function createTripReport(from, to,
|
|
16
|
+
async function createTripReport(from, to, userData, traccar) {
|
|
21
17
|
console.log('Create TripReport')
|
|
22
|
-
userData = reportUserData
|
|
23
|
-
traccarInstance = traccar
|
|
24
18
|
const reportData = []
|
|
25
19
|
|
|
26
20
|
if (userData.byDriver) {
|
|
27
21
|
console.log("ByDriver")
|
|
28
|
-
const report = await createTripReportByDriver(from, to)
|
|
22
|
+
const report = await createTripReportByDriver(from, to, userData, traccar)
|
|
29
23
|
reportData.push(report)
|
|
30
24
|
}
|
|
31
25
|
else if (userData.byGroup) {
|
|
32
26
|
console.log("ByGroup")
|
|
33
|
-
const allData = await createTripReportByGroup(from, to)
|
|
27
|
+
const allData = await createTripReportByGroup(from, to, userData, traccar)
|
|
34
28
|
reportData.push(...allData)
|
|
35
29
|
} else {
|
|
36
30
|
console.log("ByDevice")
|
|
37
|
-
const report = await createTripReportByDevice(from, to)
|
|
31
|
+
const report = await createTripReportByDevice(from, to, userData, traccar)
|
|
38
32
|
reportData.push(report)
|
|
39
33
|
}
|
|
40
34
|
|
|
41
35
|
return reportData
|
|
42
36
|
}
|
|
43
37
|
|
|
44
|
-
async function createTripReportByDevice(from, to) {
|
|
38
|
+
async function createTripReportByDevice(from, to, userData, traccar) {
|
|
45
39
|
const devices = userData.devices
|
|
46
40
|
const allData = {
|
|
47
41
|
devices: [],
|
|
@@ -51,21 +45,21 @@ async function createTripReportByDevice(from, to) {
|
|
|
51
45
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
52
46
|
|
|
53
47
|
const devicesToSlice = devices.slice()
|
|
54
|
-
const tripsData = await
|
|
55
|
-
const stopsData = await
|
|
56
|
-
const routeData = await
|
|
48
|
+
const tripsData = await traccarHelper.getTrips(traccar, from, to, devicesToSlice)
|
|
49
|
+
const stopsData = await traccarHelper.getStops(traccar, from, to, devicesToSlice)
|
|
50
|
+
const routeData = await traccarHelper.getRoute(traccar, from, to, devicesToSlice)
|
|
57
51
|
|
|
58
52
|
console.log('Trips:' + tripsData.length)
|
|
59
53
|
|
|
60
54
|
if (tripsData.length > 0) {
|
|
61
|
-
trips.checkTripsKms(
|
|
62
|
-
allData.devices = processDevices(from, to, devices, {trips: tripsData, stops: stopsData, route: routeData})
|
|
55
|
+
trips.checkTripsKms(traccar, from, to, devices, {trips: tripsData, route: routeData})
|
|
56
|
+
allData.devices = processDevices(from, to, devices, {trips: tripsData, stops: stopsData, route: routeData}, userData)
|
|
63
57
|
}
|
|
64
58
|
|
|
65
59
|
return allData
|
|
66
60
|
}
|
|
67
61
|
|
|
68
|
-
async function createTripReportByGroup(from, to) {
|
|
62
|
+
async function createTripReportByGroup(from, to, userData, traccar) {
|
|
69
63
|
const reportData = []
|
|
70
64
|
for (const g of userData.groups) {
|
|
71
65
|
const devices = userData.devices.filter(d => d.groupId === g.id)
|
|
@@ -77,20 +71,20 @@ async function createTripReportByGroup(from, to) {
|
|
|
77
71
|
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
78
72
|
}
|
|
79
73
|
|
|
80
|
-
const response = await
|
|
74
|
+
const response = await traccar.reports.reportsTripsGet(from, to, null, [g.id])
|
|
81
75
|
const tripsData = response.data
|
|
82
76
|
|
|
83
|
-
const stopsResponse = await
|
|
77
|
+
const stopsResponse = await traccar.reports.reportsStopsGet(from, to, null, [g.id])
|
|
84
78
|
const stopsData = stopsResponse.data
|
|
85
79
|
|
|
86
|
-
const routeResponse = await
|
|
80
|
+
const routeResponse = await traccar.reports.reportsRouteGet(from, to, null, [g.id])
|
|
87
81
|
const routeData = routeResponse.data
|
|
88
82
|
|
|
89
83
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
90
84
|
|
|
91
85
|
if (tripsData.length > 0) {
|
|
92
86
|
console.log('Trips:' + tripsData.length)
|
|
93
|
-
groupData.devices = processDevices(from, to, devices, {trips: tripsData, stops: stopsData, route: routeData})
|
|
87
|
+
groupData.devices = processDevices(from, to, devices, {trips: tripsData, stops: stopsData, route: routeData}, userData)
|
|
94
88
|
|
|
95
89
|
reportData.push(groupData)
|
|
96
90
|
}
|
|
@@ -100,14 +94,14 @@ async function createTripReportByGroup(from, to) {
|
|
|
100
94
|
const groupIds = userData.groups.map(g => g.id)
|
|
101
95
|
const withoutGroupDevices = userData.devices.filter(d => !groupIds.includes(d.groupId))
|
|
102
96
|
|
|
103
|
-
const allData = await createTripReportByDevice(from, to, withoutGroupDevices)
|
|
97
|
+
const allData = await createTripReportByDevice(from, to, withoutGroupDevices, userData)
|
|
104
98
|
reportData.push(allData)
|
|
105
99
|
|
|
106
100
|
return reportData
|
|
107
101
|
}
|
|
108
102
|
|
|
109
|
-
async function createTripReportByDriver(from, to){
|
|
110
|
-
const devices = await drivers.devicesByDriver(
|
|
103
|
+
async function createTripReportByDriver(from, to, userData, traccar){
|
|
104
|
+
const devices = await drivers.devicesByDriver(traccar, from, to, userData.drivers, userData.devices)
|
|
111
105
|
console.log(devices.length)
|
|
112
106
|
|
|
113
107
|
if(!devices.length){
|
|
@@ -115,13 +109,13 @@ async function createTripReportByDriver(from, to){
|
|
|
115
109
|
return { drivers:[] }
|
|
116
110
|
}
|
|
117
111
|
|
|
118
|
-
const tripsData = await
|
|
119
|
-
const routeData = await
|
|
112
|
+
const tripsData = await traccarHelper.getTrips(traccar, from, to, devices)
|
|
113
|
+
const routeData = await traccarHelper.getRoute(traccar, from, to, devices)
|
|
120
114
|
|
|
121
|
-
return { drivers: processDrivers(from, to, userData
|
|
115
|
+
return { drivers: processDrivers(from, to, userData, {trips: tripsData, route: routeData})}
|
|
122
116
|
}
|
|
123
117
|
|
|
124
|
-
function processDevices(from, to, devices, data) {
|
|
118
|
+
function processDevices(from, to, devices, data, userData) {
|
|
125
119
|
const devicesResult = []
|
|
126
120
|
|
|
127
121
|
devices.forEach(d => {
|
|
@@ -175,10 +169,10 @@ function processDevices(from, to, devices, data) {
|
|
|
175
169
|
return devicesResult
|
|
176
170
|
}
|
|
177
171
|
|
|
178
|
-
function processDrivers(from, to,
|
|
172
|
+
function processDrivers(from, to, userData, data) {
|
|
179
173
|
console.log(data)
|
|
180
174
|
const driversResult = []
|
|
181
|
-
drivers.forEach(d => {
|
|
175
|
+
userData.drivers.forEach(d => {
|
|
182
176
|
const route = data.route.filter(p => p.attributes.driverUniqueId === d.uniqueId)
|
|
183
177
|
const trips = data.trips.filter(t => t.driverUniqueId === d.uniqueId
|
|
184
178
|
&& (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
|