fleetmap-reports 1.0.756 → 1.0.757

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.756",
3
+ "version": "1.0.757",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -22,8 +22,8 @@ async function createPerformanceReport (from, to, userData, traccar) {
22
22
  deviceTrips.push(uncompletedTrip)
23
23
  }
24
24
 
25
- const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m))
26
- const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m))
25
+ const endTripData = getEndTripMessages(deviceRoute).map(m => parseEndTripMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
26
+ const canDriverStyle = getCanDriverStyleMessages(deviceRoute).map(m => parseCanDriverStyleMessage(m.xpertString || m)).sort((a, b) => a.date.localeCompare(b.date))
27
27
 
28
28
  const deviceData = {
29
29
  device: d.name,
@@ -69,4 +69,20 @@ describe('zones', function () {
69
69
  assert.equal(first.distanceIn, 93.03917199839687)
70
70
  assert.equal(first.distanceOut, 819.6685737216337)
71
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)
72
88
  })
package/src/util/xpert.js CHANGED
@@ -2,6 +2,7 @@ function parseEndTripMessage (xpertMessage) {
2
2
  const data = xpertMessage.split(',')
3
3
 
4
4
  return {
5
+ date: data[1],
5
6
  totalDistanceTravelled: Number(data[2]),
6
7
  totalDistanceTravelledWithCruiseControl: Number(data[3]),
7
8
  totalFuelConsumption: Number(data[4]),
@@ -22,6 +23,7 @@ function parseCanDriverStyleMessage (xpertMessage) {
22
23
  const data = xpertMessage.split(',')
23
24
 
24
25
  return {
26
+ date: data[1],
25
27
  totalFuelConsumptionInEcoRange: Number(data[2]),
26
28
  totalTimeInEcoRange: Number(data[3]),
27
29
  totalDistanceInEcoRange: Number(data[4]),
@@ -70,8 +70,13 @@ 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 = await parallel('zone-report', 'getInAndOutEvents', slice, cleanPositions(route), userData)
74
- allData.devices.push(...await processDevices(from, to, devices, userData, { alerts, 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 }))
75
80
 
76
81
  deviceCount = deviceCount + slice.length
77
82
  }
@@ -98,7 +103,7 @@ async function processDevices (from, to, devices, userData, data) {
98
103
 
99
104
  const zoneInOutData = analyseAlerts(alerts, deviceRoute, userData, from, to).filter(d => !userData.onlyWithStop || d.stopped)
100
105
 
101
- if (userData.groupByDay) {
106
+ if (userData.groupByDay || userData.zonesByColumn) {
102
107
  const dates = getDates(from, to, userData.user.attributes.timezone)
103
108
 
104
109
  const geofencesData = []
@@ -175,13 +180,45 @@ async function processDevices (from, to, devices, userData, data) {
175
180
  })
176
181
  }
177
182
 
178
- devicesResult.push({
179
- device: d,
180
- from,
181
- to,
182
- groupByDay: true,
183
- geofences: geofencesData
184
- })
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
+ }
185
222
  } else {
186
223
  if (zoneInOutData.length > 0) {
187
224
  devicesResult.push({