fleetmap-reports 1.0.344 → 1.0.347

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.344",
3
+ "version": "1.0.347",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -286,6 +286,8 @@ async function exportActivityReportToPDF(userData, reportData) {
286
286
 
287
287
  function exportActivityReportToPDF_Driver(doc, translations, reportData, userData) {
288
288
  const headers = [translations.report.driver,
289
+ translations.report.start,
290
+ translations.report.end,
289
291
  translations.report.distance,
290
292
  translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)',
291
293
  translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)',
@@ -298,6 +300,8 @@ function exportActivityReportToPDF_Driver(doc, translations, reportData, userDat
298
300
  reportData.drivers.forEach(d => {
299
301
  const temp = [
300
302
  d.driver.name,
303
+ d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
304
+ d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
301
305
  Number((d.summary[0].distance / 1000).toFixed(2)),
302
306
  Math.round(d.summary[0].averageSpeed * 1.85200),
303
307
  Math.round(d.summary[0].maxSpeed * 1.85200),
@@ -307,6 +311,7 @@ function exportActivityReportToPDF_Driver(doc, translations, reportData, userDat
307
311
  })
308
312
 
309
313
  const footValues = ['Total:' + reportData.drivers.length,
314
+ '','',
310
315
  (reportData.drivers.reduce((a, b) => a + b.summary[0].distance, 0) / 1000).toFixed(0),
311
316
  getSumAvgSpeed(reportData.drivers, userData),
312
317
  getSumMaxSpeed(reportData.drivers, userData),
@@ -319,6 +324,8 @@ function exportActivityReportToPDF_Driver(doc, translations, reportData, userDat
319
324
  function exportActivityReportToPDF_Vehicle(doc, translations, reportData, userData) {
320
325
  const headers = [translations.report.vehicle,
321
326
  translations.report.group,
327
+ translations.report.start,
328
+ translations.report.end,
322
329
  translations.report.distance,
323
330
  translations.report.start + ' ' + translations.report.odometer,
324
331
  translations.report.end + ' ' + translations.report.odometer,
@@ -337,6 +344,8 @@ function exportActivityReportToPDF_Vehicle(doc, translations, reportData, userDa
337
344
  const temp = [
338
345
  d.summary[0].deviceName,
339
346
  group ? group.name : '',
347
+ d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
348
+ d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
340
349
  Number((d.summary[0].distance / 1000).toFixed(2)),
341
350
  Number((d.summary[0].startOdometer / 1000).toFixed(2)),
342
351
  Number((d.summary[0].endOdometer / 1000).toFixed(2)),
@@ -349,7 +358,7 @@ function exportActivityReportToPDF_Vehicle(doc, translations, reportData, userDa
349
358
  })
350
359
 
351
360
  const footValues = ['Total:' + reportData.devices.length,
352
- '',
361
+ '','','',
353
362
  (reportData.devices.reduce((a, b) => a + b.summary[0].distance, 0) / 1000).toFixed(0),
354
363
  '', '',
355
364
  getSumAvgSpeed(reportData.devices, userData),
@@ -363,6 +372,8 @@ function exportActivityReportToPDF_Vehicle(doc, translations, reportData, userDa
363
372
 
364
373
  function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData, userData) {
365
374
  const headers = [translations.report.date,
375
+ translations.report.start,
376
+ translations.report.end,
366
377
  translations.report.distance,
367
378
  translations.report.start + ' ' + translations.report.odometer,
368
379
  translations.report.end + ' ' + translations.report.odometer,
@@ -412,6 +423,8 @@ function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportD
412
423
  d.summary.forEach(s => {
413
424
  const temp = [
414
425
  new Date(s.date).toLocaleDateString() + ' - ' + weekDays[s.date.getDay()],
426
+ s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
427
+ s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
415
428
  Number((s.distance / 1000).toFixed(2)),
416
429
  Number((s.startOdometer / 1000).toFixed(2)),
417
430
  Number((s.endOdometer / 1000).toFixed(2)),
@@ -425,6 +438,7 @@ function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportD
425
438
  })
426
439
 
427
440
  const footValues = ['Total:' + d.summary.length,
441
+ '','',
428
442
  (d.summary.reduce((a, b) => a + b.distance, 0) / 1000).toFixed(0),
429
443
  '', '',
430
444
  getSumAvgSpeed(d.summary, userData),
@@ -442,6 +456,8 @@ function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations,
442
456
  {label: translations.report.group, value: 'group'},
443
457
  {label: translations.report.date, value: 'date'},
444
458
  {label: translations.report.weekDay, value: 'weekday'},
459
+ {label: translations.report.start, value: 'start'},
460
+ {label: translations.report.end, value: 'end'},
445
461
  {label: translations.report.distance, value: 'distance'},
446
462
  {label: translations.report.start + ' ' + translations.report.odometer, value: 'startOdometer'},
447
463
  {label: translations.report.end + ' ' + translations.report.odometer, value: 'endOdometer'},
@@ -472,6 +488,8 @@ function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations,
472
488
  group: group ? group.name : '',
473
489
  date: new Date(s.date).toLocaleDateString(),
474
490
  weekday: weekDays[s.date.getDay()],
491
+ start: s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
492
+ end:s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
475
493
  distance: Number((s.distance / 1000).toFixed(0)),
476
494
  startOdometer: Number((s.startOdometer / 1000).toFixed(0)),
477
495
  endOdometer: Number((s.endOdometer / 1000).toFixed(0)),
@@ -493,6 +511,8 @@ function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations,
493
511
 
494
512
  function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData, userData) {
495
513
  const headers = [translations.report.date,
514
+ translations.report.start,
515
+ translations.report.end,
496
516
  translations.report.distance,
497
517
  translations.report.avgSpeed + ' (Km/h)',
498
518
  translations.report.maxSpeed + ' (Km/h)',
@@ -539,6 +559,8 @@ function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportDa
539
559
  d.summary.forEach(s => {
540
560
  const temp = [
541
561
  new Date(s.date).toLocaleDateString() + ' - ' + weekDays[s.date.getDay()],
562
+ s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
563
+ s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
542
564
  Number((s.distance / 1000).toFixed(2)),
543
565
  Math.round(s.averageSpeed * 1.85200),
544
566
  Math.round(s.maxSpeed * 1.85200),
@@ -549,6 +571,7 @@ function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportDa
549
571
  })
550
572
 
551
573
  const footValues = ['Total:' + d.summary.length,
574
+ '','',
552
575
  (d.summary.reduce((a, b) => a + b.distance, 0) / 1000).toFixed(0),
553
576
  getSumAvgSpeed(d.summary, userData),
554
577
  getSumMaxSpeed(d.summary, userData),
@@ -564,6 +587,8 @@ function exportActivityReportToExcel_Driver_GroupByDay(settings, translations, r
564
587
  {label: translations.report.group, value: 'group'},
565
588
  {label: translations.report.date, value: 'date'},
566
589
  {label: translations.report.weekDay, value: 'weekday'},
590
+ {label: translations.report.start, value: 'start'},
591
+ {label: translations.report.end, value: 'end'},
567
592
  {label: translations.report.distance, value: 'distance'},
568
593
  {label: translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)', value: 'avgSpeed'},
569
594
  {label: translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)', value: 'maxSpeed'},
@@ -591,6 +616,8 @@ function exportActivityReportToExcel_Driver_GroupByDay(settings, translations, r
591
616
  group: group ? group.name : '',
592
617
  date: new Date(s.date).toLocaleDateString(),
593
618
  weekday: weekDays[s.date.getDay()],
619
+ start: s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
620
+ end:s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
594
621
  distance: Number((s.distance / 1000).toFixed(0)),
595
622
  avgSpeed: Math.round(s.averageSpeed * 1.85200),
596
623
  maxSpeed: Math.round(s.maxSpeed * 1.85200),
@@ -609,6 +636,8 @@ function exportActivityReportToExcel_Driver_GroupByDay(settings, translations, r
609
636
 
610
637
  function exportActivityReportToExcel_Driver(settings, translations, reportData) {
611
638
  const headers = [{label: translations.report.driver, value: 'driver'},
639
+ {label: translations.report.start, value: 'start'},
640
+ {label: translations.report.end, value: 'end'},
612
641
  {label: translations.report.distance, value: 'distance'},
613
642
  {label: translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)', value: 'avgSpeed'},
614
643
  {label: translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)', value: 'maxSpeed'},
@@ -619,6 +648,8 @@ function exportActivityReportToExcel_Driver(settings, translations, reportData)
619
648
  reportData.drivers.forEach(d => {
620
649
  data = data.concat([{
621
650
  driver: d.driver.name,
651
+ start: d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
652
+ end: d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
622
653
  distance: Number((d.summary[0].distance / 1000).toFixed(0)),
623
654
  avgSpeed: Math.round(d.summary[0].averageSpeed * 1.85200),
624
655
  maxSpeed: Math.round(d.summary[0].maxSpeed * 1.85200),
@@ -637,6 +668,8 @@ function exportActivityReportToExcel_Driver(settings, translations, reportData)
637
668
  function exportActivityReportToExcel_Vehicle(settings, translations, reportData, userData) {
638
669
  const headers = [{label: translations.report.vehicle, value: 'name'},
639
670
  {label: translations.report.group, value: 'group'},
671
+ {label: translations.report.start, value: 'start'},
672
+ {label: translations.report.end, value: 'end'},
640
673
  {label: translations.report.distance, value: 'distance'},
641
674
  {label: translations.report.start + ' ' + translations.report.odometer, value: 'startOdometer'},
642
675
  {label: translations.report.end + ' ' + translations.report.odometer, value: 'endOdometer'},
@@ -653,6 +686,8 @@ function exportActivityReportToExcel_Vehicle(settings, translations, reportData,
653
686
  data = data.concat([{
654
687
  name: d.summary[0].deviceName,
655
688
  group: group ? group.name : '',
689
+ start: d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
690
+ end: d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
656
691
  distance: Number((d.summary[0].distance / 1000).toFixed(0)),
657
692
  startOdometer: Number((d.summary[0].startOdometer / 1000).toFixed(0)),
658
693
  endOdometer: Number((d.summary[0].endOdometer / 1000).toFixed(0)),
package/src/index.test.js CHANGED
@@ -119,6 +119,7 @@ describe('Test_Reports', function() {
119
119
  it('KmsReport by device', async () => {
120
120
  const reports = await getReports()
121
121
  const userData = await reports.getUserData()
122
+ userData.devices = userData.devices.filter(d => d.id === 22326)
122
123
  const data = await reports.kmsReport(new Date(2021, 10, 1, 0, 0,0), new Date(2021, 10, 31, 23, 59, 59),
123
124
  userData)
124
125
  assert.equal(data.length, 1)
@@ -129,6 +130,7 @@ describe('Test_Reports', function() {
129
130
  it('KmsReport byDevice groupByDay', async () => {
130
131
  const reports = await getReports()
131
132
  const userData = await reports.getUserData()
133
+ userData.devices = userData.devices.filter(d => d.id === 22326)
132
134
  userData.groupByDay = true
133
135
  const data = await reports.kmsReport(new Date(2021, 10, 1, 0, 0,0), new Date(2021, 10, 10, 23, 59, 59),
134
136
  userData)
@@ -137,7 +139,7 @@ describe('Test_Reports', function() {
137
139
  const device = data[0].devices.find(d => d.device.id===22326)
138
140
  assert.equal(device.days.length, 10) // Total Kms
139
141
  assert.equal(device.days[5].kms, 23183.010000005364) // Total Kms
140
- },90000)
142
+ },30000)
141
143
  it('Idle by device', async () => {
142
144
  const report = await getReports()
143
145
  const userData = await report.getUserData()
@@ -215,4 +217,33 @@ describe('Test_Reports', function() {
215
217
  const device2 = kmsReport[0].devices.find(d => d.device.id===11681)
216
218
  assert.equal(device2.summary.distance, device1.totalDistance) // Total Kms
217
219
  }, 30000)
220
+ it('Refueling Report', async () => {
221
+ const report = await getReports()
222
+ const userData = await report.getUserData()
223
+
224
+ const data = await report.refuelingReport(new Date(2022, 1, 2, 0, 0, 0, 0),
225
+ new Date(2022, 1, 2, 23, 59, 59, 0),
226
+ userData)
227
+
228
+ assert.equal(data.length, 1)
229
+ console.log(data[0])
230
+ const device = data[0].devices.find(d => d.device.id===16245)
231
+ assert.equal(device.refuelings.length, 2)
232
+
233
+ }, 30000)
234
+ it('Refueling2 Report', async () => {
235
+ const report = await getReports()
236
+ const userData = await report.getUserData()
237
+
238
+ const data = await report.refuelingReport(new Date(2022, 1, 21, 0, 0, 0, 0),
239
+ new Date(2022, 1, 25, 23, 59, 59, 0),
240
+ userData)
241
+
242
+ assert.equal(data.length, 1)
243
+ console.log(data[0])
244
+ const device = data[0].devices.find(d => d.device.id===16245)
245
+ console.log(device.refuelings)
246
+ assert.equal(device.refuelings.length, 4)
247
+
248
+ }, 30000)
218
249
  })
@@ -1,6 +1,8 @@
1
1
  const helpers = require("turf");
2
2
  const automaticReports = require("./automaticReports");
3
3
 
4
+ const positionsToCheck = 15
5
+
4
6
  async function createRefuelingReport(from, to, userData, traccar) {
5
7
  console.log('Create RefuelingReport')
6
8
 
@@ -134,10 +136,10 @@ function calculateRefuelingPositions(d, positions) {
134
136
  const value = Math.round(diff * d.attributes.fuel_tank_capacity / 100)
135
137
  refuelingPositions.push({position: element, diff: value})
136
138
  lastRefuelingIndex = index
137
- positionsChecked = 6 // to reset values
139
+ positionsChecked = positionsToCheck+1 // to reset values
138
140
  }
139
141
 
140
- if(positionsChecked > 5) {
142
+ if(positionsChecked > positionsToCheck) {
141
143
  refuelingActivated = false
142
144
  currentValue = null
143
145
  positionsChecked = 0
@@ -238,7 +238,6 @@ async function getHereEvents(devices, routes, threshold){
238
238
  continue
239
239
  }
240
240
  let hereAlerts = null
241
- try {
242
241
  const results = await here.routeMatch(positions)
243
242
  hereAlerts = results.filter(r => r.currentSpeedKmh > (parseInt(r.speedLimit) + threshold)).map(r => {
244
243
  const position = positions.find(p => new Date(p.fixTime).getTime() === r.timestamp)
@@ -265,9 +264,6 @@ async function getHereEvents(devices, routes, threshold){
265
264
  return acc
266
265
  })
267
266
  events.push(...reduced)
268
- } catch (e) {
269
- console.error(hereAlerts, 'threshold', threshold, e)
270
- }
271
267
  }
272
268
  return events
273
269
  }