fleetmap-reports 1.0.757 → 1.0.758

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.757",
3
+ "version": "1.0.758",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -34,8 +34,7 @@
34
34
  "eslint-plugin-import": "^2.26.0",
35
35
  "eslint-plugin-node": "^11.1.0",
36
36
  "eslint-plugin-promise": "^6.0.0",
37
- "jest": "^27.5.0",
38
- "mocha": "^10.2.0",
37
+ "jest": "^29.6.1",
39
38
  "webpack": "^5.51.0",
40
39
  "webpack-cli": "^4.5.0"
41
40
  },
@@ -264,7 +264,6 @@ function processDevices (from, to, devices, data, userData) {
264
264
  }
265
265
 
266
266
  function processDrivers (from, to, drivers, data, userData) {
267
- console.log(data)
268
267
  const driversResult = []
269
268
  drivers.forEach(d => {
270
269
  const { route, trips } = getDriverData(d, data)
@@ -351,7 +350,6 @@ function exportActivityReportToPDFDriver (doc, translations, reportData, userDat
351
350
 
352
351
  doc.setFontSize(10)
353
352
  doc.text(convertToLocaleString(reportData.from, lang, timezone) + ' - ' + convertToLocaleString(reportData.to, lang, timezone), 20, 30)
354
- doc.text()
355
353
 
356
354
  const data = []
357
355
  reportData.drivers.forEach(d => {
@@ -0,0 +1,48 @@
1
+ // eslint-disable-next-line no-undef
2
+ const { getReports } = require('./index')
3
+ const assert = require('assert')
4
+ // eslint-disable-next-line no-undef
5
+ describe('activity report', function () {
6
+ // eslint-disable-next-line no-undef
7
+ it('Activity by device', async () => {
8
+ const report = await getReports()
9
+ const userData = await report.getUserData()
10
+
11
+ const data = await report.activityReport(new Date(2022, 0, 1, 0, 0, 0, 0),
12
+ new Date(2022, 0, 31, 23, 59, 59, 0),
13
+ userData)
14
+ assert.equal(data.length, 1)
15
+ const device = data[0].devices.find(d => d.device.id === 22326)
16
+ assert.equal(device.summary[0].startOdometer, 0)
17
+ assert.equal(device.summary[0].distance, 0)
18
+ assert.equal(device.summary[0].startTime, 0)
19
+ assert.equal(device.summary[0].endTime, 0)
20
+ }, 80000)
21
+
22
+ // eslint-disable-next-line no-undef
23
+ it('Activity by driver', async () => {
24
+ const report = await getReports('felipe@codepa.com.br', process.env.password)
25
+ const userData = await report.getUserData()
26
+ userData.byDriver = true
27
+ const data = await report.activityReport(new Date(2023, 0, 1, 0, 0, 0, 0),
28
+ new Date(2023, 0, 1, 23, 59, 59, 0),
29
+ userData)
30
+ assert.equal(data.length, 1)
31
+ await report.activityReportToPDF(userData, data[0])
32
+ }, 800000)
33
+ // eslint-disable-next-line no-undef
34
+ it('Activity byDevice groupByDay', async () => {
35
+ const report = await getReports()
36
+ const userData = await report.getUserData()
37
+ userData.groupByDay = true
38
+ const data = await report.activityReport(new Date(2022, 0, 1, 0, 0, 0, 0),
39
+ new Date(2022, 0, 20, 23, 59, 59, 0),
40
+ userData)
41
+ assert.equal(data.length, 1)
42
+ const device = data[0].devices.find(d => d.device.id === 22326)
43
+ assert.equal(device.summary[5].startOdometer, 0)
44
+ assert.equal(device.summary[5].distance, 0)
45
+ assert.equal(device.summary[5].startTime, 0)
46
+ assert.equal(device.summary[5].endTime, 0)
47
+ }, 90000)
48
+ })
@@ -16,6 +16,7 @@ axiosCookieJarSupport(axios)
16
16
 
17
17
  const getReports = async (email, password) => {
18
18
  try {
19
+ console.log('email / pass', process.env.email, process.env.password)
19
20
  await new SessionApi(traccarConfig, null, axios).sessionPost(email || process.env.email, password || process.env.password)
20
21
  return new Index(traccarConfig, axios, cookieJar)
21
22
  } catch (e) {
@@ -192,36 +192,6 @@ describe('Test_Reports', function () {
192
192
  assert.equal(totalIdleTime, 16000) // Total Duration
193
193
  }, 20000)
194
194
  // eslint-disable-next-line no-undef
195
- it('Activity by device', async () => {
196
- const report = await getReports()
197
- const userData = await report.getUserData()
198
-
199
- const data = await report.activityReport(new Date(2022, 0, 1, 0, 0, 0, 0),
200
- new Date(2022, 0, 31, 23, 59, 59, 0),
201
- userData)
202
- assert.equal(data.length, 1)
203
- const device = data[0].devices.find(d => d.device.id === 22326)
204
- assert.equal(device.summary[0].startOdometer, 122502742.59)
205
- assert.equal(device.summary[0].distance, 1425532.6071218813)
206
- assert.equal(device.summary[0].startTime, '2022-01-01T13:35:47.000+0000')
207
- assert.equal(device.summary[0].endTime, '2022-01-31T17:36:27.000+0000')
208
- }, 80000)
209
- // eslint-disable-next-line no-undef
210
- it('Activity byDevice groupByDay', async () => {
211
- const report = await getReports()
212
- const userData = await report.getUserData()
213
- userData.groupByDay = true
214
- const data = await report.activityReport(new Date(2022, 0, 1, 0, 0, 0, 0),
215
- new Date(2022, 0, 20, 23, 59, 59, 0),
216
- userData)
217
- assert.equal(data.length, 1)
218
- const device = data[0].devices.find(d => d.device.id === 22326)
219
- assert.equal(device.summary[5].startOdometer, 122923290.95)
220
- assert.equal(device.summary[5].distance, 77033.18999999762)
221
- assert.equal(device.summary[5].startTime, '2022-01-06T18:35:36.000+0000')
222
- assert.equal(device.summary[5].endTime, '2022-01-06T19:54:27.000+0000')
223
- }, 90000)
224
- // eslint-disable-next-line no-undef
225
195
  it('test allinone', async () => {
226
196
  console.log('Start')
227
197
  const reports = await getReports()
@@ -2,7 +2,6 @@ const { getReports } = require('./index')
2
2
  const { createPerformanceReport } = require('../partnerReports/performance-report')
3
3
  // eslint-disable-next-line no-undef
4
4
  describe('performance', function () {
5
- this.timeout(500000)
6
5
  // eslint-disable-next-line no-undef
7
6
  it('performance report', async () => {
8
7
  const report = await getReports()
@@ -2,7 +2,6 @@ const { getReports } = require('./index')
2
2
  const assert = require('assert')
3
3
  // eslint-disable-next-line no-undef
4
4
  describe('zones', function () {
5
- this.timeout(500000)
6
5
  // eslint-disable-next-line no-undef
7
6
  it('works with ellca', async () => {
8
7
  const report = await getReports()
@@ -48,41 +47,4 @@ describe('zones', function () {
48
47
  assert.equal(first.inTime.fixTime, '2023-01-03T21:23:24.000+0000')
49
48
  assert.equal(first.outTime.fixTime, '2023-01-07T12:22:53.000+0000')
50
49
  }, 4000000)
51
-
52
- // eslint-disable-next-line no-undef
53
- it('works with casais 2', async () => {
54
- const report = await getReports('mario.andre.moreira@casais.gi', 'Casais.23')
55
- const userData = await report.getUserData()
56
- userData.groupByDay = true
57
- userData.devices = userData.devices.filter(d => d.name === 'G-2542-F Fiat Tipo')
58
- userData.geofences = userData.geofences.filter(g => g.name === 'baliza raio verde ')
59
- assert.equal(userData.geofences.length > 0, true)
60
- assert.equal(userData.devices.length > 0, true)
61
- const result = await report.zoneReport(
62
- new Date(2023, 1, 27, 0, 0, 0, 0),
63
- new Date(2023, 1, 27, 23, 59, 59, 0),
64
- userData)
65
- assert.equal(result[0].devices[0].geofences.length, 1)
66
- assert.equal(result[0].devices[0].geofences[0].days.length, 1)
67
- const first = result[0].devices[0].geofences[0].days[0]
68
- assert.equal(first.firstIn, '2023-02-27T21:53:16.000+0000')
69
- assert.equal(first.distanceIn, 93.03917199839687)
70
- assert.equal(first.distanceOut, 819.6685737216337)
71
- }, 4000000)
72
-
73
- it('works with casais 3', async () => {
74
- const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
75
- const userData = await report.getUserData()
76
- userData.zonesByColumn = true
77
- userData.devices = userData.devices.filter(d => d.name === 'G-1101-E Clio')
78
- userData.geofences = userData.geofences.filter(g => g.name === 'baliza raio verde ' || g.name === 'baliza raio amarelo ')
79
- const result = await report.zoneReport(
80
- new Date(Date.UTC(2023, 0, 1, 0, 0, 0, 0)),
81
- new Date(Date.UTC(2023, 0, 31, 23, 59, 59, 0)),
82
- userData)
83
- const first = result[0].devices[0].geofences[0]
84
- console.log(first)
85
- assert.equal(first.name, 'baliza raio verde ')
86
- assert.equal(first.distanceIn, '1069.343491503579')
87
- }, 4000000)
88
50
  })
@@ -70,13 +70,8 @@ async function createZoneReport (from, to, userData, traccar) {
70
70
  deviceCount, devices.length, sliceSize, deviceChunk, undefined)
71
71
 
72
72
  const route = filterPositions(data.route)
73
- const alerts = []
74
- if (isClientSide()) {
75
- alerts.push(...(await getInAndOutEvents(slice, cleanPositions(route), userData)))
76
- } else {
77
- alerts.push(...(await parallel('zone-report', 'getInAndOutEvents', slice, cleanPositions(route), userData)))
78
- }
79
- allData.devices.push(...await processDevices(from, to, devices, userData, { alerts, route, summary: data.summary }))
73
+ const alerts = await parallel('zone-report', 'getInAndOutEvents', slice, cleanPositions(route), userData)
74
+ allData.devices.push(...await processDevices(from, to, devices, userData, { alerts, route }))
80
75
 
81
76
  deviceCount = deviceCount + slice.length
82
77
  }
@@ -103,7 +98,7 @@ async function processDevices (from, to, devices, userData, data) {
103
98
 
104
99
  const zoneInOutData = analyseAlerts(alerts, deviceRoute, userData, from, to).filter(d => !userData.onlyWithStop || d.stopped)
105
100
 
106
- if (userData.groupByDay || userData.zonesByColumn) {
101
+ if (userData.groupByDay) {
107
102
  const dates = getDates(from, to, userData.user.attributes.timezone)
108
103
 
109
104
  const geofencesData = []
@@ -180,45 +175,13 @@ async function processDevices (from, to, devices, userData, data) {
180
175
  })
181
176
  }
182
177
 
183
- if (userData.zonesByColumn) {
184
- const groupByDay = []
185
- for (const date of dates) {
186
- const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
187
- const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
188
-
189
- const dayRoute = deviceRoute.filter(p => new Date(p.fixTime) >= fromByDay && new Date(p.fixTime) < toByDay)
190
- const totalDistance = calculateDistance(dayRoute)
191
-
192
- const geofences = geofencesData.map(g => {
193
- return {
194
- geofenceName: g.geofenceName,
195
- distanceIn: g.days.find(day => day.date === date).distanceIn
196
- }
197
- })
198
-
199
- groupByDay.push({
200
- date,
201
- geofences,
202
- distanceOut: totalDistance - geofences.reduce((a, b) => a + (b.distanceIn || 0), 0)
203
- })
204
- }
205
-
206
- devicesResult.push({
207
- device: d,
208
- from,
209
- to,
210
- zonesByColumn: true,
211
- days: groupByDay
212
- })
213
- } else {
214
- devicesResult.push({
215
- device: d,
216
- from,
217
- to,
218
- groupByDay: true,
219
- geofences: geofencesData
220
- })
221
- }
178
+ devicesResult.push({
179
+ device: d,
180
+ from,
181
+ to,
182
+ groupByDay: true,
183
+ geofences: geofencesData
184
+ })
222
185
  } else {
223
186
  if (zoneInOutData.length > 0) {
224
187
  devicesResult.push({