fleetmap-reports 1.0.342 → 1.0.343
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 +1 -1
- package/src/index.test.js +24 -3
- package/src/util/trips.js +12 -1
package/package.json
CHANGED
package/src/index.test.js
CHANGED
|
@@ -174,7 +174,7 @@ describe('Test_Reports', function() {
|
|
|
174
174
|
const device = data[0].devices.find(d => d.device.id===22326)
|
|
175
175
|
assert.equal(device.summary[5].startOdometer, 122923290.95)
|
|
176
176
|
assert.equal(device.summary[5].distance, 77020.37999999523)
|
|
177
|
-
},
|
|
177
|
+
}, 60000)
|
|
178
178
|
it('test allinone', async() => {
|
|
179
179
|
console.log('Start')
|
|
180
180
|
const reports = await getReports()
|
|
@@ -187,7 +187,28 @@ describe('Test_Reports', function() {
|
|
|
187
187
|
true,
|
|
188
188
|
true,
|
|
189
189
|
false)
|
|
190
|
-
|
|
191
|
-
assert.equal(r.
|
|
190
|
+
|
|
191
|
+
assert.equal(r.trips.filter(t => t.deviceId === 22327).length, 10)
|
|
192
|
+
assert.equal(r.stops.filter(t => t.deviceId === 22327).length, 11)
|
|
192
193
|
}, 20000)
|
|
194
|
+
it('Total KMS', async () => {
|
|
195
|
+
const report = await getReports()
|
|
196
|
+
const userData = await report.getUserData()
|
|
197
|
+
|
|
198
|
+
const tripsReport = await report.tripReport(new Date(2022, 1, 11, 0, 0, 0, 0),
|
|
199
|
+
new Date(2022, 1, 14, 23, 59, 59, 0),
|
|
200
|
+
userData)
|
|
201
|
+
|
|
202
|
+
const kmsReport = await report.kmsReport(new Date(2022, 1, 11, 0, 0, 0, 0),
|
|
203
|
+
new Date(2022, 1, 14, 23, 59, 59, 0),
|
|
204
|
+
userData)
|
|
205
|
+
|
|
206
|
+
assert.equal(tripsReport.length, 1)
|
|
207
|
+
const device1 = tripsReport[0].devices.find(d => d.device.id===11681)
|
|
208
|
+
assert.equal(device1.trips.length, 44) // Total Trips
|
|
209
|
+
assert.equal(device1.totalDistance, 883076.9928612101) // Total Kms
|
|
210
|
+
|
|
211
|
+
const device2 = kmsReport[0].devices.find(d => d.device.id===11681)
|
|
212
|
+
assert.equal(device2.summary.distance, device1.totalDistance) // Total Kms
|
|
213
|
+
}, 30000)
|
|
193
214
|
})
|
package/src/util/trips.js
CHANGED
|
@@ -34,7 +34,18 @@ function checkTripsKms(traccarInstance, from, to, devices, data) {
|
|
|
34
34
|
const tripRoute = data.route.filter(p => p.deviceId === t.deviceId
|
|
35
35
|
&& new Date(p.fixTime).getTime() >= new Date(t.startTime).getTime()
|
|
36
36
|
&& new Date(p.fixTime).getTime() <= new Date(t.endTime).getTime())
|
|
37
|
-
|
|
37
|
+
|
|
38
|
+
let current = null
|
|
39
|
+
const distances = []
|
|
40
|
+
for(const p of tripRoute) {
|
|
41
|
+
if(current) {
|
|
42
|
+
distances.push(coordsDistance(parseFloat(current.longitude),parseFloat(current.latitude),
|
|
43
|
+
parseFloat(p.longitude),parseFloat(p.latitude)))
|
|
44
|
+
}
|
|
45
|
+
current = p
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
t.distance = distances.reduce((a, b) => a + b, 0)
|
|
38
49
|
}
|
|
39
50
|
})
|
|
40
51
|
}
|