fleetmap-reports 2.0.34 → 2.0.36

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": "2.0.34",
3
+ "version": "2.0.36",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -32,9 +32,9 @@ describe('zones', function () {
32
32
  const userData = await report.getUserData()
33
33
  userData.tripsBetweenZones = true
34
34
  const result = await report.zoneReport(
35
- new Date(Date.UTC(2024, 0, 8, 0, 0, 0, 0)),
36
- new Date(Date.UTC(2024, 0, 8, 23, 59, 59, 0)),
37
- userData)
35
+ new Date(Date.UTC(2024, 0, 8, 0, 0, 0, 0)),
36
+ new Date(Date.UTC(2024, 0, 8, 23, 59, 59, 0)),
37
+ userData)
38
38
  console.log('result', result)
39
39
  }, 4000000)
40
40
 
@@ -135,11 +135,28 @@ describe('zones', function () {
135
135
  g.name === 'baliza 2 - raio amarelo')
136
136
  userData.onlyWithKmsOut = false
137
137
  const result = await report.zoneReport(
138
- new Date(Date.UTC(2023, 8, 3, 0, 0, 0, 0)),
139
- new Date(Date.UTC(2023, 8, 10, 23, 59, 59, 0)),
140
- userData)
138
+ new Date(Date.UTC(2023, 8, 3, 0, 0, 0, 0)),
139
+ new Date(Date.UTC(2023, 8, 10, 23, 59, 59, 0)),
140
+ userData)
141
+ const first = result[0].devices[0]
142
+ console.log(first)
143
+ assert.equal(first.days[1].distanceOut, 298.9872662595749)
144
+ }, 4000000)
145
+
146
+ it('works with casais zones in columns 6', async () => {
147
+ const report = await getReports()
148
+ const userData = await report.getUserData()
149
+ userData.zonesByColumn = true
150
+ userData.devices = userData.devices.filter(d => d.id === 81166)
151
+ userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde ' ||
152
+ g.name === 'baliza 2 - raio amarelo')
153
+ userData.onlyWithKmsOut = false
154
+ const result = await report.zoneReport(
155
+ new Date(Date.UTC(2023, 9, 1, 0, 0, 0, 0)),
156
+ new Date(Date.UTC(2023, 9, 27, 23, 59, 59, 0)),
157
+ userData)
141
158
  const first = result[0].devices[0]
142
159
  console.log(first)
143
- assert.equal(first.days[1].distanceOut, 347.06754247750894)
160
+ assert.equal(first.days[6].distanceOut, 867.0554430738234)
144
161
  }, 4000000)
145
162
  })
@@ -6,20 +6,13 @@ const { isInsideTimetable, isPartialInsideTimetable } = require('./trips')
6
6
  // get devices used by each driver between two dates
7
7
  async function devicesByDriver (traccarInstance, from, to, drivers, devices) {
8
8
  const eventsData = await traccar.getEvents(traccarInstance, from, to, devices, ['driverChanged'])
9
- const deviceIds = []
10
- const driversIds = []
11
- for (const d of drivers) {
12
- const events = eventsData.filter(e => {
13
- return !d.uniqueId.localeCompare(e.attributes.driverUniqueId, undefined, { sensitivity: 'base' })
14
- })
15
-
16
- if (events.length) {
17
- driversIds.push(d.id)
18
- }
9
+ const driverUniqueIdsToProcess = new Set(eventsData.map(e => e.attributes.driverUniqueId))
10
+ const driversToProcess = drivers.filter(d => driverUniqueIdsToProcess.has(d.uniqueId))
19
11
 
20
- deviceIds.push(...events.map(e => e.deviceId))
21
- }
22
- return { devices: devices.filter(d => deviceIds.includes(d.id)), drivers: drivers.filter(d => driversIds.includes(d.id)) }
12
+ const deviceIdsToProcess = new Set(eventsData.map(e => e.deviceId))
13
+ const devicesToProcess = devices.filter(d => deviceIdsToProcess.has(d.id))
14
+
15
+ return { devices: devicesToProcess, drivers: driversToProcess }
23
16
  }
24
17
 
25
18
  async function reportByDriver (devices, traccar, from, to, userData, processor, allInOneData = { route: true, trips: true, stops: true, summary: false }) {
@@ -36,7 +36,7 @@ async function createZoneReport (from, to, userData, traccar) {
36
36
  }
37
37
 
38
38
  const serverHost = isClientSide() && newDomains.includes(window.location.hostname)
39
- ? window.location.hostname
39
+ ? `${window.location.hostname}/pinmeapi`
40
40
  : process.env.SERVER_HOST
41
41
 
42
42
  if (isClientSide()) {
@@ -332,6 +332,7 @@ function calculateDistanceIn (zoneInOutDayData, deviceRoute, dayRoute, fromByDay
332
332
 
333
333
  function calculateDistanceOut (zoneInOutDayData, dayRoute, fromByDay, toByDay, field, device) {
334
334
  if (zoneInOutDayData.length) {
335
+ zoneInOutDayData.sort((a, b) => (a.inTime ? new Date(a.inTime.fixTime).getTime() : 0) - (b.inTime ? new Date(b.inTime.fixTime).getTime() : 0))
335
336
  const dataInsideDay = zoneInOutDayData.filter(z => z.outTime && new Date(z.outTime.fixTime) < toByDay)
336
337
  let distanceOut = dataInsideDay.reduce((a, b) => a + (b[field] || 0), 0)
337
338