fleetmap-reports 1.0.794 → 1.0.795

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.794",
3
+ "version": "1.0.795",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -188,21 +188,19 @@ function processDevices (from, to, devices, data, userData) {
188
188
  })
189
189
  }
190
190
  } else {
191
- const summaryCurrentDay = data.summaries.find(s => {
192
- return s.deviceId === d.id && s.date.getTime() === date.getTime()
193
- })
194
-
195
- if (summaryCurrentDay) {
196
- summaryCurrentDay.engineHours = tripsByDay.reduce((a, b) => a + b.duration, 0)
197
- summaryCurrentDay.distance = distance
198
- summaryCurrentDay.convertedSpentFuel = calculateConsumption(d, { route: deviceRoute, summary: summaryCurrentDay })
199
- summaryCurrentDay.startTime = tripsByDay.length && tripsByDay[0].startTime
200
- summaryCurrentDay.startAddress = tripsByDay.length && tripsByDay[0].startAddress
201
- summaryCurrentDay.endTime = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime
202
- summaryCurrentDay.endAddress = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endAddress
203
-
204
- summary.push(summaryCurrentDay)
205
- }
191
+ const summaryCurrentDay = { date, deviceId: d.id }
192
+ summaryCurrentDay.engineHours = tripsByDay.reduce((a, b) => a + b.duration, 0)
193
+ summaryCurrentDay.distance = distance
194
+ summaryCurrentDay.averageSpeed = distance > 0 ? ((trips.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / distance) : 0
195
+ summaryCurrentDay.maxSpeed = tripsByDay.reduce((a, b) => { return a > b.maxSpeed ? a : b.maxSpeed }, 0)
196
+ summaryCurrentDay.convertedSpentFuel = calculateConsumption(d, { route: deviceRoute })
197
+ summaryCurrentDay.startTime = tripsByDay.length && tripsByDay[0].startTime
198
+ summaryCurrentDay.startAddress = tripsByDay.length && tripsByDay[0].startAddress
199
+ summaryCurrentDay.endTime = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime
200
+ summaryCurrentDay.endAddress = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endAddress
201
+ summaryCurrentDay.startOdometer = trips.length ? trips[0].startOdometer : 0
202
+ summaryCurrentDay.endOdometer = trips.length ? trips[trips.length - 1].endOdometer : 0
203
+ summary.push(summaryCurrentDay)
206
204
  }
207
205
  }
208
206
  } else {
@@ -7,9 +7,9 @@ describe('activity report', function () {
7
7
  it('Activity by device', async () => {
8
8
  const report = await getReports()
9
9
  const userData = await report.getUserData()
10
-
11
- const data = await report.activityReport(new Date(2022, 0, 1, 0, 0, 0, 0),
12
- new Date(2022, 0, 31, 23, 59, 59, 0),
10
+ userData.groupByDay = true
11
+ const data = await report.activityReport(new Date(2023, 0, 1, 0, 0, 0, 0),
12
+ new Date(2023, 0, 31, 23, 59, 59, 0),
13
13
  userData)
14
14
  assert.equal(data.length, 1)
15
15
  const device = data[0].devices.find(d => d.device.id === 22326)