fleetmap-reports 1.0.277 → 1.0.282

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.277",
3
+ "version": "1.0.282",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/here.js CHANGED
@@ -97,10 +97,10 @@ function fillGeocoding(rows) {
97
97
  }*/
98
98
 
99
99
  exports.routeMatch = async (rows) => {
100
+ console.log('here sending', rows.length)
100
101
  const csv = generateCSV(rows)
101
102
  const response = await axios.post(calcRoute, csv, { headers: { 'Content-Type': 'application/binary' }})
102
103
  const hereData = response.data
103
- console.dir(hereData, {depth: null})
104
104
  const route = hereData.response.route[0]
105
105
  const results = []
106
106
  const wayPoints = route.waypoint
@@ -237,10 +237,17 @@ async function getCustomSpeedLimitEvents(devices, routes){
237
237
  async function getHereEvents(devices, routes, threshold){
238
238
  console.log('here speed limit events')
239
239
  const events = []
240
+ let i,j, temporary, chunk = 10;
241
+ for (i = 0,j = devices.length; i < j; i += chunk) {
242
+ temporary = devices.slice(i, i + chunk);
243
+ await Promise.all(temporary.map(d =>
244
+ here.routeMatch(routes.filter(p => p.deviceId === d.id)).then(r => d.results = r)
245
+ ))
246
+ }
247
+
240
248
  for (const d of devices) {
241
- const positions = routes.filter(p => p.deviceId === d.id)
242
249
  try {
243
- const results = await here.routeMatch(positions)
250
+ const results = d.results
244
251
  const hereAlerts = results.filter(r => r.currentSpeedKmh > (parseInt(r.speedLimit) + threshold)).map(r => {
245
252
  const position = positions.find(p => new Date(p.fixTime).getTime() === r.timestamp)
246
253
  return {
@@ -263,7 +270,7 @@ async function getHereEvents(devices, routes, threshold){
263
270
  })
264
271
  events.push(...reduced)
265
272
  } catch (e) {
266
- //console.error(e)
273
+ console.error(e)
267
274
  }
268
275
  }
269
276
  return events