fleetmap-reports 1.0.247 → 1.0.251

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.
@@ -1,11 +1,10 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="ChangeListManager">
4
- <list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="Kms Report - Calculate distance with traccar trips">
4
+ <list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="speeding report with customSpeed">
5
5
  <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
6
6
  <change beforePath="$PROJECT_DIR$/src/index.test.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.test.js" afterDir="false" />
7
7
  <change beforePath="$PROJECT_DIR$/src/speeding-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/speeding-report.js" afterDir="false" />
8
- <change beforePath="$PROJECT_DIR$/src/util/traccar.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/util/traccar.js" afterDir="false" />
9
8
  </list>
10
9
  <option name="SHOW_DIALOG" value="false" />
11
10
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -37,23 +36,28 @@
37
36
  <property name="ts.external.directory.path" value="$APPLICATION_HOME_DIR$/plugins/JavaScriptLanguage/jsLanguageServicesImpl/external" />
38
37
  <property name="vue.rearranger.settings.migration" value="true" />
39
38
  </component>
40
- <component name="RunManager" selected="Mocha.speedingReport.test speeding">
41
- <configuration name="speedingReport" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
39
+ <component name="RunManager" selected="Mocha.Reports.test event report">
40
+ <configuration name="Reports.test event report" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
42
41
  <node-interpreter>project</node-interpreter>
43
42
  <node-options />
44
43
  <mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
45
44
  <working-directory>$PROJECT_DIR$</working-directory>
46
45
  <pass-parent-env>true</pass-parent-env>
46
+ <envs>
47
+ <env name="email" value="jppenas@gmail.com" />
48
+ <env name="password" value="penas46881" />
49
+ </envs>
47
50
  <ui>bdd</ui>
48
51
  <extra-mocha-options />
49
52
  <test-kind>TEST</test-kind>
50
53
  <test-file>$PROJECT_DIR$/src/index.test.js</test-file>
51
54
  <test-names>
52
- <name value="speedingReport" />
55
+ <name value="Reports" />
56
+ <name value="test event report" />
53
57
  </test-names>
54
58
  <method v="2" />
55
59
  </configuration>
56
- <configuration name="speedingReport.test kmsReport by day" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
60
+ <configuration name="Reports.test trip report" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
57
61
  <node-interpreter>project</node-interpreter>
58
62
  <node-options />
59
63
  <mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
@@ -68,12 +72,12 @@
68
72
  <test-kind>TEST</test-kind>
69
73
  <test-file>$PROJECT_DIR$/src/index.test.js</test-file>
70
74
  <test-names>
71
- <name value="speedingReport" />
72
- <name value="test kmsReport by day" />
75
+ <name value="Reports" />
76
+ <name value="test trip report" />
73
77
  </test-names>
74
78
  <method v="2" />
75
79
  </configuration>
76
- <configuration name="speedingReport.test speeding" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
80
+ <configuration name="speedingReport.test kmsReport by day" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
77
81
  <node-interpreter>project</node-interpreter>
78
82
  <node-options />
79
83
  <mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
@@ -89,11 +93,11 @@
89
93
  <test-file>$PROJECT_DIR$/src/index.test.js</test-file>
90
94
  <test-names>
91
95
  <name value="speedingReport" />
92
- <name value="test speeding" />
96
+ <name value="test kmsReport by day" />
93
97
  </test-names>
94
98
  <method v="2" />
95
99
  </configuration>
96
- <configuration name="test reports" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
100
+ <configuration name="speedingReport.test speeding" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
97
101
  <node-interpreter>project</node-interpreter>
98
102
  <node-options />
99
103
  <mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
@@ -105,43 +109,47 @@
105
109
  </envs>
106
110
  <ui>bdd</ui>
107
111
  <extra-mocha-options />
108
- <test-kind>SUITE</test-kind>
112
+ <test-kind>TEST</test-kind>
109
113
  <test-file>$PROJECT_DIR$/src/index.test.js</test-file>
110
114
  <test-names>
111
- <name value="test reports" />
115
+ <name value="speedingReport" />
116
+ <name value="test speeding" />
112
117
  </test-names>
113
118
  <method v="2" />
114
119
  </configuration>
