fleetmap-reports 1.0.769 → 1.0.770

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.769",
3
+ "version": "1.0.770",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -55,6 +55,12 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
55
55
  new Map()
56
56
  )
57
57
 
58
+ route.forEach(p => { p.startDate = p.fixTime.substring(0, 10) })
59
+ const groupedRouteByDay = route.reduce(
60
+ (entryMap, e) => entryMap.set(e.startDate, [...entryMap.get(e.startDate) || [], e]),
61
+ new Map()
62
+ )
63
+
58
64
  const days = []
59
65
  const keys = Array.from(groupedTripsByDay.keys())
60
66
 
@@ -63,7 +69,7 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
63
69
  const dayTrips = groupedTripsByDay.get(day)
64
70
  const dayRefueling = groupedRefuelingsByDay.get(day)
65
71
  const distance = dayTrips.reduce((a, b) => a + b.distance, 0)
66
- const spentFuel = calculateConsumption(userData, d, day, odooAvgConsumption, { trips: dayTrips, route })
72
+ const spentFuel = calculateConsumption(userData, d, day, odooAvgConsumption, { trips: dayTrips, route: groupedRouteByDay.get(day) })
67
73
 
68
74
  const dataRow = {
69
75
  date: day,
@@ -124,6 +130,11 @@ function calculateConsumption (userData, d, day, avgConsumption, data) {
124
130
  if (useOdooFuelData(d, data.route)) {
125
131
  return (avgConsumption.byKms * (data.trips.reduce((a, b) => a + b.distance, 0) / 1000) / 100)
126
132
  }
133
+
134
+ if (data.route.length > 1 && data.route[0].attributes.fuelUsed) {
135
+ return data.route[data.route.length - 1].attributes.fuelUsed - data.route[0].attributes.fuelUsed
136
+ }
137
+
127
138
  return automaticReports.calculateSpentFuel(data.trips.reduce((a, b) => a + b.spentFuel, 0), d)
128
139
  }
129
140
 
@@ -145,8 +145,11 @@ function getDeviceData (allInOne, d) {
145
145
  economicDistance
146
146
  }
147
147
  } else {
148
+ const drivingTime = deviceTrips.reduce((a, b) => a + b.duration, 0)
149
+ const drivingDistance = deviceTrips.reduce((a, b) => a + b.distance, 0)
150
+
148
151
  return {
149
- drivingTime: 0,
152
+ drivingTime: drivingTime,
150
153
  idleTime: 0,
151
154
  cruiseControlTime: 0,
152
155
  economicTime: 0,
@@ -157,7 +160,7 @@ function getDeviceData (allInOne, d) {
157
160
  idleConsumption: 0,
158
161
  cruiseControlConsumption: 0,
159
162
  economicConsumption: 0,
160
- drivingDistance: 0,
163
+ drivingDistance: drivingDistance,
161
164
  cruiseControlDistance: 0,
162
165
  economicDistance: 0
163
166
  }
@@ -194,8 +194,7 @@ describe('Test_Reports', function () {
194
194
  userData)
195
195
  assert.equal(data.length, 1)
196
196
  const device = data[0].devices.find(d => d.device.id === 69114)
197
- console.log(device)
198
- assert.equal(device.days.reduce((a, b) => a + b.spentFuel, 0), 153.7)
197
+ assert.equal(device.days.reduce((a, b) => a + b.spentFuel, 0), 168.91999999999985)
199
198
  }, 30000)
200
199
  // eslint-disable-next-line no-undef
201
200
  it('Zone Report', async () => {