fleetmap-reports 1.0.733 → 1.0.735

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.733",
3
+ "version": "1.0.735",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,25 +1,50 @@
1
- async function createPerformanceReport (from, to, userData, traccarInstance) {
1
+ const automaticReports = require('../automaticReports')
2
+ const traccarHelper = require('../util/traccar')
3
+ const { getUncompletedTrip } = require('../util/trips')
4
+
5
+ async function createPerformanceReport (from, to, userData, traccar) {
2
6
  const reportData = []
3
- userData.devices.forEach(d => {
4
- const deviceData = {
5
- device: d.name,
6
- drivingTime: 850000,
7
- idleTime: 200000,
8
- drivingConsumption: 20,
9
- idleConsumption: 10,
10
- drivingDistance: 10000,
11
- economicTime: 265000,
12
- economicConsumption: 5,
13
- economicDistance: 99000,
14
- cruiseControlTime: 0,
15
- cruiseControlConsumption: 0,
16
- cruiseControlDistance: 0,
17
- highMotorRPM: 66000,
18
- hardBreaking: 10,
19
- hardAcceleration: 5
20
- }
21
- reportData.push(deviceData)
22
- })
7
+
8
+ const devices = userData.devices
9
+ const sliced = automaticReports.sliceArray(devices, 5)
10
+
11
+ let deviceCount = 0
12
+ for (const slice of sliced) {
13
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, true, false, deviceCount, devices.length)
14
+
15
+ slice.forEach(d => {
16
+ const deviceRoute = allInOne.route.filter(t => t.deviceId === d.id)
17
+ const deviceTrips = allInOne.trips.filter(t => t.deviceId === d.id)
18
+ const deviceStops = allInOne.stops.filter(t => t.deviceId === d.id)
19
+
20
+ const uncompletedTrip = getUncompletedTrip(d, deviceRoute, deviceTrips)
21
+ if (uncompletedTrip) {
22
+ deviceTrips.push(uncompletedTrip)
23
+ }
24
+
25
+ const deviceData = {
26
+ device: d.name,
27
+ drivingTime: deviceTrips.reduce((a, b) => a + b.duration, 0),
28
+ idleTime: deviceTrips.reduce((a, b) => a + b.idleTime, 0) +
29
+ deviceStops.reduce((a, b) => a + b.engineHours, 0),
30
+ drivingConsumption: 20,
31
+ idleConsumption: 10,
32
+ drivingDistance: deviceTrips.reduce((a, b) => a + b.distance, 0),
33
+ economicTime: 265000,
34
+ economicConsumption: 5,
35
+ economicDistance: 99000,
36
+ cruiseControlTime: 0,
37
+ cruiseControlConsumption: 0,
38
+ cruiseControlDistance: 0,
39
+ highEngineRPM: 66000,
40
+ hardBreaking: 10,
41
+ hardAcceleration: 5
42
+ }
43
+ reportData.push(deviceData)
44
+ })
45
+
46
+ deviceCount = deviceCount + slice.length
47
+ }
23
48
  return reportData
24
49
  }
25
50
 
@@ -2,6 +2,7 @@ const { getReports } = require('./index')
2
2
  const assert = require('assert')
3
3
  // eslint-disable-next-line no-undef
4
4
  describe('zones', function () {
5
+ this.timeout(500000)
5
6
  // eslint-disable-next-line no-undef
6
7
  it('works with ellca', async () => {
7
8
  const report = await getReports()
@@ -10,7 +10,10 @@ const { headerFromUser, addTable } = require('./util/pdfDocument')
10
10
  const { getStyle } = require('./reportStyle')
11
11
  const traccarHelper = require('./util/traccar')
12
12
  const trips = require('./util/trips')
13
- const { isInsideTimetable, isPartialInsideTimetable, calculateTrip, getTripIdleTime, calculateStopDuration } = require('./util/trips')
13
+ const {
14
+ isInsideTimetable, isPartialInsideTimetable, getTripIdleTime, calculateStopDuration,
15
+ getUncompletedTrip
16
+ } = require('./util/trips')
14
17
  const { devicesToProcess, deviceName } = require('./util/device')
15
18
  const { getIdleEvents } = require('./util/route')
16
19
  const { reportByDriver, getDriverName, getDriverData } = require('./util/driver')
@@ -152,11 +155,9 @@ function processDevices (from, to, devices, data, userData, traccar) {
152
155
  const deviceRoute = data.route.filter(t => t.deviceId === d.id)
153
156
  const deviceTrips = data.trips.filter(t => t.deviceId === d.id)
154
157
 
155
- if (deviceRoute.length && deviceTrips.length && deviceRoute[deviceRoute.length - 1].attributes.ignition) {
156
- const uncompletedTripRoute = deviceRoute.filter(p => p.attributes.ignition && new Date(p.fixTime).getTime() > new Date(deviceTrips[deviceTrips.length - 1].endTime).getTime())
157
- if (uncompletedTripRoute.length) {
158
- deviceTrips.push(calculateTrip(d, uncompletedTripRoute))
159
- }
158
+ const uncompletedTrip = getUncompletedTrip(d, deviceRoute, deviceTrips)
159
+ if (uncompletedTrip) {
160
+ deviceTrips.push(uncompletedTrip)
160
161
  }
161
162
 
162
163
  const trips = deviceTrips.filter(t => userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
package/src/util/trips.js CHANGED
@@ -104,6 +104,15 @@ function updateTrip (t, route) {
104
104
  t.averageSpeed = distance > 0 ? ((route.reduce((a, b) => a + b.speed, 0)) / route.length) : 0
105
105
  }
106
106
 
107
+ function getUncompletedTrip (device, deviceRoute, deviceTrips) {
108
+ if (deviceRoute.length && deviceTrips.length && deviceRoute[deviceRoute.length - 1].attributes.ignition) {
109
+ const uncompletedTripRoute = deviceRoute.filter(p => p.attributes.ignition && new Date(p.fixTime).getTime() > new Date(deviceTrips[deviceTrips.length - 1].endTime).getTime())
110
+ if (uncompletedTripRoute.length) {
111
+ return calculateTrip(device, uncompletedTripRoute)
112
+ }
113
+ }
114
+ }
115
+
107
116
  function calculateTrip (device, route) {
108
117
  const startPos = route[0]
109
118
  const endPos = route[route.length - 1]
@@ -153,3 +162,4 @@ exports.isPartialInsideTimetable = isPartialInsideTimetable
153
162
  exports.calculateTrip = calculateTrip
154
163
  exports.getTripIdleTime = getTripIdleTime
155
164
  exports.calculateStopDuration = calculateStopDuration
165
+ exports.getUncompletedTrip = getUncompletedTrip
package/src/util/utils.js CHANGED
@@ -110,7 +110,8 @@ function getDates (startDate, endDate, timezone) {
110
110
  const dates = []
111
111
  let currentDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate(), 12, 0, 0, 0)
112
112
  if (!isClientSide() && timezone) {
113
- currentDate = convertFromUTC(currentDate, timezone)
113
+ const startDateUserTimezone = convertFromUTC(startDate, timezone)
114
+ currentDate = new Date(startDateUserTimezone.getFullYear(), startDateUserTimezone.getMonth(), startDateUserTimezone.getDate(), 12, 0, 0, 0)
114
115
  }
115
116
  const addDays = function (days) {
116
117
  const date = new Date(this.valueOf())