fleetmap-reports 1.0.309 → 1.0.313

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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.309",
3
+ "version": "1.0.313",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -138,13 +138,13 @@ async function createActivityReportByDriver(from, to, userData, traccarInstance)
138
138
  to: to
139
139
  }
140
140
 
141
- allData.drivers = processDrivers(from, to, userData.drivers, {trips: tripsData, route: routeData})
141
+ allData.drivers = processDrivers(from, to, userData.drivers, {trips: tripsData, route: routeData}, userData)
142
142
 
143
143
  return allData
144
144
  }
145
145
 
146
146
 
147
- function processDevices(from, to, devices, data) {
147
+ function processDevices(from, to, devices, data, userData) {
148
148
  const devicesResult = []
149
149
 
150
150
  devices.forEach(d => {
@@ -211,7 +211,7 @@ function processDevices(from, to, devices, data) {
211
211
  return devicesResult
212
212
  }
213
213
 
214
- function processDrivers(from, to, drivers, data) {
214
+ function processDrivers(from, to, drivers, data, userData) {
215
215
  console.log(data)
216
216
  const driversResult = []
217
217
  drivers.forEach(d => {
@@ -264,20 +264,20 @@ async function exportActivityReportToPDF(userData, reportData) {
264
264
  await headerFromUser(doc, translations.report.titleActivityReport, userData.user)
265
265
 
266
266
  if(userData.groupByDay && userData.byDriver) {
267
- exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData)
267
+ exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData, userData)
268
268
  } else if(userData.groupByDay) {
269
- exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData)
269
+ exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData, userData)
270
270
  } else if(userData.byDriver) {
271
- exportActivityReportToPDF_Driver(doc, translations, reportData)
271
+ exportActivityReportToPDF_Driver(doc, translations, reportData, userData)
272
272
  } else {
273
- exportActivityReportToPDF_Vehicle(doc, translations, reportData)
273
+ exportActivityReportToPDF_Vehicle(doc, translations, reportData, userData)
274
274
  }
275
275
 
276
276
  return doc
277
277
  }
278
278
  }
279
279
 
280
- function exportActivityReportToPDF_Driver(doc, translations, reportData) {
280
+ function exportActivityReportToPDF_Driver(doc, translations, reportData, userData) {
281
281
  const headers = [translations.report.driver,
282
282
  translations.report.distance,
283
283
  translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)',
@@ -301,15 +301,15 @@ function exportActivityReportToPDF_Driver(doc, translations, reportData) {
301
301
 
302
302
  const footValues = ['Total:' + reportData.drivers.length,
303
303
  (reportData.drivers.reduce((a, b) => a + b.summary[0].distance, 0) / 1000).toFixed(0),
304
- getSumAvgSpeed(reportData.drivers),
305
- getSumMaxSpeed(reportData.drivers),
304
+ getSumAvgSpeed(reportData.drivers, userData),
305
+ getSumMaxSpeed(reportData.drivers, userData),
306
306
  convertMS(reportData.drivers.reduce((a, b) => a + b.summary[0].engineHours, 0))]
307
307
 
308
308
  const style = getStyle(getUserPartner(userData.user))
309
309
  addTable(doc, headers, data, footValues, style, 35)
310
310
  }
311
311
 
312
- function exportActivityReportToPDF_Vehicle(doc, translations, reportData) {
312
+ function exportActivityReportToPDF_Vehicle(doc, translations, reportData, userData) {
313
313
  const headers = [translations.report.vehicle,
314
314
  translations.report.group,
315
315
  translations.report.distance,
@@ -345,16 +345,16 @@ function exportActivityReportToPDF_Vehicle(doc, translations, reportData) {
345
345
  '',
346
346
  (reportData.devices.reduce((a, b) => a + b.summary[0].distance, 0) / 1000).toFixed(0),
347
347
  '', '',
348
- getSumAvgSpeed(reportData.devices),
349
- getSumMaxSpeed(reportData.devices),
348
+ getSumAvgSpeed(reportData.devices, userData),
349
+ getSumMaxSpeed(reportData.devices, userData),
350
350
  convertMS(reportData.devices.reduce((a, b) => a + b.summary[0].engineHours, 0)),
351
- getSumSpentFuel(reportData.devices)]
351
+ getSumSpentFuel(reportData.devices, userdata)]
352
352
 
353
353
  const style = getStyle(getUserPartner(userData.user))
354
354
  addTable(doc, headers, data, footValues, style, 35)
355
355
  }
356
356
 
357
- function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData) {
357
+ function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData, userData) {
358
358
  const headers = [translations.report.date,
359
359
  translations.report.distance,
360
360
  translations.report.start + ' ' + translations.report.odometer,
@@ -420,17 +420,17 @@ function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportD
420
420
  const footValues = ['Total:' + d.summary.length,
421
421
  (d.summary.reduce((a, b) => a + b.distance, 0) / 1000).toFixed(0),
422
422
  '', '',
423
- getSumAvgSpeed(d.summary),
424
- getSumMaxSpeed(d.summary),
423
+ getSumAvgSpeed(d.summary, userData),
424
+ getSumMaxSpeed(d.summary, userData),
425
425
  convertMS(d.summary.reduce((a, b) => a + b.engineHours, 0)),
426
- getSumSpentFuel(d.summary)]
426
+ getSumSpentFuel(d.summary, userData)]
427
427
 
428
428
  const style = getStyle(getUserPartner(userData.user))
429
429
  addTable(doc, headers, data, footValues, style, 40)
430
430
  })
431
431
  }
432
432
 
433
- function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations, reportData) {
433
+ function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations, reportData, userData) {
434
434
  const headers = [{label: translations.report.vehicle, value: 'name'},
435
435
  {label: translations.report.group, value: 'group'},
436
436
  {label: translations.report.date, value: 'date'},
@@ -484,7 +484,7 @@ function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations,
484
484
  }
485
485
  }
486
486
 
487
- function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData) {
487
+ function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData, userData) {
488
488
  const headers = [translations.report.date,
489
489
  translations.report.distance,
490
490
  translations.report.avgSpeed + ' (Km/h)',
@@ -543,8 +543,8 @@ function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportDa
543
543
 
544
544
  const footValues = ['Total:' + d.summary.length,
545
545
  (d.summary.reduce((a, b) => a + b.distance, 0) / 1000).toFixed(0),
546
- getSumAvgSpeed(d.summary),
547
- getSumMaxSpeed(d.summary),
546
+ getSumAvgSpeed(d.summary, userData),
547
+ getSumMaxSpeed(d.summary, userData),
548
548
  convertMS(d.summary.reduce((a, b) => a + b.engineHours, 0))]
549
549
 
550
550
  const style = getStyle(getUserPartner(userData.user))
@@ -552,7 +552,7 @@ function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportDa
552
552
  })
553
553
  }
