fleetmap-reports 1.0.262 → 1.0.263

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.
@@ -1,14 +1,11 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="ChangeListManager">
4
- <list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="calculate avg speed">
4
+ <list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="fix activity report by driver">
5
5
  <change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" />
6
6
  <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
7
7
  <change beforePath="$PROJECT_DIR$/src/activity-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/activity-report.js" afterDir="false" />
8
8
  <change beforePath="$PROJECT_DIR$/src/index.test.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.test.js" afterDir="false" />
9
- <change beforePath="$PROJECT_DIR$/src/kms-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/kms-report.js" afterDir="false" />
10
- <change beforePath="$PROJECT_DIR$/src/trip-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/trip-report.js" afterDir="false" />
11
- <change beforePath="$PROJECT_DIR$/src/util/traccar.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/util/traccar.js" afterDir="false" />
12
9
  </list>
13
10
  <option name="SHOW_DIALOG" value="false" />
14
11
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -222,7 +219,7 @@
222
219
  <workItem from="1640866364417" duration="67000" />
223
220
  <workItem from="1640866782794" duration="123000" />
224
221
  <workItem from="1640866964393" duration="1022000" />
225
- <workItem from="1640870147277" duration="2391000" />
222
+ <workItem from="1640870147277" duration="6811000" />
226
223
  </task>
227
224
  <task id="LOCAL-00001" summary="Fix getStyle">
228
225
  <created>1636983717385</created>
@@ -357,7 +354,14 @@
357
354
  <option name="project" value="LOCAL" />
358
355
  <updated>1640867522438</updated>
359
356
  </task>
360
- <option name="localTasksCounter" value="20" />
357
+ <task id="LOCAL-00020" summary="fix activity report by driver">
358
+ <created>1640872780966</created>
359
+ <option name="number" value="00020" />
360
+ <option name="presentableId" value="LOCAL-00020" />
361
+ <option name="project" value="LOCAL" />
362
+ <updated>1640872780968</updated>
363
+ </task>
364
+ <option name="localTasksCounter" value="21" />
361
365
  <servers />
362
366
  </component>
363
367
  <component name="TypeScriptGeneratedFilesManager">
@@ -394,6 +398,7 @@
394
398
  <MESSAGE value="location report - check if it's running on client side" />
395
399
  <MESSAGE value="timezone - check if it's running on client side" />
396
400
  <MESSAGE value="calculate avg speed" />
397
- <option name="LAST_COMMIT_MESSAGE" value="calculate avg speed" />
401
+ <MESSAGE value="fix activity report by driver" />
402
+ <option name="LAST_COMMIT_MESSAGE" value="fix activity report by driver" />
398
403
  </component>
399
404
  </project>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.262",
3
+ "version": "1.0.263",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -149,7 +149,7 @@ async function createActivityReportByDriver(from, to){
149
149
  to: to
150
150
  }
151
151
 
152
- allData.drivers = processDrivers(userData.drivers, tripsData)
152
+ allData.drivers = processDrivers(from, to, userData.drivers, tripsData)
153
153
 
154
154
  return allData
155
155
  }
@@ -180,7 +180,7 @@ function processDevices(devices, data, kmsReport) {
180
180
  return devicesResult
181
181
  }
182
182
 