115
- <configuration name="test reports.test queue" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
120
+ <configuration name="test reports" type="mocha-javascript-test-runner" temporary="true" nameIsGenerated="true">
116
121
  <node-interpreter>project</node-interpreter>
117
122
  <node-options />
118
123
  <mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
119
124
  <working-directory>$PROJECT_DIR$</working-directory>
120
125
  <pass-parent-env>true</pass-parent-env>
126
+ <envs>
127
+ <env name="email" value="jppenas@gmail.com" />
128
+ <env name="password" value="penas46881" />
129
+ </envs>
121
130
  <ui>bdd</ui>
122
131
  <extra-mocha-options />
123
- <test-kind>TEST</test-kind>
132
+ <test-kind>SUITE</test-kind>
124
133
  <test-file>$PROJECT_DIR$/src/index.test.js</test-file>
125
134
  <test-names>
126
135
  <name value="test reports" />
127
- <name value="test queue" />
128
136
  </test-names>
129
137
  <method v="2" />
130
138
  </configuration>
131
139
  <list>
132
- <item itemvalue="Mocha.speedingReport" />
133
140
  <item itemvalue="Mocha.test reports" />
134
- <item itemvalue="Mocha.test reports.test queue" />
135
141
  <item itemvalue="Mocha.speedingReport.test kmsReport by day" />
136
142
  <item itemvalue="Mocha.speedingReport.test speeding" />
143
+ <item itemvalue="Mocha.Reports.test trip report" />
144
+ <item itemvalue="Mocha.Reports.test event report" />
137
145
  </list>
138
146
  <recent_temporary>
139
147
  <list>
148
+ <item itemvalue="Mocha.Reports.test event report" />
149
+ <item itemvalue="Mocha.Reports.test trip report" />
140
150
  <item itemvalue="Mocha.speedingReport.test speeding" />
141
151
  <item itemvalue="Mocha.speedingReport.test kmsReport by day" />
142
152
  <item itemvalue="Mocha.test reports" />
143
- <item itemvalue="Mocha.test reports.test queue" />
144
- <item itemvalue="Mocha.speedingReport" />
145
153
  </list>
146
154
  </recent_temporary>
147
155
  </component>
@@ -176,7 +184,19 @@
176
184
  <workItem from="1637868513425" duration="1650000" />
177
185
  <workItem from="1637928687573" duration="37000" />
178
186
  <workItem from="1637931438656" duration="621000" />
179
- <workItem from="1637952151523" duration="10352000" />
187
+ <workItem from="1637952151523" duration="17766000" />
188
+ <workItem from="1638270786569" duration="6960000" />
189
+ <workItem from="1638455902437" duration="120000" />
190
+ <workItem from="1638486745343" duration="4126000" />
191
+ <workItem from="1638792860278" duration="2140000" />
192
+ <workItem from="1638839462028" duration="50000" />
193
+ <workItem from="1638840110567" duration="597000" />
194
+ <workItem from="1638888787940" duration="19894000" />
195
+ <workItem from="1639074912454" duration="257000" />
196
+ <workItem from="1639090037682" duration="2514000" />
197
+ <workItem from="1639135460686" duration="3092000" />
198
+ <workItem from="1639151097761" duration="13703000" />
199
+ <workItem from="1639246310204" duration="628000" />
180
200
  </task>
181
201
  <task id="LOCAL-00001" summary="Fix getStyle">
182
202
  <created>1636983717385</created>
@@ -227,7 +247,42 @@
227
247
  <option name="project" value="LOCAL" />
228
248
  <updated>1638179219256</updated>
229
249
  </task>
