fleetmap-reports 1.0.250 → 1.0.255

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.
@@ -0,0 +1,23 @@
1
+ const traccar = require("./traccar");
2
+
3
+ const minDistance = 0
4
+ const minAvgSpeed = 0
5
+
6
+ async function checkTripsKms(traccarInstance, from, to, routeData, tripsData, devices) {
7
+ console.log('checkTripsKms')
8
+ const trips = tripsData.filter(t => t.distance === minDistance && t.averageSpeed > minAvgSpeed)
9
+ if(trips.length > 0) {
10
+ //Vehicles with imported positions. calculate trip distance with route positions
11
+ const route = routeData.length === 0 ? await traccar.getRoute(traccarInstance, from, to, devices) : routeData
12
+ trips.forEach(t => {
13
+ if(t.distance === minDistance && t.averageSpeed > minAvgSpeed) {
14
+ const tripRoute = route.filter(p => p.deviceId === t.deviceId
15
+ && new Date(p.fixTime).getTime() >= new Date(t.startTime).getTime()
16
+ && new Date(p.fixTime).getTime() <= new Date(t.endTime).getTime())
17
+ t.distance = tripRoute.reduce((a, b) => a + b.attributes.distance, 0)
18
+ }
19
+ })
20
+ }
21
+ }
22
+
23
+ exports.checkTripsKms = checkTripsKms
package/src/util/utils.js CHANGED
@@ -31,7 +31,7 @@ function coordsDistance(lon1, lat1, lon2, lat2) {
31
31
 
32
32
  function getDates(startDate, endDate) {
33
33
  const dates = []
34
- let currentDate = startDate
34
+ let currentDate = new Date(startDate.toISOString().split('T')[0] + ' 12:00 PM')
35
35
  const addDays = function (days) {
36
36
  const date = new Date(this.valueOf())
37
37
  date.setDate(date.getDate() + days)