fleetmap-reports 1.0.261 → 1.0.262

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,11 +1,14 @@
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="timezone - check if it's running on client side">
4
+ <list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="calculate avg speed">
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
+ <change beforePath="$PROJECT_DIR$/src/activity-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/activity-report.js" afterDir="false" />
7
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" />
8
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" />
9
12
  </list>
10
13
  <option name="SHOW_DIALOG" value="false" />
11
14
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -218,7 +221,8 @@
218
221
  <workItem from="1640794844118" duration="10128000" />
219
222
  <workItem from="1640866364417" duration="67000" />
220
223
  <workItem from="1640866782794" duration="123000" />
221
- <workItem from="1640866964393" duration="478000" />
224
+ <workItem from="1640866964393" duration="1022000" />
225
+ <workItem from="1640870147277" duration="2391000" />
222
226
  </task>
223
227
  <task id="LOCAL-00001" summary="Fix getStyle">
224
228
  <created>1636983717385</created>
@@ -346,7 +350,14 @@
346
350
  <option name="project" value="LOCAL" />
347
351
  <updated>1640825795053</updated>
348
352
  </task>
349
- <option name="localTasksCounter" value="19" />
353
+ <task id="LOCAL-00019" summary="calculate avg speed">
354
+ <created>1640867522437</created>
355
+ <option name="number" value="00019" />
356
+ <option name="presentableId" value="LOCAL-00019" />
357
+ <option name="project" value="LOCAL" />
358
+ <updated>1640867522438</updated>
359
+ </task>
360
+ <option name="localTasksCounter" value="20" />
350
361
  <servers />
351
362
  </component>
352
363
  <component name="TypeScriptGeneratedFilesManager">
@@ -382,6 +393,7 @@
382
393
  <MESSAGE value="Fix reports by driver" />
383
394
  <MESSAGE value="location report - check if it's running on client side" />
384
395
  <MESSAGE value="timezone - check if it's running on client side" />
385
- <option name="LAST_COMMIT_MESSAGE" value="timezone - check if it's running on client side" />
396
+ <MESSAGE value="calculate avg speed" />
397
+ <option name="LAST_COMMIT_MESSAGE" value="calculate avg speed" />
386
398
  </component>
387
399
  </project>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.261",