230
- <option name="localTasksCounter" value="8" />
250
+ <task id="LOCAL-00008" summary="fix speeding report">
251
+ <created>1638186780966</created>
252
+ <option name="number" value="00008" />
253
+ <option name="presentableId" value="LOCAL-00008" />
254
+ <option name="project" value="LOCAL" />
255
+ <updated>1638186780967</updated>
256
+ </task>
257
+ <task id="LOCAL-00009" summary="refactor speeding and trip report">
258
+ <created>1638288337133</created>
259
+ <option name="number" value="00009" />
260
+ <option name="presentableId" value="LOCAL-00009" />
261
+ <option name="project" value="LOCAL" />
262
+ <updated>1638288337135</updated>
263
+ </task>
264
+ <task id="LOCAL-00010" summary="Kms report with time period">
265
+ <created>1639057192380</created>
266
+ <option name="number" value="00010" />
267
+ <option name="presentableId" value="LOCAL-00010" />
268
+ <option name="project" value="LOCAL" />
269
+ <updated>1639057192382</updated>
270
+ </task>
271
+ <task id="LOCAL-00011" summary="kms report - show every selected day">
272
+ <created>1639139696407</created>
273
+ <option name="number" value="00011" />
274
+ <option name="presentableId" value="LOCAL-00011" />
275
+ <option name="project" value="LOCAL" />
276
+ <updated>1639139696408</updated>
277
+ </task>
278
+ <task id="LOCAL-00012" summary="speeding report with customSpeed">
279
+ <created>1639238286381</created>
280
+ <option name="number" value="00012" />
281
+ <option name="presentableId" value="LOCAL-00012" />
282
+ <option name="project" value="LOCAL" />
283
+ <updated>1639238286382</updated>
284
+ </task>
285
+ <option name="localTasksCounter" value="13" />
231
286
  <servers />
232
287
  </component>
233
288
  <component name="TypeScriptGeneratedFilesManager">
@@ -253,6 +308,11 @@
253
308
  <MESSAGE value="Fix pdf logo" />
254
309
  <MESSAGE value="kms report with parallel requests" />
255
310
  <MESSAGE value="Kms Report - Calculate distance with traccar trips" />
256
- <option name="LAST_COMMIT_MESSAGE" value="Kms Report - Calculate distance with traccar trips" />
311
+ <MESSAGE value="fix speeding report" />
312
+ <MESSAGE value="refactor speeding and trip report" />
313
+ <MESSAGE value="Kms report with time period" />
314
+ <MESSAGE value="kms report - show every selected day" />
315
+ <MESSAGE value="speeding report with customSpeed" />
316
+ <option name="LAST_COMMIT_MESSAGE" value="speeding report with customSpeed" />
257
317
  </component>
258
318
  </project>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.247",
3
+ "version": "1.0.251",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -19,8 +19,8 @@ function Reports(config, axios) {
19
19
  byGroup: false
20
20
  }
21
21
  }
