fleetmap-reports 1.0.310 → 1.0.314

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.310",
3
+ "version": "1.0.314",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -301,8 +301,8 @@ function exportActivityReportToPDF_Driver(doc, translations, reportData, userDat
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))
@@ -345,10 +345,10 @@ function exportActivityReportToPDF_Vehicle(doc, translations, reportData, userDa
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)
@@ -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))
@@ -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) {
@@ -18,7 +18,7 @@ async function createIdleReport(from, to, userData, traccarInstance) {
18
18
  reportData.push(...allData)
19
19
  } else {
20
20
  console.log("ByDevice")
21
- const report = await createTripReportByDevice(from, to, userData, traccarInstance)
21
+ const report = await createTripReportByDevice(from, to, userData.devices, userData, traccarInstance)
22
22
  reportData.push(report)
23
23
  }
24
24
 
@@ -54,7 +54,7 @@ async function createSpeedingReportByGroup(from, to, userData, traccarInstance){
54
54
  devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
55
55
 
56
56
  if (events.length > 0) {
57
- groupData.devices = await processDevices(from, to, devices, events, routes)
57
+ groupData.devices = await processDevices(from, to, devices, events, routes, userData)
58
58
  reportData.push(groupData)
59
59
  }
60
60
  }
@@ -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
  }
@@ -90,12 +90,12 @@ async function createSpeedingReportByDevice(from, to, devices, userData, traccar
90
90
  }
91
91
 
92
92
  return {
93
- devices: await processDevices(from, to, devices, events, routes),
93
+ devices: await processDevices(from, to, devices, events, routes, userData),
94
94
  xpert: devices.filter(d => d && d.attributes && d.attributes.xpert).length > 0
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,35 +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
14
  const fileName = 'TripReport'
15
15
 
16
- async function createTripReport(from, to, userData, traccarInstance) {
16
+ async function createTripReport(from, to, userData, traccar) {
17
17
  console.log('Create TripReport')
18
18
  const reportData = []
19
19
 
20
20
  if (userData.byDriver) {
21
21
  console.log("ByDriver")
22
- const report = await createTripReportByDriver(from, to, userData, traccarInstance)
22
+ const report = await createTripReportByDriver(from, to, userData, traccar)
23
23
  reportData.push(report)
24
24
  }
25
25
  else if (userData.byGroup) {
26
26
  console.log("ByGroup")
27
- const allData = await createTripReportByGroup(from, to, userData, traccarInstance)
27
+ const allData = await createTripReportByGroup(from, to, userData, traccar)
28
28
  reportData.push(...allData)
29
29
  } else {
30
30
  console.log("ByDevice")
31
- const report = await createTripReportByDevice(from, to, userDatauserData, traccarInstance)
31
+ const report = await createTripReportByDevice(from, to, userData, traccar)
32
32
  reportData.push(report)
33
33
  }
34
34
 
35
35
  return reportData
36
36
  }
37
37
 
38
- async function createTripReportByDevice(from, to, userData, traccarInstance) {
38
+ async function createTripReportByDevice(from, to, userData, traccar) {
39
39
  const devices = userData.devices
40
40
  const allData = {
41
41
  devices: [],
@@ -45,21 +45,21 @@ async function createTripReportByDevice(from, to, userData, traccarInstance) {
45
45
  devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
46
46
 
47
47
  const devicesToSlice = devices.slice()
48
- const tripsData = await traccar.getTrips(traccarInstance, from, to, devicesToSlice)
49
- const stopsData = await traccar.getStops(traccarInstance, from, to, devicesToSlice)
50
- 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)
51
51
 
52
52
  console.log('Trips:' + tripsData.length)
53
53
 
54
54
  if (tripsData.length > 0) {
55
- trips.checkTripsKms(traccarInstance, from, to, devices, {trips: tripsData, route: routeData})
55
+ trips.checkTripsKms(traccar, from, to, devices, {trips: tripsData, route: routeData})
56
56
  allData.devices = processDevices(from, to, devices, {trips: tripsData, stops: stopsData, route: routeData}, userData)
57
57
  }
58
58
 
59
59
  return allData
60
60
  }
61
61
 
62
- async function createTripReportByGroup(from, to, userData, traccarInstance) {
62
+ async function createTripReportByGroup(from, to, userData, traccar) {
63
63
  const reportData = []
64
64
  for (const g of userData.groups) {
65
65
  const devices = userData.devices.filter(d => d.groupId === g.id)
@@ -71,13 +71,13 @@ async function createTripReportByGroup(from, to, userData, traccarInstance) {
71
71
  xpert: devices.filter(d => d.attributes.xpert).length > 0
72
72
  }
73
73
 
74
- const response = await traccarInstance.reports.reportsTripsGet(from, to, null, [g.id])
74
+ const response = await traccar.reports.reportsTripsGet(from, to, null, [g.id])
75
75
  const tripsData = response.data
76
76
 
77
- const stopsResponse = await traccarInstance.reports.reportsStopsGet(from, to, null, [g.id])
77
+ const stopsResponse = await traccar.reports.reportsStopsGet(from, to, null, [g.id])
78
78
  const stopsData = stopsResponse.data
79
79
 
80
- const routeResponse = await traccarInstance.reports.reportsRouteGet(from, to, null, [g.id])
80
+ const routeResponse = await traccar.reports.reportsRouteGet(from, to, null, [g.id])
81
81
  const routeData = routeResponse.data
82
82
 
83
83
  devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
@@ -100,8 +100,8 @@ async function createTripReportByGroup(from, to, userData, traccarInstance) {
100
100
  return reportData
101
101
  }
102
102
 
103
- async function createTripReportByDriver(from, to, userData, traccarInstance){
104
- 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)
105
105
  console.log(devices.length)
106
106
 
107
107
  if(!devices.length){
@@ -109,8 +109,8 @@ async function createTripReportByDriver(from, to, userData, traccarInstance){
109
109
  return { drivers:[] }
110
110
  }
111
111
 
112
- const tripsData = await traccar.getTrips(traccarInstance, from, to, devices)
113
- 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)
114
114
 
115
115
  return { drivers: processDrivers(from, to, userData, {trips: tripsData, route: routeData})}
116
116
  }