fleetmap-reports 1.0.610 → 1.0.612

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.610",
3
+ "version": "1.0.612",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -73,7 +73,7 @@ function processDevices (from, to, devices, data, userData) {
73
73
  const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
74
74
  const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
75
75
 
76
- const routeByDay = deviceRoute.filter(p => (new Date(p.fixTime) > fromByDay && new Date(p.fixTime) < toByDay) && p.valid && p.attributes.hours !== undefined)
76
+ const routeByDay = deviceRoute.filter(p => (new Date(p.fixTime) > fromByDay && new Date(p.fixTime) < toByDay) && p.valid)
77
77
  routeByDay.sort((a, b) => new Date(a.fixTime).getTime() - new Date(b.fixTime).getTime())
78
78
 
79
79
  const ignitions = calculateIgnitions(routeByDay)
@@ -97,10 +97,21 @@ function processDevices (from, to, devices, data, userData) {
97
97
  function getSummaryData (date, device, route, ignition, ignitions) {
98
98
  const startTime = ignition ? ignition.on.fixTime : (ignitions.length ? ignitions[0].on.fixTime : undefined)
99
99
  const endTime = ignition ? ignition.off.fixTime : (ignitions.length ? ignitions[ignitions.length - 1].off.fixTime : undefined)
100
- const engineHours = ignition
100
+ let engineHours = ignition
101
101
  ? ignition.route[ignition.route.length - 1].attributes.hours - ignition.route[0].attributes.hours
102
102
  : (ignitions ? ignitions.reduce((a, b) => a + (b.route[b.route.length - 1].attributes.hours - b.route[0].attributes.hours), 0) : undefined)
103
103
 
104
+ if (!engineHours) {
105
+ engineHours = 0
106
+ if (ignition) {
107
+ engineHours = new Date(endTime).getTime() - new Date(startTime).getTime()
108
+ } else {
109
+ ignitions.forEach(e => {
110
+ engineHours = engineHours + (new Date(e.off.fixTime).getTime() - new Date(e.on.fixTime).getTime())
111
+ })
112
+ }
113
+ }
114
+
104
115
  return {
105
116
  date,
106
117
  deviceId: device.id,
@@ -135,7 +135,7 @@ async function getEvents (traccarInstance, from, to, devices, userData, deviceCo
135
135
 
136
136
  const events = []
137
137
  if (userData.roadSpeedLimits) {
138
- const hereResults = await getHereEvents(devices, routes, userData.maxSpeedThreshold, userData.minimumIdleTime)
138
+ const hereResults = await getHereEvents(devices, routes, userData.maxSpeedThreshold, userData.minimumIdleMinutes)
139
139
  console.log('got', hereResults.length, 'from here')
140
140
  events.push(...hereResults)
141
141
  } else if (!userData.useVehicleSpeedLimit && userData.customSpeed) {
@@ -5,7 +5,6 @@ const utils = require('../util/utils')
5
5
 
6
6
  // eslint-disable-next-line no-undef
7
7
  describe('Test_Reports', function () {
8
- this.timeout(5000000)
9
8
  it('converts to pdf', async () => {
10
9
  const report = await getReports()
11
10
  const userData = await report.getUserData()
@@ -23,7 +23,7 @@ describe('speeding tests', function () {
23
23
  assert.equal(device.alerts.length, 104) // Total Alerts
24
24
  console.log(device.alerts)
25
25
 
26
- userData.minimumIdleTime = 1
26
+ userData.minimumIdleMinutes = 1
27
27
  const r = await getSpeedingReport(report, userData)
28
28
  r.device.alerts.forEach(a => assert.equal(true, a.eventTime >= 60000))
29
29
  assert.equal(r.device.alerts.length, 6) // Total Alerts