22
- this.speedingReport = (from, to, userData, roadSpeedLimits) => {
23
- return require('./speeding-report').createSpeedingReport(from, to, userData, this.traccar, roadSpeedLimits)
22
+ this.speedingReport = (from, to, userData) => {
23
+ return require('./speeding-report').createSpeedingReport(from, to, userData, this.traccar)
24
24
  }
25
25
 
26
26
  this.speedingReportToPDF = (userData, reportData) => {
package/src/index.test.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const {getReports} = require("./tests");
2
2
 
3
- describe('speedingReport', function() {
3
+ describe('Reports', function() {
4
4
  this.timeout(500000)
5
5
  it('test speeding', async () => {
6
6
  const report = await getReports()
@@ -12,6 +12,28 @@ describe('speedingReport', function() {
12
12
 
13
13
  console.log(reportData)
14
14
 
15
+ })
16
+ it('test trip report', async () => {
17
+ const report = await getReports()
18
+ const userData = await report.getUserData()
19
+ userData.byGroup = true
20
+ const reportData = await report.tripReport(new Date(2021, 2, 30, 0, 0, 0, 0),
21
+ new Date(2021, 2, 30, 23, 59, 59, 0),
22
+ userData)
23
+
24
+ console.log(reportData)
25
+
26
+ })
27
+ it('test event report', async () => {
28
+ const report = await getReports()
29
+ const userData = await report.getUserData()
30
+ userData.eventTypes = []
31
+ const reportData = await report.eventsReport(new Date(2021, 10, 20, 0, 0, 0, 0),
32
+ new Date(2021, 10, 30, 23, 59, 59, 0),
33
+ userData)
34
+
35
+ console.log(reportData)
36
+
15
37
  })
16
38
  it('test kmsReport by day', async () => {
17
39
  const reports = await getReports()
package/src/kms-report.js CHANGED
@@ -6,13 +6,15 @@ const {getStyle} = require("./reportStyle");
6
6
  const {headerFromUser,addTable} = require("./util/pdfDocument");
7
7
  const {getUserPartner} = require("fleetmap-partners");
8
8
  const traccar = require("./util/traccar");
9
+ const {getDates} = require("./util/utils");
9
10
 
10
11
 
11
12
  let traccarInstance
13
+ let userData
12
14
 
13
15
  const fileName = 'KmsReport'
14
16
 
15
- async function createKmsReportByDevice(from, to, userData) {
17
+ async function createKmsReportByDevice(from, to) {
16
18
  const groupIds = userData.groups.map(g => g.id)
17
19
  const devicesToProcess = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
18
20
 
@@ -23,54 +25,110 @@ async function createKmsReportByDevice(from, to, userData) {
23
25
  }
24
26
 
25
27
  devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
26
- //const data = await traccar.getRoute(traccarInstance, from, to, devicesToProcess)
27
- const data = await traccar.getTrips(traccarInstance, from, to, devicesToProcess)
28
+ const route = userData.allWeek ? [] : await traccar.getRoute(traccarInstance, from, to, devicesToProcess)
29
+ const trips = await traccar.getTrips(traccarInstance, from, to, devicesToProcess)
28
30
 
29
- console.log('trips:' + data.length)
31
+ console.log('trips:' + trips.length)
30
32
 
31
- if (data.length > 0) {
32
- allData.devices = processDevices(from, to, devicesToProcess, data)
33
+ if (trips.length > 0) {
34
+ allData.devices = processDevices(from, to, devicesToProcess, route, trips)
33
35
  }
34
36
 
35
37
  return allData
36
38
  }
37
39
 
38
- async function createKmsReportByDriver(from, to, userData) {
40
+ async function createKmsReportByDriver(from, to) {
39
41
 
40
42
  }
41
43
 
42
- async function createKmsReportByGroup(from, to, userData) {
44
+ async function createKmsReportByGroup(from, to) {
43
45
 
44
46
  }
45
47
 
46
- function processDevices(from, to, devices, data) {
48
+ function processDevices(from, to, devices, route, trips) {
47
49
  const devicesResult = []
48
50
 
49
51
  for (const d of devices) {
50
- const trips = data.filter(t => t.deviceId === d.id)
52
+ const deviceTrips = trips.filter(t => t.deviceId === d.id)
51
53
 
52
- if (trips.length > 0) {
53
- trips.forEach(t => t.tripDay = new Date(t.startTime).toISOString().split('T')[0] + ' 12:00 PM')
54
- const groupedTrips = trips.reduce(
54
+ if (deviceTrips.length > 0) {
55
+ deviceTrips.forEach(t => t.tripDay = new Date(t.startTime).toISOString().split('T')[0] + ' 12:00 PM')
56
+ const groupedTrips = deviceTrips.reduce(
55
57
  (entryMap, e) => entryMap.set(e.tripDay, [...entryMap.get(e.tripDay)||[], e]),
56
58
  new Map()
57
59
  )
58
60
 
59
- const days = []
60
- const keys = Array.from(groupedTrips.keys())
61
+ const allDates = getDates(from, to)
61
62
 
62
- keys.forEach(key => {
63
- const dayTrips = groupedTrips.get(key)
63
+ const days = []
64
+ let keys = Array.from(groupedTrips.keys())
65
+ allDates.forEach(d => {
66
+ const day = d.toISOString().split('T')[0] + ' 12:00 PM'
67
+ if(!keys.includes(day)){
68
+ groupedTrips.set(day, [])
69
+ }
70
+ })
71
+
72
+ keys = Array.from(groupedTrips.keys())
73
+ keys.sort((a,b)=>new Date(a).getTime()-new Date(b).getTime());
74
+ keys.forEach(key => {
75
+ const currentDate = new Date(key)
76
+ let dayTrips = groupedTrips.get(key)
64
77
  const day = {
65
- date: new Date(key),
66
- kms: dayTrips.reduce((a, b) => a + b.distance, 0) || 0
78
+ date: currentDate,
79
+ kms: 0
80
+ }
81
+
82
+ if(userData.allWeek){
83
+ day.kms = dayTrips.reduce((a, b) => a + b.distance, 0) || 0
84
+ } else {
85
+ if((currentDate.getDay() === 0 && userData.weekDays.sunday) ||
86
+ (currentDate.getDay() === 1 && userData.weekDays.monday) ||
87
+ (currentDate.getDay() === 2 && userData.weekDays.tuesday) ||
88
+ (currentDate.getDay() === 3 && userData.weekDays.wednesday) ||
89
+ (currentDate.getDay() === 4 && userData.weekDays.thursday) ||
90
+ (currentDate.getDay() === 5 && userData.weekDays.friday) ||
91
+ (currentDate.getDay() === 6 && userData.weekDays.saturday)) {
92
+
93
+ const startDate = new Date(new Date(key).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
94
+ const endDate = new Date(new Date(key).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
95
+
96
+ console.log(key, startDate, endDate)
97
+
98
+ //Trips inside time period
99
+ const filteredTrips = dayTrips.filter(t => new Date(t.startTime).getTime() > startDate.getTime()
100
+ && new Date(t.endTime).getTime() < endDate.getTime())
101
+
102
+ //Trip starts outside time period and ends inside time period
103
+ const startIncompleteTrip = dayTrips.filter(t => new Date(t.startTime).getTime() < startDate.getTime()
104
+ && new Date(t.endTime).getTime() > startDate.getTime())
105
+
106
+ //Trip starts inside time period and ends outside time period
107
+ const endIncompleteTrip = dayTrips.filter(t => new Date(t.startTime).getTime() < endDate.getTime()
108
+ && new Date(t.endTime).getTime() > endDate.getTime())
109
+
110
+ day.kms = filteredTrips.reduce((a, b) => a + b.distance, 0) || 0
111
+ console.log('Inside trips:'+day.kms)
112
+
113
+ if(startIncompleteTrip.length){
114
+ const routeInside = route.filter(p => new Date(p.fixTime).getTime() > startDate.getTime() && new Date(p.fixTime).getTime() < new Date(startIncompleteTrip[0].endTime).getTime())
115
+ day.kms = day.kms + (routeInside.reduce((a, b) => a + b.distance, 0) || 0)
116
+ console.log('startIncompleteTrip:'+day.kms)
117
+ }
118
+
119
+ if(endIncompleteTrip.length){
120
+ const routeInside = route.filter(p => new Date(p.fixTime).getTime() < endDate.getTime() && new Date(p.fixTime).getTime() > new Date(endIncompleteTrip[0].startTime).getTime())
121
+ day.kms = day.kms + (routeInside.reduce((a, b) => a + b.distance, 0) || 0)
122
+ console.log('endIncompleteTrip:'+day.kms)
123
+ }
124
+ }
67
125
  }
126
+
68
127
  days.push(day)
69
128
  })
70
-
71
129
  devicesResult.push({
72
- device: d,
73
- days: days
130
+ device: d,
131
+ days: days
74
132
  })
75
133
  }
76
134
  }
@@ -78,23 +136,26 @@ function processDevices(from, to, devices, data) {
78
136
  return devicesResult
79
137
  }
80
138
 
81
- async function createKmsReport(from, to, userData, traccar) {
139
+ async function createKmsReport(from, to, reportUserData, traccar) {
82
140
  console.log('Create KmsReport')
141
+
142
+ console.log(from, to)
83
143
  traccarInstance = traccar
144
+ userData = reportUserData
84
145
  if(userData.groupByDay){
85
146
  const reportData = []
86
147
 
87
148
  if(userData.byDriver){
88
- const allData = await createKmsReportByDriver(from, to, userData)
149
+ const allData = await createKmsReportByDriver(from, to)
89
150
  reportData.push(allData)
90
151
  }
91
152
  else if(userData.byGroup){
92
- const allGroupsData = await createKmsReportByGroup(from, to, userData)
153
+ const allGroupsData = await createKmsReportByGroup(from, to)
93
154
  allGroupsData.forEach(data => reportData.push(data))
94
- const withoutGroupDevices = await createKmsReportByDevice(from, to, userData)
155
+ const withoutGroupDevices = await createKmsReportByDevice(from, to)
95
156
  reportData.push(withoutGroupDevices)
96
157
  } else {
97
- const allData = await createKmsReportByDevice(from, to, userData)
158
+ const allData = await createKmsReportByDevice(from, to)
98
159
  reportData.push(allData)
99
160
  }
100
161