fleetmap-reports 1.0.976 → 1.0.978

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.976",
3
+ "version": "1.0.978",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -366,13 +366,13 @@ async function invokeValhalla (route, i, chunk, country, threshold, results, ret
366
366
  console.log(e.message, 'retry:', retry)
367
367
  return invokeValhalla(route, i, chunk, country, threshold, results, retry)
368
368
  } else {
369
- console.error(e.message, e.response && e.response.data, slice[0])
369
+ console.error(e.message, e.response && e.response.data, 'deviceId', slice[0] && slice[0].deviceId, slice[0] && slice[0].address)
370
370
  }
371
371
  }
372
372
  }
373
373
 
374
374
  async function getOSMSpeedingEvents (devices, routes, threshold, minimumMinutes = 0, country) {
375
- const chunk = 1000
375
+ const chunk = 500
376
376
  const events = []
377
377
  for (const d of devices) {
378
378
  const route = routes.filter(r => r.deviceId === d.id)
@@ -139,7 +139,11 @@ async function createTripReportByDriver (from, to, userData, traccar) {
139
139
  d.totalDuration = d.trips.reduce((a, b) => a + b.duration, 0)
140
140
  d.totalDistance = d.trips.reduce((a, b) => a + b.distance, 0)
141
141
  d.maxSpeed = d.trips.reduce((a, b) => { return a > b.maxSpeed ? a : b.maxSpeed }, 0)
142
- d.trips.sort((a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime())
142
+ d.trips = d.trips.sort((a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime())
143
+
144
+ d.trips.forEach((trip, i) => {
145
+ trip.stopDuration = (i !== d.trips.length - 1 ? (new Date(d.trips[i + 1].startTime) - new Date(trip.endTime)) : (to - new Date(trip.endTime))) - trip.stopEngineHours
146
+ })
143
147
  })
144
148
 
145
149
  return report
@@ -274,8 +278,8 @@ async function processDrivers (from, to, userData, data) {
274
278
  filteredTrips.push(t)
275
279
  }
276
280
  }
277
- filteredTrips.sort((a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime())
278
- filteredTrips.forEach(function (trip, i) {
281
+
282
+ filteredTrips.forEach(trip => {
279
283
  trip.totalKms = trip.distance / 1000
280
284
 
281
285
  const nearestPOIs = getNearestPOIs(trip.endLon, trip.endLat, userData.geofences)
@@ -286,7 +290,6 @@ async function processDrivers (from, to, userData, data) {
286
290
  const stop = data.stops.find(s => s.deviceId === trip.deviceId && (new Date(s.startTime).getTime() === new Date(trip.endTime).getTime()))
287
291
 
288
292
  trip.stopEngineHours = getTripIdleTime(trip, idleEvents) + (stop ? stop.engineHours : 0)
289
- trip.stopDuration = (i !== trips.length - 1 ? (new Date(trips[i + 1].startTime) - new Date(trip.endTime)) : (to - new Date(trip.endTime))) - trip.stopEngineHours
290
293
  })
291
294
 
292
295
  if (filteredTrips.length > 0) {