fleetmap-reports 1.0.851 → 1.0.853

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.851",
3
+ "version": "1.0.853",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -0,0 +1,13 @@
1
+ const baseURL = 'https://api.carbone.io/render'
2
+
3
+ const axios = require('axios').create({
4
+ baseURL,
5
+ headers: {
6
+ Authorization: `Bearer ${process.env.CARBONE_API_KEY}`
7
+ }
8
+ })
9
+
10
+ exports.getPdf = async (template, body) => {
11
+ const { data } = await axios.post(template, body).then(r => r.data)
12
+ return `${baseURL}/${data.renderId}`
13
+ }
@@ -106,6 +106,7 @@ async function processDevices (from, to, devices, data, traccar, userData) {
106
106
  }
107
107
 
108
108
  const alerts = deviceAlerts.filter(a => userData.allWeek || !userData.weekDays || (!a.position || isInside(a.position.fixTime, a.position.fixTime, userData)))
109
+ .filter(a => a.position).sort((a, b) => a.position.fixTime.localeCompare(b.position.fixTime))
109
110
  console.log('LOADING_MESSAGE:' + d.name)
110
111
  console.log(`PROGRESS_PERC:${++i / devices.length * 100}`)
111
112
 
package/src/index.js CHANGED
@@ -182,5 +182,6 @@ function Reports (config, axios, cookieJar) {
182
182
  this.stopReportToExcel = (userData, reportData) => {
183
183
  return require('./stop-report').exportStopReportToExcel(userData, reportData)
184
184
  }
185
+ this.getPdf = require('./carbone').getPdf
185
186
  }
186
187
  module.exports = Reports
@@ -6,6 +6,11 @@ const { convertToFeature, convertPositionToFeature } = require('../util/utils')
6
6
  function calculateLastStopTime (stopTime, to, time) {
7
7
  return stopTime + (to.getTime() - new Date(time).getTime())
8
8
  }
9
+
10
+ function calculateFirstStopTime (stopTime, from, time) {
11
+ return stopTime + (new Date(time).getTime() - from.getTime())
12
+ }
13
+
9
14
  async function createActivityReport (from, to, userData, traccarInstance) {
10
15
  const unauthorizedGeofences = []
11
16
  const authorizedGeofences = []
@@ -72,14 +72,4 @@ describe('activity report', function () {
72
72
  console.log(device)
73
73
  assert.equal(device.summary.reduce((a, b) => a + b.convertedSpentFuel, 0), 168.79999999999995)
74
74
  }, 800000)
75
- it('Activity test performance', async () => {
76
- const report = await getReports('q.trans', 'quality1214')
77
- const userData = await report.getUserData()
78
- console.log(userData)
79
- userData.groupByDay = true
80
- const data = await report.activityReport(new Date(2023, 7, 1, 0, 0, 0, 0),
81
- new Date(2023, 31, 5, 23, 59, 59, 0),
82
- userData)
83
- assert.equal(data.length, 1)
84
- }, 8000000)
85
75
  })
@@ -0,0 +1,20 @@
1
+ const carbone = require('../carbone')
2
+
3
+ // eslint-disable-next-line no-undef
4
+ describe('test carbone', function () {
5
+ // eslint-disable-next-line no-undef
6
+ // eslint-disable-next-line no-undef
7
+ it('works', async () => {
8
+ try {
9
+ console.log(
10
+ await carbone.getPdf('a7322d5a19b6a37c3ceee4719ed701876a27e288f8b9b58b7e0f8c13b7f01bbb',
11
+ {
12
+ data: 1,
13
+ convertTo: 'pdf'
14
+ }))
15
+ } catch (e) {
16
+ console.error(e && e.response && e.response.data)
17
+ throw e
18
+ }
19
+ })
20
+ })
@@ -2,7 +2,6 @@
2
2
  const { getReports } = require('./index')
3
3
  const assert = require('assert')
4
4
  const utils = require('../util/utils')
5
- const { createGPSJumpReport } = require('../partnerReports/gpsjump-report')
6
5
 
7
6
  // eslint-disable-next-line no-undef