554
554
 
555
- function exportActivityReportToExcel_Driver_GroupByDay(settings, translations, reportData) {
555
+ function exportActivityReportToExcel_Driver_GroupByDay(settings, translations, reportData, userData) {
556
556
  const headers = [{label: translations.report.driver, value: 'name'},
557
557
  {label: translations.report.group, value: 'group'},
558
558
  {label: translations.report.date, value: 'date'},
@@ -627,7 +627,7 @@ function exportActivityReportToExcel_Driver(settings, translations, reportData)
627
627
  }
628
628
  }
629
629
 
630
- function exportActivityReportToExcel_Vehicle(settings, translations, reportData) {
630
+ function exportActivityReportToExcel_Vehicle(settings, translations, reportData, userData) {
631
631
  const headers = [{label: translations.report.vehicle, value: 'name'},
632
632
  {label: translations.report.group, value: 'group'},
633
633
  {label: translations.report.distance, value: 'distance'},
@@ -664,9 +664,8 @@ function exportActivityReportToExcel_Vehicle(settings, translations, reportData)
664
664
  }
665
665
  }
666
666
 
667
- function exportActivityReportToExcel(reportUserData, reportData) {
667
+ function exportActivityReportToExcel(userData, reportData) {
668
668
  console.log('Export to Excel')
669
- userData = reportUserData
670
669
  const lang = userData.user.attributes.lang
671
670
  const translations = messages[lang] ? messages[lang] : messages['en-GB']
672
671
 
@@ -676,17 +675,17 @@ function exportActivityReportToExcel(reportUserData, reportData) {
676
675
  }
677
676
 
678
677
  if(userData.groupByDay && userData.byDriver){
679
- return exportActivityReportToExcel_Driver_GroupByDay(settings, translations, reportData)
678
+ return exportActivityReportToExcel_Driver_GroupByDay(settings, translations, reportData, userData)
680
679
  } else if(userData.groupByDay){
681
- return exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations, reportData)
680
+ return exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations, reportData, userData)
682
681
  } else if(userData.byDriver){
683
- return exportActivityReportToExcel_Driver(settings, translations, reportData)
682
+ return exportActivityReportToExcel_Driver(settings, translations, reportData, userData)
684
683
  } else {
685
- return exportActivityReportToExcel_Vehicle(settings, translations, reportData)
684
+ return exportActivityReportToExcel_Vehicle(settings, translations, reportData, userData)
686
685
  }
687
686
  }
688
687
 
689
- function getSumAvgSpeed(data){
688
+ function getSumAvgSpeed(data, userData){
690
689
  const values = data.map(item => {
691
690
  if(userData.groupByDay){
692
691
  return Math.round(item.averageSpeed * 1.85200)
@@ -697,7 +696,7 @@ function getSumAvgSpeed(data){
697
696
  return Math.round((values.reduce((a, b) => a + b, 0)) / values.length)
698
697
  }
699
698
 
700
- function getSumMaxSpeed(data){
699
+ function getSumMaxSpeed(data, userData){
701
700
  const values = data.map(item => {
702
701
  if(userData.groupByDay){
703
702
  return item.maxSpeed
@@ -711,7 +710,7 @@ function getSumMaxSpeed(data){
711
710
  return Math.round(max * 1.85200)
712
711
  }
713
712
 
714
- function getSumSpentFuel(data){
713
+ function getSumSpentFuel(data, userData){
715
714
  const values = data.map(item => {
716
715
  if(userData.groupByDay){
717
716
  return item.convertedSpentFuel >= 0 ? item.convertedSpentFuel : 0
@@ -46,7 +46,7 @@ async function createEventsReport(from, to, userData, traccar) {
46
46
 
47
47
  if(data.length > 0) {
48
48
  reportData.push({
49
- devices: await processDevices(from, to, withoutGroupDevices, userData.geofences, userData.drivers, data),
49
+ devices: await processDevices(from, to, withoutGroupDevices, userData.geofences, userData.drivers, data, traccar),
50
50
  xpert: withoutGroupDevices.filter(d => d.attributes.xpert).length > 0
51
51
  })
52
52
  }
@@ -71,7 +71,7 @@ async function getReportData(from, to, devices, types, traccar) {
71
71
  return data
72
72
  }
73
73
 
74
- async function processDevices(from, to, devices, geofences, drivers, data) {
74
+ async function processDevices(from, to, devices, geofences, drivers, data, traccar) {
75
75
  const devicesResult = []
76
76
 
77
77
  for (const d of devices) {
@@ -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, reportUserData, traccar) {
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.devices, 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, reportUserData, traccar) {
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.drivers, {trips: tripsData, route: routeData}) }
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, drivers, data) {
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) {
@@ -75,7 +75,7 @@ async function createSpeedingReportByDevice(from, to, devices, userData, traccar
75
75
  const routes = await traccarHelper.getRoute(traccarInstance, from, to, devices)
76
76
  const events = []
77
77
  if(!userData.useVehicleSpeedLimit && userData.customSpeed){
78
- events.push(...await getCustomSpeedLimitEvents(devices, routes))
78
+ events.push(...await getCustomSpeedLimitEvents(devices, routes, userData.customSpeed))
79
79
  } else {
80
80
  events.push(...await traccarHelper.getEvents(traccarInstance, from, to, devices, eventTypes))
81
81
  }
@@ -95,7 +95,7 @@ async function createSpeedingReportByDevice(from, to, devices, userData, traccar
95
95
  }
96
96
  }
97
97
 
98
- async function createSpeedingReportByDriver(from, to) {
98
+ async function createSpeedingReportByDriver(from, to, userData) {
99
99
  const devices = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
100
100
  console.log('Devices with driver',devices.length)
101
101
 
@@ -107,7 +107,7 @@ async function createSpeedingReportByDriver(from, to) {
107
107
  const routes = await traccarHelper.getRoute(traccarInstance, from, to, devices)
108
108
  const events = []
109
109
  if(!userData.useVehicleSpeedLimit && userData.customSpeed){
110
- events.push(...await getCustomSpeedLimitEvents(devices, routes))
110
+ events.push(...await getCustomSpeedLimitEvents(devices, routes, userData.customSpeed))
111
111
  } else {
112
112
  events.push(...await traccarHelper.getEvents(traccarInstance, from, to, devices, eventTypes))
113
113
  }
@@ -121,13 +121,13 @@ async function createSpeedingReportByDriver(from, to) {
121
121
  return { drivers: [] }
122
122
  }
123
123
 
124
- return {drivers: await processDrivers(from, to, events, routes)}
124
+ return {drivers: await processDrivers(from, to, events, routes, userData)}
125
125
  }
126
126
 
127
- async function processDrivers(from, to, events, routes) {
127
+ async function processDrivers(from, to, events, routes, userData) {
128
128
  const driversResult = []
129
129
 
130
- await findEventsPosition(from, to, userData.devices, events, routes)
130
+ await findEventsPosition(from, to, userData.devices, events, routes, userData)
131
131
 
132
132
  userData.drivers.forEach(d => {
133
133
  const driverEvents = events.filter(e => e.position && e.position.attributes.driverUniqueId === d.uniqueId)
@@ -148,9 +148,9 @@ async function processDrivers(from, to, events, routes) {
148
148
  return driversResult
149
149
  }
150
150
 
151
- async function processDevices(from, to, devices, events, routes) {
151
+ async function processDevices(from, to, devices, events, routes, userData) {
152
152
  const devicesResult = []
153
- await findEventsPosition(from, to, devices, events, routes)
153
+ await findEventsPosition(from, to, devices, events, routes, userData)
154
154
 
155
155
  for (const d of devices) {
156
156
  const deviceEvents = events.filter(e => e.deviceId === d.id && e.position)
@@ -171,7 +171,7 @@ async function processDevices(from, to, devices, events, routes) {
171
171
  return devicesResult
172
172
  }
173
173
 
174
- async function findEventsPosition(from, to, devices, events, routes){
174
+ async function findEventsPosition(from, to, devices, events, routes, userData){
175
175
  for (const d of devices) {
176
176
  let deviceEvents = events.filter(e => e.deviceId === d.id && e.positionId)
177
177
  if (deviceEvents.length > 0) {
@@ -190,7 +190,7 @@ async function findEventsPosition(from, to, devices, events, routes){
190
190
  }
191
191
 
192
192
  a.position = positions[pIndex]
193
- pIndex = calculateEventData(positions, pIndex, a, d, geofence)
193
+ pIndex = calculateEventData(positions, pIndex, a, d, geofence, userData)
194
194
  positions.slice(pIndex)
195
195
  }
196
196
  }
@@ -198,10 +198,10 @@ async function findEventsPosition(from, to, devices, events, routes){
198
198
  }
199
199
  }
200
200
 
201
- async function getCustomSpeedLimitEvents(devices, routes){
201
+ async function getCustomSpeedLimitEvents(devices, routes, customSpeed){
202
202
  console.log('custom speed limit events')
203
203
  const events = []
204
- const maxSpeed = userData.customSpeed / 1.85200
204
+ const maxSpeed = customSpeed / 1.85200
205
205
 
206
206
  for (const d of devices) {
207
207
  const positions = routes.filter(p => p.deviceId === d.id)
@@ -272,7 +272,7 @@ async function getHereEvents(devices, routes, threshold){
272
272
  return events
273
273
  }
274
274
 
275
- function calculateEventData(positions, pIndex, alert, device, geofence){
275
+ function calculateEventData(positions, pIndex, alert, device, geofence, userData){
276
276
  let endEventPosition = alert.position
277
277
  let maxSpeed = alert.position.speed
278
278
  let dist = 0
@@ -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 traccar = require("./util/traccar")
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, reportUserData, traccar) {
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 traccar.getTrips(traccarInstance, from, to, devicesToSlice)
55
- const stopsData = await traccar.getStops(traccarInstance, from, to, devicesToSlice)
56
- const routeData = await traccar.getRoute(traccarInstance, from, to, devicesToSlice)
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(traccarInstance, from, to, devices, {trips: tripsData, route: routeData})
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 traccarInstance.reports.reportsTripsGet(from, to, null, [g.id])
74
+ const response = await traccar.reports.reportsTripsGet(from, to, null, [g.id])
81
75
  const tripsData = response.data
82
76
 
83
- const stopsResponse = await traccarInstance.reports.reportsStopsGet(from, to, null, [g.id])
77
+ const stopsResponse = await traccar.reports.reportsStopsGet(from, to, null, [g.id])
84
78
  const stopsData = stopsResponse.data
85
79
 
86
- const routeResponse = await traccarInstance.reports.reportsRouteGet(from, to, null, [g.id])
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(traccarInstance, from, to, userData.drivers, userData.devices)
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 traccar.getTrips(traccarInstance, from, to, devices)
119
- const routeData = await traccar.getRoute(traccarInstance, from, to, devices)
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.drivers, {trips: tripsData, route: routeData})}
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, drivers, data) {
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)))
@@ -1,7 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <code_scheme name="Project" version="173">
3
- <ScalaCodeStyleSettings>
4
- <option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
5
- </ScalaCodeStyleSettings>
6
- </code_scheme>
7
- </component>
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
- </state>
5
- </component>
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="JavaScriptLibraryMappings">
4
- <file url="file://$PROJECT_DIR$" libraries="{Node.js Core}" />
5
- </component>
6
- </project>