fleetmap-reports 1.0.486 → 1.0.488

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.486",
3
+ "version": "1.0.488",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -111,30 +111,35 @@ async function createSpeedingReportByDriver (from, to, userData, traccarInstance
111
111
  }
112
112
 
113
113
  async function getEvents (traccarInstance, from, to, devices, userData, deviceCount, totalDevices, sliceSize) {
114
- const geofencesFeatures = userData.geofences.filter(g => g.area.startsWith('POLYGON') &&
114
+ if (process.env.PROCESS_HERE_EVENTS && process.env.PROCESS_HERE_EVENTS === 'server') {
115
+ const url = `${process.env.REPORTS_SERVER}/reports/speeding-report/getEvents`
116
+ return axios.post(url, { from, to, devices, userData, deviceCount, totalDevices, sliceSize }, { withCredentials: true }).then(d => d.data)
117
+ } else {
118
+ const geofencesFeatures = userData.geofences.filter(g => g.area.startsWith('POLYGON') &&
115
119
  g.attributes.speedLimit).map(g => convertToFeature(g))
116
120
 
117
- const allInOne = await traccarHelper.getAllInOne(traccarInstance, from, to, devices, true, false,
118
- false, false, deviceCount, totalDevices, sliceSize)
119
- const routes = allInOne.route
120
-
121
- const events = []
122
- if (userData.roadSpeedLimits) {
123
- const hereResults = await getHereEvents(devices, routes, userData.maxSpeedThreshold)
124
- console.log('got', hereResults.length, 'from here')
125
- events.push(...hereResults)
126
- } else if (!userData.useVehicleSpeedLimit && userData.customSpeed) {
127
- events.push(...await getCustomSpeedLimitEvents(devices, routes, userData.customSpeed))
128
- } else {
129
- const traccarEvents = await traccarHelper.getEvents(traccarInstance, from, to, devices, eventTypes)
130
- if (geofencesFeatures.length) {
131
- events.push(...getGeofenceSpeedLimitEvents(geofencesFeatures, routes, devices))
132
- events.push(...traccarEvents.filter(e => !(e.geofenceId)))
121
+ const allInOne = await traccarHelper.getAllInOne(traccarInstance, from, to, devices, true, false,
122
+ false, false, deviceCount, totalDevices, sliceSize)
123
+ const routes = allInOne.route
124
+
125
+ const events = []
126
+ if (userData.roadSpeedLimits) {
127
+ const hereResults = await getHereEvents(devices, routes, userData.maxSpeedThreshold)
128
+ console.log('got', hereResults.length, 'from here')
129
+ events.push(...hereResults)
130
+ } else if (!userData.useVehicleSpeedLimit && userData.customSpeed) {
131
+ events.push(...await getCustomSpeedLimitEvents(devices, routes, userData.customSpeed))
133
132
  } else {
134
- events.push(...traccarEvents)
133
+ const traccarEvents = await traccarHelper.getEvents(traccarInstance, from, to, devices, eventTypes)
134
+ if (geofencesFeatures.length) {
135
+ events.push(...getGeofenceSpeedLimitEvents(geofencesFeatures, routes, devices))
136
+ events.push(...traccarEvents.filter(e => !(e.geofenceId)))
137
+ } else {
138
+ events.push(...traccarEvents)
139
+ }
135
140
  }
141
+ return { routes, events }
136
142
  }
137
- return { routes, events }
138
143
  }
139
144
 
140
145
  function getGeofenceSpeedLimitEvents (geofencesFeatures, routes, devices) {
@@ -557,3 +562,4 @@ function getMaxSpeed (data) {
557
562
  exports.createSpeedingReport = createSpeedingReport
558
563
  exports.exportSpeedingReportToPDF = exportSpeedingReportToPDF
559
564
  exports.exportSpeedingReportToExcel = exportSpeedingReportToExcel
565
+ exports.getEvents = getEvents