3
+ "version": "1.0.262",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -140,8 +140,7 @@ async function createActivityReportByDriver(from, to){
140
140
  console.log(deviceIds)
141
141
  let tripsData = []
142
142
  if(deviceIds.length > 0) {
143
- const response = await traccar.getTrips(traccarInstance, from, to, deviceIds)
144
- tripsData = response.data
143
+ tripsData = await traccar.getTrips(traccarInstance, from, to, deviceIds)
145
144
  }
146
145
 
147
146
  const allData = {
@@ -189,12 +188,12 @@ function processDrivers(drivers, data) {
189
188
  if (trips.length > 0) {
190
189
  const driverData = {
191
190
  driver: d,
192
- summary: {
191
+ summary: [{
193
192
  distance: trips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
194
193
  engineHours: trips.reduce((a, b) => a + b.duration, 0),
195
194
  maxSpeed: trips.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
196
195
  averageSpeed: Math.round(trips.reduce((a, b) => a + b.averageSpeed, 0) / trips.length),
197
- },
196
+ }],
198
197
  }
199
198
  driversResult.push(driverData)
200
199
  }
@@ -257,7 +256,7 @@ function exportActivityReportToPDF_Driver(doc, translations, reportData) {
257
256
  }
258
257
 
259
258
  function exportActivityReportToPDF_Vehicle(doc, translations, reportData) {
260
- const headers = [translations.report.name,
259
+ const headers = [translations.report.vehicle,
261
260
  translations.report.group,
262
261
  translations.report.distance,
263
262
  translations.report.start + ' ' + translations.report.odometer,
@@ -275,7 +274,7 @@ function exportActivityReportToPDF_Vehicle(doc, translations, reportData) {
275
274
  const group = userData.groups.find(g => d.device.groupId === g.id)
276
275
 
277
276
  const temp = [
278
- d.summary.deviceName,
277
+ d.summary[0].deviceName,
279
278
  group ? group.name : '',
280
279
  Number((d.summary[0].distance / 1000).toFixed(2)),
281
280
  Number((d.summary[0].startOdometer / 1000).toFixed(2)),
@@ -443,10 +442,10 @@ function exportActivityReportToExcel_Driver(settings, translations, reportData)
443
442
  reportData.drivers.forEach(d => {
444
443
  data = data.concat([{
445
444
  driver: d.driver.name,
446
- distance: Number((d.summary.distance / 1000).toFixed(0)),
447
- avgSpeed: Math.round(d.summary.averageSpeed * 1.85200),
448
- maxSpeed: Math.round(d.summary.maxSpeed * 1.85200),
449
- engineHours: convertMS(d.summary.engineHours)
445
+ distance: Number((d.summary[0].distance / 1000).toFixed(0)),
446
+ avgSpeed: Math.round(d.summary[0].averageSpeed * 1.85200),
447
+ maxSpeed: Math.round(d.summary[0].maxSpeed * 1.85200),
448
+ engineHours: convertMS(d.summary[0].engineHours)
450
449
  }])
451
450
  })
452
451
  console.log(data)
@@ -475,15 +474,15 @@ function exportActivityReportToExcel_Vehicle(settings, translations, reportData)
475
474
  const group = userData.groups.find(g => d.device.groupId === g.id)
476
475
 
477
476
  data = data.concat([{
478
- name: d.summary.deviceName,
477
+ name: d.summary[0].deviceName,
479
478
  group: group ? group.name : '',
480
- distance: Number((d.summary.distance / 1000).toFixed(0)),
481
- startOdometer: Number((d.summary.startOdometer / 1000).toFixed(0)),
482
- endOdometer: Number((d.summary.endOdometer / 1000).toFixed(0)),
483
- avgSpeed: Math.round(d.summary.averageSpeed * 1.85200),
484
- maxSpeed: Math.round(d.summary.maxSpeed * 1.85200),
485
- engineHours: convertMS(d.summary.engineHours),
486
- spentFuel: d.summary.convertedSpentFuel >= 0 ? d.summary.convertedSpentFuel : 0,
479
+ distance: Number((d.summary[0].distance / 1000).toFixed(0)),
480
+ startOdometer: Number((d.summary[0].startOdometer / 1000).toFixed(0)),
481
+ endOdometer: Number((d.summary[0].endOdometer / 1000).toFixed(0)),
482
+ avgSpeed: Math.round(d.summary[0].averageSpeed * 1.85200),
483
+ maxSpeed: Math.round(d.summary[0].maxSpeed * 1.85200),
484
+ engineHours: convertMS(d.summary[0].engineHours),
485
+ spentFuel: d.summary[0].convertedSpentFuel >= 0 ? d.summary[0].convertedSpentFuel : 0,
487
486
  }])
488
487
  })
489
488
  console.log(data)
package/src/kms-report.js CHANGED
@@ -26,7 +26,7 @@ async function createKmsReportByDevice(from, to) {
26
26
 
27
27
  devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
28
28
  const route = userData.allWeek ? [] : await traccar.getRoute(traccarInstance, from, to, devicesToProcess)
29
- const tripsData = await traccar.getTrips(traccarInstance, from, to, devicesToProcess)
29
+ const tripsData = await traccar.getTrips(traccarInstance, from, to, devicesToProcess.map(d => d.id))
30
30
 
31
31
  console.log('trips:' + tripsData.length)
32
32
 
@@ -51,7 +51,7 @@ async function createTripReportByDevice(from, to, devices) {
51
51
  devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
52
52
 
53
53
  const devicesToSlice = devices.slice()
54
- const data = await traccar.getTrips(traccarInstance, from, to, devicesToSlice)
54
+ const data = await traccar.getTrips(traccarInstance, from, to, devicesToSlice.map(d => d.id))
55
55
  const stopsData = await traccar.getStops(traccarInstance, from, to, devicesToSlice)
56
56
 
57
57
  console.log('Trips:' + data.length)
@@ -14,12 +14,12 @@ async function getRoute(traccar, from, to, devices){
14
14
  return result.map(r => r.data).flat()
15
15
  }
16
16
 
17
- async function getTrips(traccar, from, to, devices){
18
- const devicesToSlice = devices.slice()
17
+ async function getTrips(traccar, from, to, deviceIds){
18
+ const devicesToSlice = deviceIds.slice()
19
19
  const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
20
20
  let requests = []
21
21
  for (const a of arrayOfArrays) {
22
- const promise = traccar.reports.reportsTripsGet(from, to, a.map(d => d.id))
22
+ const promise = traccar.reports.reportsTripsGet(from, to, a)
23
23
  requests = requests.concat(promise)
24
24
  }
25
25