fleetmap-reports 1.0.447 → 1.0.451

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/lang/enGB.js CHANGED
@@ -161,6 +161,10 @@ module.exports = {
161
161
  delete_geofence: 'Delete'
162
162
  },
163
163
  report: {
164
+ closed: 'Door Closed',
165
+ opened: 'Door Opened',
166
+ sun: 'Sun',
167
+ rain: 'Rain',
164
168
  temperature: 'Temperatura',
165
169
  select_vehicles: 'Select vehicles',
166
170
  select_vehicles_placeholder: 'Vehicles',
package/lang/ptBR.js CHANGED
@@ -153,6 +153,12 @@ module.exports = {
153
153
  delete_geofence: 'Apagar'
154
154
  },
155
155
  report: {
156
+ closed: 'Porta fechada',
157
+ opened: 'Porta aberta',
158
+ sun: 'Sol',
159
+ rain: 'Chuva',
160
+ digital_ports1: 'Portas Digitais 1',
161
+ digital_ports2: 'Portas Digitais 2',
156
162
  temperature: 'Temperatura',
157
163
  select_vehicles: 'Seleccionar veículos',
158
164
  select_vehicles_placeholder: 'Veículos',
package/lang/ptPT.js CHANGED
@@ -157,6 +157,12 @@ module.exports = {
157
157
  delete_geofence: 'Apagar'
158
158
  },
159
159
  report: {
160
+ closed: 'Porta fechada',
161
+ opened: 'Porta aberta',
162
+ sun: 'Sol',
163
+ rain: 'Chuva',
164
+ digital_ports1: 'Portas Digitais 1',
165
+ digital_ports2: 'Portas Digitais 2',
160
166
  temperature: 'Temperatura',
161
167
  select_vehicles: 'Seleccionar veículos',
162
168
  select_vehicles_placeholder: 'Veículos',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.447",
3
+ "version": "1.0.451",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.test.js CHANGED
@@ -19,6 +19,7 @@ describe('Test_Reports', function () {
19
19
  it('Speeding by device', async () => {
20
20
  const report = await getReports()
21
21
  const userData = await report.getUserData()
22
+ userData.roadSpeedLimit = true
22
23
  const { device, totalDistance, totalEventTime } = await getSpeedingReport(report, userData)
23
24
  assert.equal(device.alerts.length, 15) // Total Alerts
24
25
  assert.equal(totalDistance, 19.59984677533689) // Total Kms
@@ -49,8 +50,9 @@ describe('Test_Reports', function () {
49
50
  const device = data[0].devices.find(d => d.device.id === 22326)
50
51
  assert.equal(device.trips.length, 7) // Total Trips
51
52
  assert.equal(device.trips[0].endPOIName, 'Casa João')
53
+ assert.equal(device.trips[0].idleTime, 602000)
52
54
  assert.equal(device.trips[1].endPOIName, undefined)
53
- assert.equal(device.totalDistance, 339204.53999999166) // Total Kms
55
+ assert.equal(device.totalDistance, 339170.3099999875) // Total Kms
54
56
  }, 20000)
55
57
  // eslint-disable-next-line no-undef
56
58
  it('Trip by driver', async () => {
@@ -63,10 +65,10 @@ describe('Test_Reports', function () {
63
65
  assert.equal(data.length, 1)
64
66
  console.log(data[0].drivers)
65
67
  const driver = data[0].drivers.find(d => d.driver.id === 14020)
66
- assert.equal(driver.trips.length, 9) // Total Trips
67
- assert.equal(driver.totalDuration, 6274000)
68
- assert.equal(driver.maxSpeed, 70.1944)
69
- }, 20000)
68
+ assert.equal(driver.trips.length, 13) // Total Trips
69
+ assert.equal(driver.totalDuration, 8159000)
70
+ assert.equal(driver.maxSpeed, 78.8337)
71
+ }, 90000)
70
72
  // eslint-disable-next-line no-undef
71
73
  it('Trip without addresses', async () => {
72
74
  const report = await getReports()
@@ -197,7 +199,7 @@ describe('Test_Reports', function () {
197
199
  assert.equal(data.length, 1)
198
200
  assert.equal(data.length, 1)
199
201
  const device = data[0].devices.find(d => d.device.id === 22326)
200
- assert.equal(device.summary.distance, 1193284.3100000024) // Total Kms
202
+ assert.equal(device.summary.distance, 1183904.0299999565) // Total Kms
201
203
  }, 30000)
202
204
  // eslint-disable-next-line no-undef
203
205
  it('KmsReport byDevice groupByDay', async () => {
@@ -211,7 +213,7 @@ describe('Test_Reports', function () {
211
213
  assert.equal(data.length, 1)
212
214
  const device = data[0].devices.find(d => d.device.id === 22326)
213
215
  assert.equal(device.days.length, 10) // Total Kms
214
- assert.equal(device.days[5].kms, 23183.010000005364) // Total Kms
216
+ assert.equal(device.days[5].kms, 23124.280000001192) // Total Kms
215
217
  }, 30000)
216
218
  // eslint-disable-next-line no-undef
217
219
  it('Idle by device', async () => {
@@ -224,23 +226,26 @@ describe('Test_Reports', function () {
224
226
  assert.equal(data.length, 1)
225
227
  const device = data[0].devices.find(d => d.device.id === 22326)
226
228
  const totalIdleTime = device.idleEvents.reduce((a, b) => a + b.idleTime, 0)
227
- assert.equal(device.idleEvents.length, 8) // Total Alerts
228
- assert.equal(totalIdleTime, 1294000) // Total Duration
229
+ assert.equal(device.idleEvents.length, 9) // Total Alerts
230
+ assert.equal(totalIdleTime, 1592000) // Total Duration
229
231
  }, 20000)
230
232
  // eslint-disable-next-line no-undef
231
233
  it('Idle by driver', async () => {
232
234
  const report = await getReports()
233
235
  const userData = await report.getUserData()
234
- userData.minimumIdleMinutes = 2
236
+ userData.minimumIdleMinutes = 0
235
237
  userData.byDriver = true
238
+
239
+ console.log(userData.drivers)
236
240
  const data = await report.idleReport(new Date(2022, 0, 3, 0, 0, 0, 0),
237
241
  new Date(2022, 0, 7, 23, 59, 59, 0),
238
242
  userData)
239
243
  assert.equal(data.length, 1)
240
244
  const driver = data[0].drivers.find(d => d.driver.id === 14020)
245
+
241
246
  const totalIdleTime = driver.idleEvents.reduce((a, b) => a + b.idleTime, 0)
242
- assert.equal(driver.idleEvents.length, 1) // Total Alerts
243
- assert.equal(totalIdleTime, 8267000) // Total Duration
247
+ assert.equal(driver.idleEvents.length, 15) // Total Alerts
248
+ assert.equal(totalIdleTime, 16000) // Total Duration
244
249
  }, 20000)
245
250
  // eslint-disable-next-line no-undef
246
251
  it('Activity by device', async () => {
@@ -253,7 +258,7 @@ describe('Test_Reports', function () {
253
258
  assert.equal(data.length, 1)
254
259
  const device = data[0].devices.find(d => d.device.id === 22326)
255
260
  assert.equal(device.summary[0].startOdometer, 122502742.59)
256
- assert.equal(device.summary[0].distance, 1423529.600000009)
261
+ assert.equal(device.summary[0].distance, 1404204.4299999028)
257
262
  assert.equal(device.summary[0].startTime, '2022-01-01T13:35:47.000+0000')
258
263
  assert.equal(device.summary[0].endTime, '2022-01-31T17:36:27.000+0000')
259
264
  }, 40000)
@@ -281,8 +286,8 @@ describe('Test_Reports', function () {
281
286
  assert.equal(data.length, 1)
282
287
  const device = data[0].devices.find(d => d.device.id === 22326)
283
288
  assert.equal(device.summary[5].startOdometer, 122923290.95)
284
- assert.equal(device.summary[5].distance, 77020.37999999523)
285
- assert.equal(device.summary[5].startTime, '2022-01-06T18:35:04.000+0000')
289
+ assert.equal(device.summary[5].distance, 77021.6400000006)
290
+ assert.equal(device.summary[5].startTime, '2022-01-06T18:35:36.000+0000')
286
291
  assert.equal(device.summary[5].endTime, '2022-01-06T19:54:27.000+0000')
287
292
  }, 90000)
288
293
  // eslint-disable-next-line no-undef
@@ -318,11 +323,11 @@ describe('Test_Reports', function () {
318
323
  userData)
319
324
 
320
325
  assert.equal(tripsReport.length, 1)
321
- const device1 = tripsReport[0].devices.find(d => d.device.id === 11681)
322
- assert.equal(device1.trips.length, 44) // Total Trips
323
- assert.equal(device1.totalDistance, 882801.0815308811) // Total Kms
326
+ const device1 = tripsReport[0].devices.find(d => d.device.id === 22327)
327
+ assert.equal(device1.trips.length, 14) // Total Trips
328
+ assert.equal(device1.totalDistance, 83553.13999999687) // Total Kms
324
329
 
325
- const device2 = kmsReport[0].devices.find(d => d.device.id === 11681)
330
+ const device2 = kmsReport[0].devices.find(d => d.device.id === 22327)
326
331
  assert.equal(device2.summary.distance, device1.totalDistance) // Total Kms
327
332
  }, 30000)
328
333
  // eslint-disable-next-line no-undef
@@ -169,19 +169,26 @@ async function exportLocationReportToPDF (userData, reportData) {
169
169
  translations.report.address,
170
170
  translations.report.speed,
171
171
  translations.report.ignition,
172
- translations.report.vehicle,
173
- translations.report.temperature
172
+ translations.report.vehicle
174
173
  ]
175
174
  : [
176
175
  translations.report.date,
177
176
  translations.report.address,
178
177
  translations.report.speed,
179
178
  translations.report.ignition,
180
- translations.report.driver,
181
- translations.report.temperature
179
+ translations.report.driver
182
180
  ]
183
181
 
182
+ if (userData.includeTemperature) {
183
+ headers.push(translations.report.temperature)
184
+ }
185
+
184
186
  if (positionsData) {
187
+ if (userData.includeDigitalPorts) {
188
+ headers.push(getDigitalPort1Label(userData.byDriver ? positionsData[0].driver : positionsData[0].device, translations))
189
+ headers.push(getDigitalPort2Label(userData.byDriver ? positionsData[0].driver : positionsData[0].device, translations))
190
+ }
191
+
185
192
  let first = true
186
193
  // eslint-disable-next-line new-cap
187
194
  const doc = new jsPDF.jsPDF('l')
@@ -210,9 +217,18 @@ async function exportLocationReportToPDF (userData, reportData) {
210
217
  a.address,
211
218
  Math.round(a.speed * 1.85200),
212
219
  a.attributes.ignition ? translations.report.ignitionOn : translations.report.ignitionOff,
213
- userData.byDriver ? a.vehicleName : getDriverName(a, userData.drivers),
214
- getTempValue(a)
220
+ userData.byDriver ? a.vehicleName : getDriverName(a, userData.drivers)
215
221
  ]
222
+
223
+ if (userData.includeTemperature) {
224
+ temp.push(getTempValue(a))
225
+ }
226
+
227
+ if (userData.includeDigitalPorts) {
228
+ temp.push(getDigitalPortValue(a, 1, translations))
229
+ temp.push(getDigitalPortValue(a, 2, translations))
230
+ }
231
+
216
232
  data.push(temp)
217
233
  })
218
234
 
@@ -257,6 +273,28 @@ function getTempValue (row) {
257
273
  )) || ''
258
274
  }
259
275
 
276
+ function getDigitalPort1Label (row, translations) {
277
+ return row.attributes.door1 || translations.report.digital_ports1
278
+ }
279
+
280
+ function getDigitalPort2Label (row, translations) {
281
+ return row.attributes.door2 || translations.report.digital_ports2
282
+ }
283
+
284
+ function getDigitalPortValue (row, index, translations) {
285
+ switch (index) {
286
+ case 1:
287
+ return row.attributes && row.attributes.door1 ? translations.report[row.attributes.door1] : ''
288
+ case 2:
289
+ if (row.attributes && row.attributes.door2) {
290
+ return translations.report[row.attributes.door2]
291
+ }
292
+ return row.attributes && row.attributes.rain ? translations.report[row.attributes.rain] : ''
293
+ default:
294
+ return ''
295
+ }
296
+ }
297
+
260
298
  function exportLocationReportToExcel (userData, reportData) {
261
299
  console.log('Export to Excel')
262
300
 
@@ -285,11 +323,20 @@ function exportLocationReportToExcel (userData, reportData) {
285
323
  { label: translations.report.address, value: 'address' },
286
324
  { label: translations.report.speed, value: 'speed' },
287
325
  { label: translations.report.ignition, value: 'ignition' },
288
- { label: translations.report.driver, value: 'driver' },
289
- { label: translations.report.temperature, value: 'temperature' }
326
+ { label: translations.report.driver, value: 'driver' }
290
327
  ]
328
+
329
+ if (userData.includeTemperature) {
330
+ headers.push({ label: translations.report.temperature, value: 'temperature' })
331
+ }
332
+
291
333
  let data = []
292
334
  if (positionsData) {
335
+ if (userData.includeDigitalPorts) {
336
+ headers.push({ label: getDigitalPort1Label(userData.byDriver ? positionsData[0].driver : positionsData[0].device, translations), value: 'digitalport1' })
337
+ headers.push({ label: getDigitalPort2Label(userData.byDriver ? positionsData[0].driver : positionsData[0].device, translations), value: 'digitalport2' })
338
+ }
339
+
293
340
  positionsData.forEach(d => {
294
341
  data = data.concat(d.positions.map(a => {
295
342
  return {
@@ -300,7 +347,9 @@ function exportLocationReportToExcel (userData, reportData) {
300
347
  speed: Math.round(a.speed * 1.85200),
301
348
  ignition: a.attributes.ignition ? translations.report.ignitionOn : translations.report.ignitionOff,
302
349
  driver: userData.byDriver ? d.driver.name : getDriverName(a, userData.drivers),
303
- temperature: getTempValue(a)
350
+ temperature: getTempValue(a),
351
+ digitalport1: getDigitalPortValue(a, 1, translations),
352
+ digitalport2: getDigitalPortValue(a, 2, translations)
304
353
  }
305
354
  }))
306
355
  })
@@ -169,9 +169,10 @@ function processDevices (from, to, devices, data, userData, traccar) {
169
169
  }
170
170
 
171
171
  const stop = getStop(new Date(trip.startTime), stops)
172
+
172
173
  if (stop && !trip.endTimeIsOut) {
173
174
  trip.stopDuration = (new Date(stop.endTime) - new Date(stop.startTime))
174
- trip.stopEngineHours = stop.engineHours
175
+ trip.stopEngineHours = trip.idleTime + stop.idleTime
175
176
  } else {
176
177
  trip.stopDuration = 0
177
178
  trip.stopEngineHours = 0
@@ -270,6 +271,7 @@ async function exportTripReportToPDF (userData, reportData) {
270
271
  }
271
272
 
272
273
  if (tripsData) {
274
+ // eslint-disable-next-line new-cap
273
275
  const doc = new jsPDF.jsPDF('l')
274
276
  await headerFromUser(doc, translations.report.titleTripReport, userData.user)
275
277
 
package/src/util/route.js CHANGED
@@ -1,4 +1,5 @@
1
1
  function getIdleEvents (route, driver) {
2
+ const speedThreshold = 3
2
3
  const idleEvents = []
3
4
 
4
5
  const routeByDevice = route.reduce(function (a, x) {
@@ -8,8 +9,9 @@ function getIdleEvents (route, driver) {
8
9
 
9
10
  Object.keys(routeByDevice).forEach(function (key) {
10
11
  let inIdle = false
12
+ let last = null
11
13
  routeByDevice[key].forEach(p => {
12
- if (p.attributes.ignition && p.speed === 0 && (!driver || p.attributes.driverUniqueId === driver.uniqueId)) {
14
+ if (p.attributes.ignition && p.speed < speedThreshold && (!driver || p.attributes.driverUniqueId === driver.uniqueId)) {
13
15
  if (!inIdle) {
14
16
  const idleEvent = {
15
17
  position: p,
@@ -17,20 +19,16 @@ function getIdleEvents (route, driver) {
17
19
  }
18
20
  idleEvents.push(idleEvent)
19
21
  inIdle = true
20
- } else {
21
- if (!idleEvents[idleEvents.length - 1].position.attributes.driverUniqueId) {
22
- idleEvents[idleEvents.length - 1].position.attributes.driverUniqueId = p.attributes.driverUniqueId
23
- }
22
+ }
24
23
 
25
- if (p.attributes.idleTime) {
26
- idleEvents[idleEvents.length - 1].idleTime = p.attributes.idleTime
27
- }
24
+ if (!idleEvents[idleEvents.length - 1].position.attributes.driverUniqueId) {
25
+ idleEvents[idleEvents.length - 1].position.attributes.driverUniqueId = p.attributes.driverUniqueId
28
26
  }
27
+
28
+ last = p
29
29
  } else if (inIdle) {
30
30
  const currentIdleEvent = idleEvents[idleEvents.length - 1]
31
- if (p.attributes.idleTime === undefined) {
32
- currentIdleEvent.idleTime = new Date(p.fixTime) - new Date(currentIdleEvent.position.fixTime)
33
- }
31
+ currentIdleEvent.idleTime = new Date(last.fixTime) - new Date(currentIdleEvent.position.fixTime)
34
32
  inIdle = false
35
33
  }
36
34
  })
@@ -38,5 +36,4 @@ function getIdleEvents (route, driver) {
38
36
 
39
37
  return idleEvents
40
38
  }
41
-
42
39
  exports.getIdleEvents = getIdleEvents