183
- function processDrivers(drivers, data) {
183
+ function processDrivers(from, to, drivers, data) {
184
184
  console.log(data)
185
185
  const driversResult = []
186
186
  drivers.forEach(d => {
@@ -188,12 +188,63 @@ function processDrivers(drivers, data) {
188
188
  if (trips.length > 0) {
189
189
  const driverData = {
190
190
  driver: d,
191
- summary: [{
191
+ summary: [],
192
+ }
193
+ if(userData.groupByDay) {
194
+ const dates = getDates(from, to)
195
+ for(const date of dates){
196
+ if(userData.allWeek){
197
+ const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
198
+ const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
199
+
200
+ const tripsByDay = trips.filter(t => new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay)
201
+
202
+ driverData.summary.push({
203
+ date: date,
204
+ distance: tripsByDay.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
205
+ engineHours: tripsByDay.reduce((a, b) => a + b.duration, 0),
206
+ maxSpeed: tripsByDay.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
207
+ averageSpeed: tripsByDay.length > 0 ? Math.round(tripsByDay.reduce((a, b) => a + b.averageSpeed, 0) / tripsByDay.length) : 0,
208
+ })
209
+ } else {
210
+ if((date.getDay() === 0 && userData.weekDays.sunday) ||
211
+ (date.getDay() === 1 && userData.weekDays.monday) ||
212
+ (date.getDay() === 2 && userData.weekDays.tuesday) ||
213
+ (date.getDay() === 3 && userData.weekDays.wednesday) ||
214
+ (date.getDay() === 4 && userData.weekDays.thursday) ||
215
+ (date.getDay() === 5 && userData.weekDays.friday) ||
216
+ (date.getDay() === 6 && userData.weekDays.saturday)) {
217
+
218
+ const fromByDay = new Date(new Date(date).toISOString().split('T')[0] + ' ' + userData.dayHours.startTime)
219
+ const toByDay = new Date(new Date(date).toISOString().split('T')[0] + ' ' + userData.dayHours.endTime)
220
+
221
+ const tripsByDay = trips.filter(t => new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay)
222
+
223
+ driverData.summary.push({
224
+ date: date,
225
+ distance: tripsByDay.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
226
+ engineHours: tripsByDay.reduce((a, b) => a + b.duration, 0),
227
+ maxSpeed: tripsByDay.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
228
+ averageSpeed: tripsByDay.length > 0 ? Math.round(tripsByDay.reduce((a, b) => a + b.averageSpeed, 0) / tripsByDay.length) : 0,
229
+ })
230
+ }else {
231
+ driverData.summary.push({
232
+ date: date,
233
+ distance: 0,
234
+ engineHours: 0,
235
+ maxSpeed: 0,
236
+ averageSpeed: 0,
237
+ })
238
+ }
239
+ }
240
+ }
241
+ } else {
242
+ driverData.summary.push({
192
243
  distance: trips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
193
244
  engineHours: trips.reduce((a, b) => a + b.duration, 0),
194
245
  maxSpeed: trips.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
195
246
  averageSpeed: Math.round(trips.reduce((a, b) => a + b.averageSpeed, 0) / trips.length),
196
- }],
247
+ })
197
248
  }
198
249
  driversResult.push(driverData)
199
250
  }
@@ -211,9 +262,11 @@ async function exportActivityReportToPDF(userData, reportData) {
211
262
  const doc = new jsPDF.jsPDF('l')
212
263
  await headerFromUser(doc, translations.report.titleActivityReport, userData.user)
213
264
 
214
- if(userData.groupByDay){
265
+ if(userData.groupByDay && userData.byDriver) {
266
+ exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData)
267
+ } else if(userData.groupByDay) {
215
268
  exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData)
216
- } else if(userData.byDriver){
269
+ } else if(userData.byDriver) {
217
270
  exportActivityReportToPDF_Driver(doc, translations, reportData)
218
271
  } else {
219
272
  exportActivityReportToPDF_Vehicle(doc, translations, reportData)
@@ -430,6 +483,122 @@ function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations,
430
483
  }
431
484
  }
432
485
 
486
+ function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData) {
487
+ const headers = [translations.report.date,
488
+ translations.report.distance,
489
+ translations.report.avgSpeed + ' (Km/h)',
490
+ translations.report.maxSpeed + ' (Km/h)',
491
+ translations.report.engineHours]
492
+
493
+ const weekDays = [
494
+ translations.report.sunday,
495
+ translations.report.monday,
496
+ translations.report.tuesday,
497
+ translations.report.wednesday,
498
+ translations.report.thursday,
499
+ translations.report.friday,
500
+ translations.report.saturday
501
+ ]
502
+
503
+ reportData.drivers.forEach(function (d, index) {
504
+ const name = d.driver.name
505
+ const group = userData.groups.find(g => g.drivers.includes(d.id))
506
+
507
+ let space = index === 0 ? 8 : 0
508
+ if(index){
509
+ doc.addPage()
510
+ }
511
+
512
+ doc.setFontSize(13)
513
+ doc.text(name, 20, space + 20)
514
+ doc.setFontSize(11)
515
+ doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space + 20)
516
+ doc.text(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString(), 20, space + 25)
517
+
518
+ if (!userData.allWeek) {
519
+ doc.text((userData.weekDays.monday ? ' ' + translations.report.monday + ',' : '')
520
+ + (userData.weekDays.tuesday ? ' ' + translations.report.tuesday + ',' : '')
521
+ + (userData.weekDays.wednesday ? ' ' + translations.report.wednesday + ',' : '')
522
+ + (userData.weekDays.thursday ? ' ' + translations.report.thursday + ',' : '')
523
+ + (userData.weekDays.friday ? ' ' + translations.report.friday + ',' : '')
524
+ + (userData.weekDays.saturday ? ' ' + translations.report.saturday + ',' : '')
525
+ + (userData.weekDays.sunday ? ' ' + translations.report.sunday + ',' : '')
526
+ + ' das '
527
+ + userData.dayHours.startTime + ' - ' + userData.dayHours.endTime, 20, space + 30)
528
+ }
529
+
530
+ const data = []
531
+ d.summary.forEach(s => {
532
+ const temp = [
533
+ new Date(s.date).toLocaleDateString() + ' - ' + weekDays[s.date.getDay()],
534
+ Number((s.distance / 1000).toFixed(2)),
535
+ Math.round(s.averageSpeed * 1.85200),
536
+ Math.round(s.maxSpeed * 1.85200),
537
+ convertMS(s.engineHours)
538
+ ]
539
+
540
+ data.push(temp)
541
+ })
542
+
543
+ const footValues = ['Total:' + d.summary.length,
544
+ (d.summary.reduce((a, b) => a + b.distance, 0) / 1000).toFixed(0),
545
+ getSumAvgSpeed(d.summary),
546
+ getSumMaxSpeed(d.summary),
547
+ convertMS(d.summary.reduce((a, b) => a + b.engineHours, 0))]
548
+
549
+ const style = getStyle(getUserPartner(userData.user))
550
+ addTable(doc, headers, data, footValues, style, 40)
551
+ })
552
+ }
553
+
554
+ function exportActivityReportToExcel_Driver_GroupByDay(settings, translations, reportData) {
555
+ const headers = [{label: translations.report.driver, value: 'name'},
556
+ {label: translations.report.group, value: 'group'},
557
+ {label: translations.report.date, value: 'date'},
558
+ {label: translations.report.weekDay, value: 'weekday'},
559
+ {label: translations.report.distance, value: 'distance'},
560
+ {label: translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)', value: 'avgSpeed'},
561
+ {label: translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)', value: 'maxSpeed'},
562
+ {label: translations.report.engineHours, value: 'engineHours'}]
563
+
564
+ const weekDays = [
565
+ translations.report.sunday,
566
+ translations.report.monday,
567
+ translations.report.tuesday,
568
+ translations.report.wednesday,
569
+ translations.report.thursday,
570
+ translations.report.friday,
571
+ translations.report.saturday
572
+ ]
573
+
574
+ let data = []
575
+ if (reportData.drivers) {
576
+ reportData.drivers.forEach(d => {
577
+ const group = userData.groups.find(g => g.drivers.includes(d.id))
578
+
579
+ data = data.concat([{}])
580
+ data = data.concat(d.summary.map(s => {
581
+ return {
582
+ name: d.driver.name,
583
+ group: group ? group.name : '',
584
+ date: new Date(s.date).toLocaleDateString(),
585
+ weekday: weekDays[s.date.getDay()],
586
+ distance: Number((s.distance / 1000).toFixed(0)),
587
+ avgSpeed: Math.round(s.averageSpeed * 1.85200),
588
+ maxSpeed: Math.round(s.maxSpeed * 1.85200),
589
+ engineHours: convertMS(s.engineHours)
590
+ }
591
+ }))
592
+ })
593
+ console.log(data)
594
+ return {
595
+ headers,
596
+ data,
597
+ settings
598
+ }
599
+ }
600
+ }
601
+
433
602
  function exportActivityReportToExcel_Driver(settings, translations, reportData) {
434
603
  const headers = [{label: translations.report.driver, value: 'driver'},
435
604
  {label: translations.report.distance, value: 'distance'},
@@ -505,7 +674,9 @@ function exportActivityReportToExcel(reportUserData, reportData) {
505
674
  fileName: fileName // The name of the spreadsheet
506
675
  }
507
676
 
508
- if(userData.groupByDay){
677
+ if(userData.groupByDay && userData.byDriver){
678
+ return exportActivityReportToExcel_Driver_GroupByDay(settings, translations, reportData)
679
+ } else if(userData.groupByDay){
509
680
  return exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations, reportData)
510
681
  } else if(userData.byDriver){
511
682
  return exportActivityReportToExcel_Driver(settings, translations, reportData)