8
7
  describe('Test_Reports', function () {
@@ -19,19 +18,12 @@ describe('Test_Reports', function () {
19
18
  const pdf = await report.speedingReportToPDF(userData, data[0])
20
19
  pdf.save()
21
20
  }, 40000)
21
+
22
22
  it('converts madrid time', async () => {
23
23
  assert.equal(false, utils.isClientSide())
24
24
  console.log(utils.convertToLocaleString(new Date(), 'es-CL', 'Europe/Madrid'))
25
25
  })
26
- it('gps jump device', async () => {
27
- const report = await getReports('HASSANE', 'movitec.1637')
28
- const userData = await report.getUserData()
29
- userData.devices = userData.devices.filter(d => d.id === 148725)
30
- const data = await createGPSJumpReport(new Date(2023, 8, 22, 0, 0, 0, 0),
31
- new Date(2023, 8, 24, 23, 59, 59, 0),
32
- userData, report.traccar)
33
- console.log(data)
34
- }, 40000)
26
+
35
27
  it('Idle by device', async () => {
36
28
  const report = await getReports()
37
29
  const userData = await report.getUserData()
@@ -62,7 +54,7 @@ describe('Test_Reports', function () {
62
54
  const totalIdleTime = driver.idleEvents.reduce((a, b) => a + b.idleTime, 0)
63
55
  assert.equal(driver.idleEvents.length, 15) // Total Alerts
64
56
  assert.equal(totalIdleTime, 16000) // Total Duration
65
- }, 20000),
57
+ }, 20000)
66
58
  // eslint-disable-next-line no-undef
67
59
  it('test allinone', async () => {
68
60
  console.log('Start')
@@ -3,20 +3,15 @@ const assert = require('assert')
3
3
  // eslint-disable-next-line no-undef
4
4
  describe('zones', function () {
5
5
  // eslint-disable-next-line no-undef
6
- it('works with ellca', async () => {
6
+ it('works tripsBetweenZones', async () => {
7
7
  const report = await getReports()
8
8
  const userData = await report.getUserData()
9
- const ellca = require('./ellca.json')
10
- userData.devices = userData.devices.filter(d => ellca.find(e => e === d.name))
11
- console.log(userData.devices.length)
12
- console.log(userData.devices.map(d => d.id))
13
- userData.geofences = userData.geofences.filter(g => g.name === 'Geofence Ellca 2')
14
- console.log(userData.geofences)
9
+ userData.tripsBetweenZones = true
15
10
  const result = await report.zoneReport(
16
- new Date(Date.UTC(2022, 6, 24, 0, 0, 0, 0)),
17
- new Date(Date.UTC(2022, 6, 25, 23, 59, 59, 0)),
11
+ new Date(Date.UTC(2023, 6, 24, 0, 0, 0, 0)),
12
+ new Date(Date.UTC(2023, 6, 25, 23, 59, 59, 0)),
18
13
  userData)
19
- console.log('result', result)
14
+ console.log(await report.zoneReportToPDF(userData, result[0]))
20
15
  }, 4000000)
21
16
 
22
17
  // eslint-disable-next-line no-undef
@@ -32,18 +27,6 @@ describe('zones', function () {
32
27
  console.log('result', result)
33
28
  }, 4000000)
34
29
 
35
- it('works with afriquia', async () => {
36
- const report = await getReports(process.env.USER_AFRIQUIA, process.env.PASS_AFRIQUIA)
37
- const userData = await report.getUserData()
38
- console.log(userData.devices.length)
39
- console.log(userData.geofences)
40
- const result = await report.zoneReport(
41
- new Date(Date.UTC(2023, 5, 11, 0, 0, 0, 0)),
42
- new Date(Date.UTC(2023, 5, 11, 23, 59, 59, 0)),
43
- userData)
44
- console.log('result', result)
45
- }, 4000000)
46
-
47
30
  // eslint-disable-next-line no-undef
48
31
  it('works with casais', async () => {
49
32
  const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
@@ -1,46 +0,0 @@
1
- [
2
- "KRS5330",
3
- "LTR6D02",
4
- "LTS8J58",
5
- "LUA4F53",
6
- "LUN9B64",
7
- "RJN0J89",
8
- "RJP0I18",
9
- "RJY4A56",
10
- "RKT2C85",
11
- "RKU3F60",
12
- "EPA5I95",
13
- "ESV3G14",
14
- "FKT3J22",
15
- "JAD3F55",
16
- "JAJ1C36",
17
- "KRX2869",
18
- "KXG9094",
19
- "KZA5664",
20
- "KZA5940",
21
- "LMT4A13",
22
- "LTY8D84",
23
- "RIP4C67",
24
- "RIZ0H12",
25
- "RJA0F90",
26
- "RJG4J53",
27
- "RJH4J70",
28
- "RJJ5E13",
29
- "RJK9F52",
30
- "RJL1E23",
31
- "RJL1E26",
32
- "RJM5G37",
33
- "RJN9G45",
34
- "RJP3C03",
35
- "RJR4G53",
36
- "RJV8G79",
37
- "RJY4A55",
38
- "RKC9H45",
39
- "RKG0I43",
40
- "RKG3D47",
41
- "RKK9G32",
42
- "RKR3I02",
43
- "RKR3I09",
44
- "RKR3I10",
45
- "RKS1A72"
46
- ]