fleetmap-reports 1.0.353 → 1.0.354

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.353",
3
+ "version": "1.0.354",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -85,7 +85,7 @@ async function createActivityReportByDevice(from, to, userData, traccarInstance)
85
85
  devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
86
86
 
87
87
  let summaries = []
88
- const {trips, route, summary} = await traccar.getAllInOne(traccarInstance, from, to, devicesToProcess, userData.groupByDay && !userData.allWeek, true, false, !userData.groupByDay)
88
+ const {trips, route, summary} = await traccar.getAllInOne(traccarInstance, from, to, devicesToProcess, true, true, false, !userData.groupByDay)
89
89
 
90
90
  if(userData.groupByDay) {
91
91
  console.log('trips:' + trips.length)
@@ -142,6 +142,15 @@ async function createActivityReportByDriver(from, to, userData, traccarInstance)
142
142
  }
143
143
 
144
144
 
145
+ function getActivityEnd(deviceTrips, deviceRoute) {
146
+ const route = deviceRoute.filter(p => p.attributes.ignition)
147
+ const tripEndDate = deviceTrips.length && deviceTrips[deviceTrips.length-1].endTime
148
+ if(route.length && new Date(route[route.length-1].fixTime).getTime() > new Date(tripEndDate).getTime()) {
149
+ return route[route.length-1].fixTime
150
+ }
151
+ return tripEndDate
152
+ }
153
+
145
154
  function processDevices(from, to, devices, data, userData) {
146
155
  const devicesResult = []
147
156
 
@@ -195,10 +204,12 @@ function processDevices(from, to, devices, data, userData) {
195
204
  if (summary.length) {
196
205
  summary.forEach(s => {
197
206
  const deviceTrips = data.trips.filter(t => t.deviceId === d.id)
207
+ const deviceRoute = data.route.filter(t => t.deviceId === d.id)
208
+
198
209
  s.distance = deviceTrips.reduce((a, b) => a + b.distance, 0)
199
210
  s.convertedSpentFuel = automaticReports.calculateSpentFuel(s.spentFuel, d)
200
211
  s.startTime = deviceTrips.length && deviceTrips[0].startTime
201
- s.endTime = deviceTrips.length && deviceTrips[deviceTrips.length-1].endTime
212
+ s.endTime = getActivityEnd(deviceTrips, deviceRoute)
202
213
  })
203
214
  }
204
215
  }
package/src/index.test.js CHANGED
@@ -165,8 +165,20 @@ describe('Test_Reports', function() {
165
165
  assert.equal(device.summary[0].startOdometer, 122502742.59)
166
166
  assert.equal(device.summary[0].distance, 1386519.1300000101)
167
167
  assert.equal(device.summary[0].startTime, '2022-01-01T13:35:47.000+0000')
168
- assert.equal(device.summary[0].endTime, '2022-01-30T13:48:18.000+0000')
169
- }, 90000)
168
+ assert.equal(device.summary[0].endTime, '2022-01-30T14:08:13.000+0000')
169
+ }, 40000)
170
+ it('Activity 2 by device', async () => {
171
+ const report = await getReports()
172
+ const userData = await report.getUserData()
173
+ userData.devices = userData.devices.filter(d => d.id === 11437)
174
+ const data = await report.activityReport(new Date(2022, 2, 5, 0, 0, 0, 0),
175
+ new Date(2022, 2, 5, 23, 59, 59, 0),
176
+ userData)
177
+ assert.equal(data.length, 1)
178
+ const device = data[0].devices.find(d => d.device.id===11437)
179
+ assert.equal(device.summary[0].endTime, '2022-03-05T23:59:55.000+0000')
180
+
181
+ }, 40000)
170
182
  it('Activity byDevice groupByDay', async () => {
171
183
  const report = await getReports()
172
184
  const userData = await report.getUserData()