fleetmap-reports 1.0.378 → 1.0.381

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.378",
3
+ "version": "1.0.381",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.test.js CHANGED
@@ -200,9 +200,9 @@ describe('Test_Reports', function() {
200
200
  assert.equal(data.length, 1)
201
201
  const device = data[0].devices.find(d => d.device.id===22326)
202
202
  assert.equal(device.summary[0].startOdometer, 122502742.59)
203
- assert.equal(device.summary[0].distance, 1386539.76000001)
203
+ assert.equal(device.summary[0].distance, 1423529.600000009)
204
204
  assert.equal(device.summary[0].startTime, '2022-01-01T13:35:47.000+0000')
205
- assert.equal(device.summary[0].endTime, '2022-01-30T14:08:13.000+0000')
205
+ assert.equal(device.summary[0].endTime, '2022-01-31T17:36:27.000+0000')
206
206
  }, 40000)
207
207
  it('Activity 2 by device', async () => {
208
208
  const report = await getReports()
@@ -235,16 +235,16 @@ describe('Test_Reports', function() {
235
235
  const reports = await getReports()
236
236
  const userData = await reports.getUserData()
237
237
  const r = await require('./util/traccar').getAllInOne(reports.traccar,
238
- new Date(2022, 1, 1),
239
- new Date(2022, 1, 4),
238
+ new Date(2022, 1, 1, 0, 0, 0, 0),
239
+ new Date(2022, 1, 4, 23, 59, 59, 0),
240
240
  userData.devices,
241
241
  false,
242
242
  true,
243
243
  true,
244
244
  false)
245
245
 
246
- assert.equal(r.trips.filter(t => t.deviceId === 22327).length, 10)
247
- assert.equal(r.stops.filter(t => t.deviceId === 22327).length, 11)
246
+ assert.equal(r.trips.filter(t => t.deviceId === 22327).length, 20)
247
+ assert.equal(r.stops.filter(t => t.deviceId === 22327).length, 21)
248
248
  }, 20000)
249
249
  it('Total KMS', async () => {
250
250
  const report = await getReports()
@@ -72,7 +72,8 @@ async function createSpeedingReportByDevice(from, to, userData, traccarInstance)
72
72
 
73
73
  devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
74
74
 
75
- const routes = await traccarHelper.getRoute(traccarInstance, from, to, devices)
75
+ const allInOne = await traccarHelper.getAllInOne(traccarInstance, from, to, devices, true, false, false, false)
76
+ const routes = allInOne.route
76
77
  const events = []
77
78
  if(!userData.useVehicleSpeedLimit && userData.customSpeed){
78
79
  events.push(...await getCustomSpeedLimitEvents(devices, routes, userData.customSpeed))
@@ -104,7 +105,9 @@ async function createSpeedingReportByDriver(from, to, userData, traccarInstance)
104
105
  return { drivers: [] }
105
106
  }
106
107
 
107
- const routes = await traccarHelper.getRoute(traccarInstance, from, to, devices)
108
+ const allInOne = await traccarHelper.getAllInOne(traccarInstance, from, to, devices, true, false, false, false)
109
+ const routes = allInOne.route
110
+
108
111
  const events = []
109
112
  if(!userData.useVehicleSpeedLimit && userData.customSpeed){
110
113
  events.push(...await getCustomSpeedLimitEvents(devices, routes, userData.customSpeed))
@@ -45,16 +45,28 @@ async function createTripReportByDevice(from, to, userData, traccar) {
45
45
  devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
46
46
 
47
47
  const devicesToSlice = devices.slice()
48
- const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devicesToSlice, true, true, true, false)
49
- const tripsData = allInOne.trips
50
- const stopsData = allInOne.stops
51
- const routeData = allInOne.route
52
-
53
- console.log('Trips:' + tripsData.length)
54
-
55
- if (tripsData.length > 0) {
56
- trips.checkTripsKms(traccar, from, to, devices, {trips: tripsData, route: routeData})
57
- allData.devices = processDevices(from, to, devices, {trips: tripsData, stops: stopsData, route: routeData}, userData)
48
+ const sliced = automaticReports.sliceArray(devicesToSlice, 5)
49
+
50
+ console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
51
+ let deviceCount = 0
52
+ for(const slice of sliced) {
53
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, true, false)
54
+ const tripsData = allInOne.trips
55
+ const stopsData = allInOne.stops
56
+ const routeData = allInOne.route
57
+
58
+ console.log('Trips:' + tripsData.length)
59
+
60
+ if (tripsData.length > 0) {
61
+ trips.checkTripsKms(traccar, from, to, slice, {trips: tripsData, route: routeData})
62
+ allData.devices.push(...processDevices(from, to, slice, {
63
+ trips: tripsData,
64
+ stops: stopsData,
65
+ route: routeData
66
+ }, userData))
67
+ }
68
+ deviceCount = deviceCount + slice.length
69
+ console.log(`PROGRESS_PERC:${deviceCount / devices.length * 100}`)
58
70
  }
59
71
 
60
72
  return allData
@@ -133,8 +145,6 @@ function processDevices(from, to, devices, data, userData) {
133
145
  const trips = deviceTrips.filter(t => userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
134
146
  const stops = data.stops.filter(s => s.deviceId === d.id)
135
147
 
136
- console.log('LOADING_MESSAGE:' + d.name)
137
-
138
148
  addNearestPOIs(trips, userData)
139
149
 
140
150
  trips.forEach(trip => {
@@ -71,10 +71,8 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
71
71
  if(getTrips) url += `&type=trips`
72
72
  if(getStops) url += `&type=stops`
73
73
  if(getSummary) url += `&type=summary`
74
- console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
75
74
 
76
75
  const sliced = automaticReports.sliceArray(devices, 5)
77
- let deviceCount = 0
78
76
  const result = []
79
77
  for(const chunk of sliced) {
80
78
  const requests = chunk.map(d =>
@@ -83,7 +81,6 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
83
81
  withCredentials: true
84
82
  }).then(r => r.data).then(x => {
85
83
  console.log('LOADING_MESSAGE:' + d.name)
86
- console.log(`PROGRESS_PERC:${++deviceCount / devices.length * 100}`)
87
84
  return x
88
85
  }))
89
86
  result.push(...(await Promise.all(requests)))