fleetmap-reports 2.0.382 → 2.0.383
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
|
@@ -12,6 +12,8 @@ const { calculateConsumption, calculateTotalFuelFromSensor, shouldUseFuelSensor
|
|
|
12
12
|
const { getSummary } = require('./util/traccar')
|
|
13
13
|
const { calculatePartialTrip } = require('./util/trips')
|
|
14
14
|
|
|
15
|
+
const CHUNK_BOUNDARY_BUFFER_MS = 24 * 60 * 60 * 1000
|
|
16
|
+
|
|
15
17
|
function getReportTimezone (userData) {
|
|
16
18
|
const tz = userData.user.attributes.timezone || getUserPartner(userData.user).timezone
|
|
17
19
|
try {
|
|
@@ -151,8 +153,20 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
|
151
153
|
|
|
152
154
|
for (let chunkIndex = 0; chunkIndex < dateGroups.length; chunkIndex++) {
|
|
153
155
|
const dates = dateGroups[chunkIndex]
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
+
const chunkFromBase = chunkIndex === 0 ? from : getDayWindow(dates[0], timezone)[0]
|
|
157
|
+
const chunkToBase = chunkIndex === dateGroups.length - 1 ? to : getDayWindow(dates[dates.length - 1], timezone)[1]
|
|
158
|
+
|
|
159
|
+
// A trip in progress across a chunk boundary would otherwise come back from Traccar
|
|
160
|
+
// truncated to the request window, bypassing the day-boundary proration below (which
|
|
161
|
+
// only triggers when the trip's real end/start still extends past dayStart/dayEnd) -
|
|
162
|
+
// making a day's consumption depend on which chunk it happened to land in. Widening
|
|
163
|
+
// only the internal boundaries (never the report's actual from/to) by a day-long
|
|
164
|
+
// buffer ensures such a trip is always fetched whole here, so it goes through the same
|
|
165
|
+
// getReportDataByDay/calculatePartialTrip proration as any other cross-midnight trip.
|
|
166
|
+
// The date-by-date loop below still only processes this chunk's own `dates`, so no day
|
|
167
|
+
// is ever double-counted.
|
|
168
|
+
const chunkFrom = chunkIndex === 0 ? chunkFromBase : new Date(chunkFromBase.getTime() - CHUNK_BOUNDARY_BUFFER_MS)
|
|
169
|
+
const chunkTo = chunkIndex === dateGroups.length - 1 ? chunkToBase : new Date(chunkToBase.getTime() + CHUNK_BOUNDARY_BUFFER_MS)
|
|
156
170
|
|
|
157
171
|
const allInOne = await traccarHelper.getAllInOne(traccar, chunkFrom, chunkTo, devices, true, true, true, false)
|
|
158
172
|
const summary = await getReportSummaryByDay(dates, userData, traccar, devices, timezone, from, to, firstDate, lastDate)
|