fleetmap-reports 2.0.139 → 2.0.142

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": "2.0.139",
3
+ "version": "2.0.142",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -7,11 +7,11 @@ const jsPDF = require('jspdf')
7
7
  const { headerFromUser, addTable } = require('../util/pdfDocument')
8
8
  const { getStyle } = require('../reportStyle')
9
9
  const { getUserPartner } = require('fleetmap-partners')
10
- const { getRoadSpeedLimits } = require('../speeding-report')
10
+ const { getOverspeedEvents } = require('../speeding-report')
11
11
  const { calculateConsumption } = require('../util/fuel')
12
12
  const { getCanAvgConsumption } = require('../fuel-consumption-report')
13
13
 
14
- const distanceTarget = 10000 // meters
14
+ const distanceTarget = 10000000 // meters
15
15
  const distanceCoefficient = 0.5
16
16
 
17
17
  const consumptionTarget = 11.5 // minutes
@@ -49,25 +49,30 @@ async function create (from, to, userData, traccar) {
49
49
 
50
50
  const drivers = userData.drivers
51
51
  const devices = userData.devices
52
+ userData.geofences = []
53
+ userData.roadSpeedLimits = true
52
54
 
53
55
  let deviceCount = 0
54
56
  const driversData = new Map()
57
+ const overspeedEvents = await getOverspeedEvents(from, to, userData, devices, userData, traccar)
58
+
55
59
  for (const device of devices) {
56
60
  const allInOne = await traccarHelper.getAllInOne(traccar, from, to, [device], true, true, false, false, deviceCount, devices.length)
57
- const hereResults = await getRoadSpeedLimits([device], allInOne.route, 5)
58
-
59
- // getEvents
60
- const geofenceAlarm = 0
61
- const continuesDrivingAlarm = 0
62
- const reverseAlarm = 0
63
- const otherAlarm = 0
61
+ const deviceOverspeedEvents = overspeedEvents.find(e => e.device.id === device.id)
62
+ const { data } = await traccar.reports.reportsEventsGet(from, to, [device.id], null, ['alarm'])
64
63
 
65
64
  for (const d of drivers) {
66
65
  const { trips, route } = await getDriverData(d, allInOne, userData)
67
- const positionIds = route.map(p => p.id)
68
- const driverOverSpeedEvents = hereResults.filter(e => positionIds.includes(e.positionId))
66
+ const positionsIds = route.map(p => p.id)
67
+ const events = data.filter(e => positionsIds.includes(e.positionId))
68
+ const driverOverSpeedEvents = deviceOverspeedEvents ? deviceOverspeedEvents.alerts.filter(e => positionsIds.includes(e.position.id)) : []
69
69
  const spentFuel = calculateConsumption(device, { trips, route })
70
70
 
71
+ const geofenceAlarm = events.filter(e => e.attributes.alarm === 'la ceinture').length
72
+ const continuesDrivingAlarm = events.filter(e => e.attributes.alarm === 'Conduite continue').length
73
+ const reverseAlarm = events.filter(e => e.attributes.alarm === 'MARCHE ARIERRE').length
74
+ const otherAlarm = events.length - (geofenceAlarm + continuesDrivingAlarm + reverseAlarm)
75
+
71
76
  let driverData = driversData.get(d.id)
72
77
  if (!driverData) {
73
78
  driverData = {
@@ -79,20 +79,13 @@ function processServerSide () {
79
79
  return (process.env.PROCESS_HERE_EVENTS && process.env.PROCESS_HERE_EVENTS === 'server')
80
80
  }
81
81
 
82
- async function createSpeedingReportByDevice (from, to, userData, traccarInstance) {
83
- const devices = devicesToProcess(userData)
84
-
85
- const allData = {
86
- devices: [],
87
- xpert: devices.filter(d => d && d.attributes && d.attributes.xpert).length > 0
88
- }
89
-
82
+ async function getOverspeedEvents (from, to, userData, devices, allData, traccarInstance) {
90
83
  const _sliced = automaticReports.sliceArray(automaticReports.sliceArray(devices, 5), 5)
91
-
92
84
  let deviceCount = 0
85
+ const overspeedEvents = []
93
86
  for (const sliced of _sliced) {
94
87
  await Promise.all(sliced.map(async slice => {
95
- allData.devices = allData.devices.concat(await getEvents(traccarInstance, from, to, slice, userData, deviceCount, devices.length, slice.length))
88
+ overspeedEvents.push(...await getEvents(traccarInstance, from, to, slice, userData, deviceCount, devices.length, slice.length))
96
89
  deviceCount = deviceCount + slice.length
97
90
  if (processServerSide()) {
98
91
  console.log('LOADING_MESSAGE:' + slice[0].name)
@@ -100,6 +93,18 @@ async function createSpeedingReportByDevice (from, to, userData, traccarInstance
100
93
  }
101
94
  }))
102
95
  }
96
+ return overspeedEvents
97
+ }
98
+
99
+ async function createSpeedingReportByDevice (from, to, userData, traccarInstance) {
100
+ const devices = devicesToProcess(userData)
101
+
102
+ const allData = {
103
+ devices: [],
104
+ xpert: devices.filter(d => d && d.attributes && d.attributes.xpert).length > 0
105
+ }
106
+
107
+ allData.devices = await getOverspeedEvents(from, to, userData, devices, allData, traccarInstance)
103
108
 
104
109
  return allData
105
110
  }
@@ -351,7 +356,7 @@ async function invokeValhalla (route, i, chunk, country, threshold, results, ret
351
356
  lon: p.longitude,
352
357
  lat: p.latitude
353
358
  }))
354
- }, { timeout: 10000 })
359
+ }, { timeout: 50000 })
355
360
  .then(r => r.data)
356
361
  countSuccess++
357
362
  lastSuccessDuration = new Date() - now
@@ -703,4 +708,4 @@ exports.exportSpeedingReportToExcel = exportSpeedingReportToExcel
703
708
  exports.create = createSpeedingReport
704
709
  exports.exportToPDF = exportSpeedingReportToPDF
705
710
  exports.exportToExcel = exportSpeedingReportToExcel
706
- exports.getEvents = getEvents
711
+ exports.getOverspeedEvents = getOverspeedEvents
package/src/util/utils.js CHANGED
@@ -320,7 +320,7 @@ exports.convertFromUTCDate = (value, user) => {
320
320
  return convertFromUTC(value, user.attributes.timezone || getUserPartner(user).timezone)
321
321
  }
322
322
 
323
- exports.getCountry = position => position && position.attributes.address && position.attributes.address.split(',').slice(-1)[0].trim()
323
+ exports.getCountry = position => position && position.address && position.address.split(',').slice(-1)[0].trim()
324
324
 
325
325
  exports.processServerSide = (userData) => {
326
326
  const devices = devicesToProcess(userData)