fleetmap-reports 1.0.398 → 1.0.401

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.401",
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
 
package/src/index.test.js CHANGED
@@ -48,6 +48,8 @@ describe('Test_Reports', function () {
48
48
  assert.equal(data.length, 1)
49
49
  const device = data[0].devices.find(d => d.device.id === 22326)
50
50
  assert.equal(device.trips.length, 7) // Total Trips
51
+ assert.equal(device.trips[0].endPOIName, 'Casa João')
52
+ assert.equal(device.trips[1].endPOIName, undefined)
51
53
  assert.equal(device.totalDistance, 339204.53999999166) // Total Kms
52
54
  }, 20000)
53
55
  // eslint-disable-next-line no-undef
@@ -271,7 +273,7 @@ describe('Test_Reports', function () {
271
273
  assert.equal(tripsReport.length, 1)
272
274
  const device1 = tripsReport[0].devices.find(d => d.device.id === 11681)
273
275
  assert.equal(device1.trips.length, 44) // Total Trips
274
- assert.equal(device1.totalDistance, 882.801081530881) // Total Kms
276
+ assert.equal(device1.totalDistance, 882801.0815308811) // Total Kms
275
277
 
276
278
  const device2 = kmsReport[0].devices.find(d => d.device.id === 11681)
277
279
  assert.equal(device2.summary.distance, device1.totalDistance) // Total Kms
@@ -12,7 +12,7 @@ const traccarHelper = require('./util/traccar')
12
12
  const { devicesToProcess } = require('./util/device')
13
13
  const turf = require('@turf/distance')
14
14
  const { point } = require('@turf/helpers')
15
- const distance = require('@turf/distance');
15
+ const distance = require('@turf/distance')
16
16
 
17
17
  const fileName = 'SpeedingReport'
18
18
  const eventTypes = ['deviceOverspeed']
@@ -73,14 +73,15 @@ async function createSpeedingReportByDevice (from, to, userData, traccarInstance
73
73
  const allInOne = await traccarHelper.getAllInOne(traccarInstance, from, to, devices, true, false, false, false)
74
74
  const routes = allInOne.route
75
75
  const events = []
76
- if (!userData.useVehicleSpeedLimit && userData.customSpeed) {
77
- events.push(...await getCustomSpeedLimitEvents(devices, routes, userData.customSpeed))
78
- } else {
79
- events.push(...await traccarHelper.getEvents(traccarInstance, from, to, devices, eventTypes))
80
- }
81
76
 
82
77
  if (userData.roadSpeedLimits) {
83
78
  events.push(...await getHereEvents(devices, routes, userData.maxSpeedThreshold))
79
+ } else {
80
+ if (!userData.useVehicleSpeedLimit && userData.customSpeed) {
81
+ events.push(...await getCustomSpeedLimitEvents(devices, routes, userData.customSpeed))
82
+ } else {
83
+ events.push(...await traccarHelper.getEvents(traccarInstance, from, to, devices, eventTypes))
84
+ }
84
85
  }
85
86
 
86
87
  if (!events.length) {
package/src/util/utils.js CHANGED
@@ -32,7 +32,7 @@ function coordsDistance (lon1, lat1, lon2, lat2) {
32
32
  const from = turf.point([lon1, lat1])
33
33
  const to = turf.point([lon2, lat2])
34
34
 
35
- return distance.default(from, to, 'meters')
35
+ return distance.default(from, to, {units: 'meters'})
36
36
  }
37
37
 
38
38
  function convertPositionToFeature (position) {
@@ -175,7 +175,7 @@ function getInAndOutEvents(devices, route, userData) {
175
175
  }
176
176
  }
177
177
  if(g.geometry.type === 'Point') {
178
- if (distance(p, g, 'meters') < g.properties.distance) {
178
+ if (distance(p, g, {units: 'meters'}) < g.properties.distance) {
179
179
  if (!entryMap.includes(g)) {
180
180
  events.push(createEvent('geofenceEnter',d.id,p,g))
181
181
  entryMap.push(g)