fleetmap-reports 1.0.721 → 1.0.723

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.721",
3
+ "version": "1.0.723",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -0,0 +1,26 @@
1
+ async function createPerformanceReport (from, to, userData, traccarInstance) {
2
+ const reportData = []
3
+ userData.devices.forEach(d => {
4
+ const deviceData = {
5
+ device: d.name,
6
+ drivingTime: 850000,
7
+ idleTime: 200000,
8
+ drivingConsumption: 20,
9
+ idleConsumption: 10,
10
+ drivingDistance: 10000,
11
+ economicTime: 265000,
12
+ economicConsumption: 5,
13
+ economicDistance: 99000,
14
+ cruiseControlTime: 0,
15
+ cruiseControlConsumption: 0,
16
+ cruiseControlDistance: 0,
17
+ highMotorRPM: 66000,
18
+ hardBreaking: 10,
19
+ hardAcceleration: 5
20
+ }
21
+ reportData.push(deviceData)
22
+ })
23
+ return reportData
24
+ }
25
+
26
+ exports.createPerformanceReport = createPerformanceReport
@@ -47,4 +47,26 @@ describe('zones', function () {
47
47
  assert.equal(first.inTime.fixTime, '2023-01-03T21:23:24.000+0000')
48
48
  assert.equal(first.outTime.fixTime, '2023-01-07T12:22:53.000+0000')
49
49
  }, 4000000)
50
+
51
+ // eslint-disable-next-line no-undef
52
+ it('works with casais 2', async () => {
53
+ const report = await getReports('mario.andre.moreira@casais.gi', 'Casais.23')
54
+ const userData = await report.getUserData()
55
+ userData.groupByDay = true
56
+ userData.devices = userData.devices.filter(d => d.name === 'G-2542-F Fiat Tipo')
57
+ userData.geofences = userData.geofences.filter(g => g.name === 'baliza raio verde ')
58
+ assert.equal(userData.geofences.length > 0, true)
59
+ assert.equal(userData.devices.length > 0, true)
60
+ const result = await report.zoneReport(
61
+ new Date(Date.UTC(2023, 1, 27, 0, 0, 0, 0)),
62
+ new Date(Date.UTC(2023, 1, 27, 23, 59, 59, 0)),
63
+ userData)
64
+ assert.equal(result[0].devices[0].geofences.length, 1)
65
+ assert.equal(result[0].devices[0].geofences[0].days.length, 1)
66
+ const first = result[0].devices[0].geofences[0].days[0]
67
+ console.log(first)
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)
50
72
  })
@@ -119,7 +119,8 @@ async function processDevices (from, to, devices, userData, data) {
119
119
  let distanceIn = zoneInOutDayData.length && dayRoute.length ? zoneInOutDayData.reduce((a, b) => a + (b.distanceIn || 0), 0) : 0
120
120
  let distanceOut = 0
121
121
  if (zoneInOutDayData.length) {
122
- distanceOut = zoneInOutDayData.reduce((a, b) => a + (b.distanceOut || 0), 0) - zoneInOutDayData[zoneInOutDayData.length - 1].distanceOut
122
+ distanceOut = zoneInOutDayData.reduce((a, b) => a + (b.distanceOut || 0), 0) -
123
+ (zoneInOutDayData[zoneInOutDayData.length - 1].distanceOut || 0)
123
124
  } else {
124
125
  distanceOut = calculateDistance(deviceRoute.filter(p => new Date(p.fixTime) >= fromByDay && new Date(p.fixTime) < toByDay))
125
126
  }