fleetmap-reports 1.0.340 → 1.0.342

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.340",
3
+ "version": "1.0.342",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -28,6 +28,7 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "axios-debug-log": "^0.8.4",
31
+ "jest": "^27.5.0",
31
32
  "mocha": "^9.0.3",
32
33
  "webpack": "^5.24.3",
33
34
  "webpack-cli": "^4.5.0"
@@ -9,7 +9,7 @@ const {getStyle} = require("./reportStyle")
9
9
  const {getUserPartner} = require("fleetmap-partners")
10
10
  const traccar = require("./util/traccar")
11
11
  const {isInsideTimetable, isPartialInsideTimetable} = require("./util/trips");
12
- const trips = require("./util/trips");
12
+ const tripHelper = require("./util/trips");
13
13
 
14
14
  const fileName = 'ActivityReport'
15
15
 
@@ -85,16 +85,14 @@ async function createActivityReportByDevice(from, to, userData, traccarInstance)
85
85
  //Get report data from traccar
86
86
  devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
87
87
 
88
- let routeData = []
89
88
  let summaries = []
90
- const tripsData = await traccar.getTrips(traccarInstance, from, to, devicesToProcess)
89
+ const {trips, route, summary} = await traccar.getAllInOne(traccarInstance, from, to, devicesToProcess, userData.groupByDay && !userData.allWeek, true, false, !userData.groupByDay)
91
90
 
92
91
  if(userData.groupByDay) {
93
- routeData = await traccar.getRoute(traccarInstance, from, to, devicesToProcess)
94
- console.log('trips:' + tripsData.length)
92
+ console.log('trips:' + trips.length)
95
93
 
96
- if (tripsData.length > 0) {
97
- trips.checkTripsKms(traccarInstance, from, to, devicesToProcess, {trips: tripsData, route: routeData})
94
+ if (trips.length) {
95
+ tripHelper.checkTripsKms(traccarInstance, from, to, devicesToProcess, {trips, route})
98
96
  }
99
97
 
100
98
  const dates = getDates(from, to)
@@ -109,14 +107,14 @@ async function createActivityReportByDevice(from, to, userData, traccarInstance)
109
107
  }
110
108
  }
111
109
  } else {
112
- summaries = await traccar.getSummary(traccarInstance, from, to, devicesToProcess)
110
+ summaries = summary
113
111
  }
114
112
 
115
113
  console.log('Summary:' + summaries.length)
116
114
 
117
115
  //Process report data
