fleetmap-reports 1.0.614 → 1.0.615

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.614",
3
+ "version": "1.0.615",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -135,10 +135,6 @@ async function createTripReportByDriver (from, to, userData, traccar) {
135
135
  d.totalDuration = d.trips.reduce((a, b) => a + b.duration, 0)
136
136
  d.totalDistance = d.trips.reduce((a, b) => a + b.distance, 0)
137
137
  d.maxSpeed = d.trips.reduce((a, b) => { return a > b.maxSpeed ? a : b.maxSpeed }, 0)
138
- d.trips = d.trips.sort((a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime())
139
- d.trips.forEach(function (trip, i) {
140
- trip.stopDuration = i !== d.trips.length - 1 ? (new Date(d.trips[i + 1].startTime) - new Date(trip.endTime)) : 0
141
- })
142
138
  })
143
139
 
144
140
  return report
@@ -220,9 +216,11 @@ function processDrivers (from, to, userData, data) {
220
216
  const driversResult = []
221
217
  userData.drivers.forEach(d => {
222
218
  const route = data.route.filter(p => p.attributes.driverUniqueId === d.uniqueId)
223
- const trips = data.trips.filter(t => t.driverUniqueId === d.uniqueId &&
219
+ let trips = data.trips.filter(t => t.driverUniqueId === d.uniqueId &&
224
220
  (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
225
221
 
222
+ trips = trips.sort((a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime())
223
+
226
224
  const idleEvents = getIdleEvents(data.route, d)
227
225
 
228
226
  trips.forEach(function (trip, i) {
@@ -233,8 +231,10 @@ function processDrivers (from, to, userData, data) {
233
231
  trip.endPOIName = nearestPOIs[0].p.name
234
232
  }
235
233
 
236
- trip.stopEngineHours = getTripIdleTime(trip, idleEvents)
237
- trip.stopDuration = i !== trips.length - 1 ? (new Date(trips[i + 1].startTime) - new Date(trip.endTime)) : 0
234
+ const stop = data.stops.find(s => s.deviceId === trip.deviceId && (new Date(s.startTime).getTime() === new Date(trip.endTime).getTime()))
235
+
236
+ trip.stopEngineHours = getTripIdleTime(trip, idleEvents) + (stop ? stop.engineHours : 0)
237
+ trip.stopDuration = (i !== trips.length - 1 ? (new Date(trips[i + 1].startTime) - new Date(trip.endTime)) : (to - new Date(trip.endTime))) - trip.stopEngineHours
238
238
  })
239
239
 
240
240
  if (trips.length > 0) {
@@ -25,11 +25,9 @@ async function reportByDriver (devices, traccar, from, to, userData, processor)
25
25
 
26
26
  let deviceCount = 0
27
27
  for (const slice of sliced) {
28
- const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, false, false, deviceCount, devices.length)
29
- const tripsData = allInOne.trips
30
- const routeData = allInOne.route
28
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, true, false, deviceCount, devices.length)
31
29
 
32
- const results = processor(from, to, userData, { trips: tripsData, route: routeData })
30
+ const results = processor(from, to, userData, { trips: allInOne.trips, route: allInOne.route, stops: allInOne.stops })
33
31
 
34
32
  report.drivers.push(...results)
35
33