fleetmap-reports 1.0.398 → 1.0.399

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.398",
3
+ "version": "1.0.399",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -197,15 +197,33 @@ function processDevices(from, to, devices, data, userData) {
197
197
  }
198
198
  }
199
199
  } else {
200
- summary.push(...data.summaries.filter(s => s.deviceId === d.id))
201
-
202
- if (summary.length) {
203
- summary.forEach(s => {
204
- s.distance = deviceTrips.reduce((a, b) => a + b.distance, 0)
205
- s.convertedSpentFuel = automaticReports.calculateSpentFuel(s.spentFuel, d)
206
- s.startTime = deviceTrips.length && deviceTrips[0].startTime
207
- s.endTime = deviceTrips.length && deviceTrips[deviceTrips.length-1].endTime
200
+ if(!userData.allWeek && userData.weekDays && userData.dayHours) {
201
+ const trips = deviceTrips.filter(t => userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
202
+ const distance = trips.reduce((a, b) => a + b.distance, 0)
203
+ summary.push({
204
+ deviceId: d.id,
205
+ averageSpeed: distance > 0 ? ((trips.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / distance) : 0,
206
+ distance: distance,
207
+ engineHours: trips.reduce((a, b) => a + b.duration, 0),
208
+ maxSpeed: trips.reduce((a, b) => {
209
+ return a > b.maxSpeed ? a : b.maxSpeed
210
+ }, 0),
211
+ startOdometer: trips.length ? trips[0].startOdometer : 0,
212
+ endOdometer: trips.length ? trips[trips.length - 1].endOdometer : 0,
213
+ startTime: trips.length && trips[0].startTime,
214
+ endTime: trips.length && trips[trips.length - 1].endTime
208
215
  })
216
+ } else {
217
+ summary.push(...data.summaries.filter(s => s.deviceId === d.id))
218
+
219
+ if (summary.length) {
220
+ summary.forEach(s => {
221
+ s.distance = deviceTrips.reduce((a, b) => a + b.distance, 0)
222
+ s.convertedSpentFuel = automaticReports.calculateSpentFuel(s.spentFuel, d)
223
+ s.startTime = deviceTrips.length && deviceTrips[0].startTime
224
+ s.endTime = deviceTrips.length && deviceTrips[deviceTrips.length - 1].endTime
225
+ })
226
+ }
209
227
  }
210
228
  }
211
229