118
- if (summaries.length || tripsData.length) {
119
- allData.devices = processDevices(from, to, devicesToProcess, {summaries: summaries, trips: tripsData, route: routeData}, userData)
116
+ if (summaries.length || trips.length) {
117
+ allData.devices = processDevices(from, to, devicesToProcess, {summaries: summaries, trips, route}, userData)
120
118
  }
121
119
 
122
120
  return allData
package/src/index.test.js CHANGED
@@ -16,7 +16,7 @@ describe('Test_Reports', function() {
16
16
  assert.equal(device.alerts.length, 15) // Total Alerts
17
17
  assert.equal(totalDistance, 19.605972526552154) // Total Kms
18
18
  assert.equal(totalEventTime, 562000) // Total Duration
19
- }).timeout(20000)
19
+ }, 20000)
20
20
  it('Speeding by device with custom speed', async () => {
21
21
  const report = await getReports()
22
22
  const userData = await report.getUserData()
@@ -34,7 +34,7 @@ describe('Test_Reports', function() {
34
34
  assert.equal(device.alerts.length, 24) // Total Alerts
35
35
  assert.equal(totalDistance, 49.49653008204987) // Total Kms
36
36
  assert.equal(totalEventTime, 1523000) // Total Duration
37
- }).timeout(20000)
37
+ }, 20000)
38
38
  it('Trip by device', async () => {
39
39
  const report = await getReports()
40
40
  const userData = await report.getUserData()
@@ -47,7 +47,7 @@ describe('Test_Reports', function() {
47
47
  const device = data[0].devices.find(d => d.device.id===22326)
48
48
  assert.equal(device.trips.length, 7) // Total Trips
49
49
  assert.equal(device.totalDistance, 339204.53999999166) // Total Kms
50
- }).timeout(20000)
50
+ }, 20000)
51
51
  it('Trip by device with time period ', async () => {
52
52
  const report = await getReports()
53
53
  const userData = await report.getUserData()
@@ -75,7 +75,7 @@ describe('Test_Reports', function() {
75
75
  const device = data[0].devices.find(d => d.device.id===22326)
76
76
  assert.equal(device.trips.length, 4) // Total Trips
77
77
  assert.equal(device.totalDistance, 265155.1099999994) // Total Kms
78
- }).timeout(20000)
78
+ },20000)
79
79
  it('Trip by device with time period 2', async () => {
80
80
  const report = await getReports()
81
81
  const userData = await report.getUserData()
@@ -103,7 +103,7 @@ describe('Test_Reports', function() {
103
103
  const device = data[0].devices.find(d => d.device.id===22326)
104
104
  assert.equal(device.trips.length, 18) // Total Trips
105
105
  assert.equal(device.totalDistance, 133505.6100000143) // Total Kms
106
- }).timeout(20000)
106
+ },20000)
107
107
  it('Location by device', async () => {
108
108
  const report = await getReports()
109
109
  const userData = await report.getUserData()
@@ -115,7 +115,7 @@ describe('Test_Reports', function() {
115
115
  assert.equal(data.length, 1)
116
116
  const device = data[0].devices.find(d => d.device.id===22326)
117
117
  assert.equal(device.positions.length, 708) // Total Positions
118
- }).timeout(20000)
118
+ },20000)
119
119
  it('KmsReport by device', async () => {
120
120
  const reports = await getReports()
121
121
  const userData = await reports.getUserData()
@@ -125,7 +125,7 @@ describe('Test_Reports', function() {
125
125
  assert.equal(data.length, 1)
126
126
  const device = data[0].devices.find(d => d.device.id===22326)
127
127
  assert.equal(device.summary.distance, 1193284.3100000024) // Total Kms
128
- }).timeout(20000)
128
+ },20000)
129
129
  it('KmsReport byDevice groupByDay', async () => {
130
130
  const reports = await getReports()
131
131
  const userData = await reports.getUserData()
@@ -137,7 +137,7 @@ describe('Test_Reports', function() {
137
137
  const device = data[0].devices.find(d => d.device.id===22326)
138
138
  assert.equal(device.days.length, 10) // Total Kms
139
139
  assert.equal(device.days[5].kms, 23183.010000005364) // Total Kms
140
- }).timeout(20000)
140
+ },20000)
141
141
  it('Idle by device', async () => {
142
142
  const report = await getReports()
143
143
  const userData = await report.getUserData()
@@ -150,7 +150,7 @@ describe('Test_Reports', function() {
150
150
  const totalIdleTime = device.idleEvents.reduce((a, b) => a + b.idleTime, 0)
151
151
  assert.equal(device.idleEvents.length, 8) // Total Alerts
152
152
  assert.equal(totalIdleTime, 1294000) // Total Duration
153
- }).timeout(20000)
153
+ },20000)
154
154
  it('Activity by device', async () => {
155
155
  const report = await getReports()
156
156
  const userData = await report.getUserData()
@@ -162,7 +162,7 @@ describe('Test_Reports', function() {
162
162
  const device = data[0].devices.find(d => d.device.id===22326)
163
163
  assert.equal(device.summary[0].startOdometer, 122502742.59)
164
164
  assert.equal(device.summary[0].distance, 1386519.1300000101)
165
- }).timeout(20000)
165
+ }, 20000)
166
166
  it('Activity byDevice groupByDay', async () => {
167
167
  const report = await getReports()
168
168
  const userData = await report.getUserData()
@@ -174,7 +174,7 @@ describe('Test_Reports', function() {
174
174
  const device = data[0].devices.find(d => d.device.id===22326)
175
175
  assert.equal(device.summary[5].startOdometer, 122923290.95)
176
176
  assert.equal(device.summary[5].distance, 77020.37999999523)
177
- }).timeout(40000)
177
+ }, 40000)
178
178
  it('test allinone', async() => {
179
179
  console.log('Start')
180
180
  const reports = await getReports()
@@ -188,5 +188,6 @@ describe('Test_Reports', function() {
188
188
  true,
189
189
  false)
190
190
  assert.equal(r.trips.length, 10)
191
- }).timeout(20000)
191
+ assert.equal(r.stops.length, 11)
192
+ }, 20000)
192
193
  })
@@ -84,8 +84,8 @@ async function getAllInOne(traccar, from, to, devices, getRoutes, getTrips, getS
84
84
  return {
85
85
  route: result.filter(t => t.route).map(r => r.route).flat(),
86
86
  trips: result.filter(t => t.trips).map(r => r.trips).flat(),
87
- stops: result.filter(t => t.result).map(r => r.stops).flat(),
88
- summary: result.filter(t => t.summay).map(r => r.summary).flat(),
87
+ stops: result.filter(t => t.stops).map(r => r.stops).flat(),
88
+ summary: result.filter(t => t.summary).map(r => r.summary).flat(),
89
89
  }
90
90
  }
91
91
 
package/src/here.test.js DELETED
@@ -1,25 +0,0 @@
1
- const here = require('./here')
2
-
3
- require('axios-debug-log')({
4
- request: function (debug, config) {
5
- console.log('Req headers:', config.headers.common)
6
- },
7
- response: function (debug, response) {
8
- console.log(
9
- 'Response Headers:', response.headers,
10
- 'from', response.config.url
11
- )
12
- },
13
- error: function (debug, error) {
14
- // Read https://www.npmjs.com/package/axios#handling-errors for more info
15
- console.error('Boom', error)
16
- }
17
- })
18
-
19
- describe('here', async () => {
20
- it('here', async () => {
21
- console.log(process.env.HERE_API_KEY)
22
- const rows = [{latitude:0, longitude:0, fixtime:new Date().toISOString(), speed:0, course:0}]
23
- console.dir(await here.routeMatch(rows), {depth: null})
24
- })
25
- })