fleetmap-reports 1.0.761 → 1.0.763

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.761",
3
+ "version": "1.0.763",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -2,14 +2,15 @@ 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)
5
6
  // eslint-disable-next-line no-undef
6
7
  it('performance report', async () => {
7
8
  const report = await getReports()
8
9
  const userData = await report.getUserData()
9
- userData.devices = userData.devices.filter(d => d.attributes.xpert)
10
+ userData.devices = userData.devices.filter(d => d.id === 128270)
10
11
  const data = await createPerformanceReport(
11
- new Date(Date.UTC(2023, 5, 10, 0, 0, 0, 0)),
12
- new Date(Date.UTC(2023, 5, 20, 23, 59, 59, 0)),
12
+ new Date(Date.UTC(2023, 5, 29, 0, 0, 0, 0)),
13
+ new Date(Date.UTC(2023, 5, 30, 23, 59, 59, 0)),
13
14
  userData,
14
15
  report.traccar)
15
16
  console.log(data)
@@ -2,6 +2,7 @@ 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)
5
6
  // eslint-disable-next-line no-undef
6
7
  it('works with ellca', async () => {
7
8
  const report = await getReports()
@@ -63,4 +64,41 @@ describe('zones', function () {
63
64
  console.log(first)
64
65
  assert.equal(first.distanceOut, 0.0009407267222226043)
65
66
  }, 4000000)
67
+
68
+ // eslint-disable-next-line no-undef
69
+ it('works with casais 2', async () => {
70
+ const report = await getReports('mario.andre.moreira@casais.gi', 'Casais.23')
71
+ const userData = await report.getUserData()
72
+ userData.groupByDay = true
73
+ userData.devices = userData.devices.filter(d => d.name === 'G-2542-F Fiat Tipo')
74
+ userData.geofences = userData.geofences.filter(g => g.name === 'baliza raio verde ')
75
+ assert.equal(userData.geofences.length > 0, true)
76
+ assert.equal(userData.devices.length > 0, true)
77
+ const result = await report.zoneReport(
78
+ new Date(2023, 1, 27, 0, 0, 0, 0),
79
+ new Date(2023, 1, 27, 23, 59, 59, 0),
80
+ userData)
81
+ assert.equal(result[0].devices[0].geofences.length, 1)
82
+ assert.equal(result[0].devices[0].geofences[0].days.length, 1)
83
+ const first = result[0].devices[0].geofences[0].days[0]
84
+ assert.equal(first.firstIn, '2023-02-27T21:53:16.000+0000')
85
+ assert.equal(first.distanceIn, 93.03917199839687)
86
+ assert.equal(first.distanceOut, 819.6685737216337)
87
+ }, 4000000)
88
+
89
+ it('works with casais 3', async () => {
90
+ const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
91
+ const userData = await report.getUserData()
92
+ userData.zonesByColumn = true
93
+ userData.devices = userData.devices.filter(d => d.name === 'G-1101-E Clio')
94
+ userData.geofences = userData.geofences.filter(g => g.name === 'baliza raio verde ' || g.name === 'baliza raio amarelo ')
95
+ const result = await report.zoneReport(
96
+ new Date(Date.UTC(2023, 0, 29, 0, 0, 0, 0)),
97
+ new Date(Date.UTC(2023, 0, 31, 23, 59, 59, 0)),
98
+ userData)
99
+ const first = result[0].devices[0].geofences[0]
100
+ console.log(first)
101
+ assert.equal(first.name, 'baliza raio verde ')
102
+ assert.equal(first.distanceIn, '1069.343491503579')
103
+ }, 4000000)
66
104
  })
@@ -131,7 +131,7 @@ async function processDevices (from, to, devices, userData, data) {
131
131
  geofencesData.push({
132
132
  geofenceId: geofence.id,
133
133
  geofenceName: geofence.name,
134
- days: dataByDay
134
+ days: userData.onlyWithKmsOut ? dataByDay.filter(d => d.distanceOut) : dataByDay
135
135
  })
136
136
  }
137
137
 
@@ -154,12 +154,14 @@ async function processDevices (from, to, devices, userData, data) {
154
154
  }
155
155
  })
156
156
 
157
- if (distanceOut || geofences.filter(g => g.distanceIn).length) {
158
- groupByDay.push({
159
- date,
160
- geofences,
161
- distanceOut
162
- })
157
+ if (distanceOut > 0.01 || geofences.filter(g => g.distanceIn > 0.01).length) {
158
+ if (!userData.onlyWithKmsOut || distanceOut) {
159
+ groupByDay.push({
160
+ date,
161
+ geofences,
162
+ distanceOut
163
+ })
164
+ }
163
165
  }
164
166
  }
165
167
 
@@ -187,7 +189,7 @@ async function processDevices (from, to, devices, userData, data) {
187
189
  device: d,
188
190
  from,
189
191
  to,
190
- geofences: zoneInOutData
192
+ geofences: userData.onlyWithKmsOut ? zoneInOutData.filter(a => a.distanceOut) : zoneInOutData
191
193
  })
192
194
  }
193
195
  }
@@ -237,7 +239,7 @@ function calculateDistanceIn (zoneInOutDayData, deviceRoute, dayRoute, fromByDay
237
239
  if (zoneInOutDayData.length) {
238
240
  // Check if the first entry starts only on the day before
239
241
  if (!zoneInOutDayData[0].inTime || new Date(zoneInOutDayData[0].inTime.fixTime) < fromByDay) {
240
- const routeDayBefore = deviceRoute.filter(p => (!zoneInOutDayData[0].inTime || new Date(p.fixTime) >= new Date(zoneInOutDayData[0].inTime.fixTime)) &&
242
+ const routeDayBefore = deviceRoute.filter(p => (!zoneInOutDayData[0].inTime || (new Date(p.fixTime) >= new Date(zoneInOutDayData[0].inTime.fixTime))) &&
241
243
  new Date(p.fixTime) < fromByDay)
242
244
  distanceIn = distanceIn - calculateDistance(routeDayBefore)
243
245
  }
@@ -245,7 +247,7 @@ function calculateDistanceIn (zoneInOutDayData, deviceRoute, dayRoute, fromByDay
245
247
  // Check if the last entry ends only on the next day
246
248
  if (!zoneInOutDayData[zoneInOutDayData.length - 1].outTime || new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime) > toByDay) {
247
249
  const outTime = zoneInOutDayData[zoneInOutDayData.length - 1].outTime ? new Date(zoneInOutDayData[zoneInOutDayData.length - 1].outTime.fixTime) : to
248
- const routeDayAfter = deviceRoute.filter(p => new Date(p.fixTime) <= outTime && new Date(p.fixTime) > toByDay)
250
+ const routeDayAfter = deviceRoute.filter(p => new Date(p.fixTime) < outTime && new Date(p.fixTime) > toByDay)
249
251
  distanceIn = distanceIn - calculateDistance(routeDayAfter)
250
252
  }
251
253
  }