fleetmap-reports 1.0.462 → 1.0.463

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.462",
3
+ "version": "1.0.463",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -6,6 +6,7 @@ const { headerFromUser } = require('./util/pdfDocument')
6
6
  const { getUserPartner } = require('fleetmap-partners')
7
7
  const { convertToLocaleString, getTranslations } = require('./util/utils')
8
8
  const { devicesToProcess } = require('./util/device')
9
+ const { isInside } = require('./util/timetable')
9
10
 
10
11
  const fileName = 'EventReport'
11
12
 
@@ -43,7 +44,7 @@ async function createEventsReport (from, to, userData, traccar) {
43
44
 
44
45
  if (data.length > 0) {
45
46
  reportData.push({
46
- devices: await processDevices(from, to, devices, userData.geofences, userData.drivers, data, traccar),
47
+ devices: await processDevices(from, to, devices, data, traccar, userData),
47
48
  xpert: devices.filter(d => d.attributes.xpert).length > 0
48
49
  })
49
50
  }
@@ -68,21 +69,21 @@ async function getReportData (from, to, devices, types, traccar) {
68
69
  return data
69
70
  }
70
71
 
71
- async function processDevices (from, to, devices, geofences, drivers, data, traccar) {
72
+ async function processDevices (from, to, devices, data, traccar, userData) {
72
73
  const devicesResult = []
73
74
  let i = 0
74
75
  await Promise.all(devices.map(async d => {
75
- const alerts = data.filter(t => t.deviceId === d.id)
76
+ const deviceAlerts = data.filter(t => t.deviceId === d.id)
76
77
 
77
- if (alerts.length > 0) {
78
+ if (deviceAlerts.length > 0) {
78
79
  const response = await traccar.reports.reportsRouteGet(from, to, [d.id])
79
80
  const positions = response.data
80
81
 
81
- for (const a of alerts) {
82
+ for (const a of deviceAlerts) {
82
83
  a.position = positions.find(p => p.id === a.positionId)
83
84
 
84
85
  if (a.geofenceId) {
85
- const geofence = geofences.find(g => g.id === a.geofenceId)
86
+ const geofence = userData.geofences.find(g => g.id === a.geofenceId)
86
87
  if (geofence) {
87
88
  if (a.type === 'deviceOverspeed') {
88
89
  a.geofenceName = geofence.name + ' (' + Math.round(a.attributes.speedLimit * 1.85200) + ' Km/h)'
@@ -93,11 +94,13 @@ async function processDevices (from, to, devices, geofences, drivers, data, trac
93
94
  }
94
95
 
95
96
  if (a.position && a.position.attributes.driverUniqueId) {
96
- const driver = drivers.find(d => d.uniqueId === a.position.attributes.driverUniqueId)
97
+ const driver = userData.drivers.find(d => d.uniqueId === a.position.attributes.driverUniqueId)
97
98
  a.driver = driver && driver.name
98
99
  }
99
100
  }
100
101
 
102
+ const alerts = deviceAlerts.filter(a => userData.allWeek || !userData.weekDays || (!a.position || isInside(a.position.fixTime, a.position.fixTime, userData)))
103
+
101
104
  console.log('LOADING_MESSAGE:' + d.name)
102
105
  console.log(`PROGRESS_PERC:${++i / devices.length * 100}`)
103
106
 
package/src/index.test.js CHANGED
@@ -15,6 +15,7 @@ async function getSpeedingReport (report, userData) {
15
15
 
16
16
  // eslint-disable-next-line no-undef
17
17
  describe('Test_Reports', function () {
18
+ this.timeout(500000)
18
19
  // eslint-disable-next-line no-undef
19
20
  it('Speeding by device', async () => {
20
21
  const report = await getReports()
package/src/util/odoo.js CHANGED
@@ -1,14 +1,16 @@
1
1
 
2
- async function getOdooFuelServices(traccar, from, to) {
3
- const url = `/odoo/reports/refuelingServices?startDate=${from.toDateString()}&endDate=${to.toDateString()}`
2
+ async function getOdooFuelServices (traccar, from, to) {
3
+ const url = `/odoo/reports/refuelingServices?startDate=${from.toDateString()}&endDate=${to.toDateString()}`
4
4
 
5
- const {data} = await traccar.axios.get(url,{
6
- jar: traccar.cookieJar,
7
- withCredentials: true })
5
+ console.log('LOADING_MESSAGE:' + url)
6
+ const { data } = await traccar.axios.get(url, {
7
+ jar: traccar.cookieJar,
8
+ withCredentials: true
9
+ })
8
10
 
9
- console.log(data)
11
+ console.log(data)
10
12
 
11
- return data
13
+ return data
12
14
  }
13
15
 
14
16
  exports.getOdooFuelServices = getOdooFuelServices
@@ -0,0 +1,26 @@
1
+ const { weekDaySelected, convertFromUTC, isClientSide, convertFromLocal } = require('./utils')
2
+
3
+ function isInside (start, end, userData) {
4
+ const tripStart = new Date(start)
5
+ const tripEnd = new Date(end)
6
+
7
+ if (weekDaySelected(tripStart, userData.weekDays)) {
8
+ const startDateLocal = new Date(convertFromUTC(start, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.startTime)
9
+ const endDateLocal = new Date(convertFromUTC(end, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.endTime)
10
+
11
+ const startDate = isClientSide() ? startDateLocal : convertFromLocal(startDateLocal, userData.user.attributes.timezone)
12
+ const endDate = isClientSide() ? endDateLocal : convertFromLocal(endDateLocal, userData.user.attributes.timezone)
13
+
14
+ // Trips inside time period
15
+ if (startDate.getTime() < endDate.getTime()) {
16
+ return tripStart.getTime() > startDate.getTime() && tripEnd.getTime() < endDate.getTime()
17
+ } else {
18
+ return (tripStart.getTime() < endDate.getTime() && tripEnd.getTime() < endDate.getTime()) ||
19
+ (tripStart.getTime() > startDate.getTime())
20
+ }
21
+ }
22
+
23
+ return false
24
+ }
25
+
26
+ exports.isInside = isInside
package/src/util/trips.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const { coordsDistance, convertFromUTC, weekDaySelected, convertFromLocal, isClientSide } = require('./utils')
2
+ const { isInside } = require('./timetable')
2
3
 
3
4
  const minDistance = 0
4
5
  const minAvgSpeed = 0
@@ -112,26 +113,7 @@ function isPartialInsideTimetable (t, userData, route) {
112
113
  }
113
114
 
114
115
  function isInsideTimetable (t, userData) {
115
- const tripStart = new Date(t.startTime)
116
- const tripEnd = new Date(t.endTime)
117
-
118
- if (weekDaySelected(tripStart, userData.weekDays)) {
119
- const startDateLocal = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.startTime)
120
- const endDateLocal = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.endTime)
121
-
122
- const startDate = isClientSide() ? startDateLocal : convertFromLocal(startDateLocal, userData.user.attributes.timezone)
123
- const endDate = isClientSide() ? endDateLocal : convertFromLocal(endDateLocal, userData.user.attributes.timezone)
124
-
125
- // Trips inside time period
126
- if (startDate.getTime() < endDate.getTime()) {
127
- return tripStart.getTime() > startDate.getTime() && tripEnd.getTime() < endDate.getTime()
128
- } else {
129
- return (tripStart.getTime() < endDate.getTime() && tripEnd.getTime() < endDate.getTime()) ||
130
- (tripStart.getTime() > startDate.getTime())
131
- }
132
- }
133
-
134
- return false
116
+ return isInside(t.startTime, t.endTime, userData)
135
117
  }
136
118
 
137
119
  function updateTrip (t, route) {