fleetmap-reports 1.0.379 → 1.0.380

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.379",
3
+ "version": "1.0.380",
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()
@@ -44,17 +44,29 @@ async function createTripReportByDevice(from, to, userData, traccar) {
44
44
 
45
45
  devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
46
46
 
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)
47
+ //const devicesToSlice = devices.slice()
48
+
49
+ console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
50
+ let deviceCount = 0
51
+ for(const device of devices) {
52
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, [device], true, true, true, false)
53
+ const tripsData = allInOne.trips
54
+ const stopsData = allInOne.stops
55
+ const routeData = allInOne.route
56
+
57
+ console.log('Trips:' + tripsData.length)
58
+
59
+ if (tripsData.length > 0) {
60
+ trips.checkTripsKms(traccar, from, to, [device], {trips: tripsData, route: routeData})
61
+ allData.devices.push(...processDevices(from, to, [device], {
62
+ trips: tripsData,
63
+ stops: stopsData,
64
+ route: routeData
65
+ }, userData))
66
+ }
54
67
 
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)
68
+ console.log('LOADING_MESSAGE:' + device.name)
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 =>
@@ -82,8 +80,6 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
82
80
  jar: traccar.cookieJar,
83
81
  withCredentials: true
84
82
  }).then(r => r.data).then(x => {
85
- console.log('LOADING_MESSAGE:' + d.name)
86
- console.log(`PROGRESS_PERC:${++deviceCount / devices.length * 100}`)
87
83
  return x
88
84
  }))
89
85
  result.push(...(await Promise.all(requests)))