@transportme/vline-nsp-reader 1.0.5 → 1.0.7

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.
@@ -28,20 +28,26 @@ export default class PassPDFReader {
28
28
  const body = this.getBody(table)
29
29
 
30
30
  for (let columnIndex = 0; columnIndex < body[0].length; columnIndex++) {
31
+ let operationDay = body[0][columnIndex]
31
32
  let currentRun = {
32
33
  type: '',
33
- stops: []
34
+ stops: [],
35
+ operationDay,
36
+ flags: ''
34
37
  }
35
38
 
36
39
  let lastStation
37
- for (let stationIndex = 0; stationIndex < stations.length; stationIndex++) {
40
+ for (let stationIndex = 1; stationIndex < stations.length; stationIndex++) {
38
41
  const stationName = stations[stationIndex]
39
42
  const stopData = (body[stationIndex][columnIndex] || '').replace('.', ':')
40
43
  if (stationName === 'Service') {
41
44
  currentRun.type = stopData[0] + stopData.slice(1).toLowerCase()
42
45
  continue
43
46
  }
44
- if (stationName === 'Service Information') continue
47
+ if (stationName === 'Service Information') {
48
+ currentRun.flags = stopData || ''
49
+ continue
50
+ }
45
51
  if (!stopData || stopData.length === 1) continue
46
52
  if (stationName === 'Change Service' && !currentRun.stops.length) continue
47
53
  if (stationName === 'Change Service' && stopData.length) {
@@ -50,7 +56,9 @@ export default class PassPDFReader {
50
56
  lastStation = null
51
57
  currentRun = {
52
58
  type: stopData[0] + stopData.slice(1).toLowerCase(),
53
- stops: []
59
+ stops: [],
60
+ operationDay,
61
+ flags: ''
54
62
  }
55
63
 
56
64
  continue
@@ -56,12 +56,12 @@ export default class PassTableReader {
56
56
  const tableData = []
57
57
 
58
58
  page.Texts.forEach(text => {
59
- if (text.y < tableStart - commonHeight || text.y > tableEnd + commonHeight * 1.5) return
59
+ if (text.y < tableStart - commonHeight * 2 || text.y > tableEnd + commonHeight * 1.5) return
60
60
 
61
61
  let textContent = decodeURIComponent(text.R[0].T)
62
62
 
63
- let currentRow = rowStarts.findIndex(r => r > text.y + 0.3) - 1
64
- if (currentRow < 0) currentRow = rowStarts.length - 1
63
+ let currentRow = text.y < tableStart - commonHeight ? 0 : rowStarts.findIndex(r => r > text.y + 0.3)
64
+ if (currentRow < 0) currentRow = rowStarts.length
65
65
 
66
66
  let currentCol = colStarts.findLastIndex(c => c < text.x + 0.4)
67
67
 
@@ -78,29 +78,22 @@ export default class PassTableReader {
78
78
  }
79
79
  }
80
80
 
81
- return tableData
82
- })
83
-
84
- console.log(tables)
85
-
86
- console.log(heightFrequency)
87
- console.log(VLines)
88
- console.log(rowStarts)
81
+ const colCount = tableData[1].length
82
+ for (let x = colCount - 1; x > 0; x--) {
83
+ let text = tableData[0][x] || ''
84
+ if (text.startsWith(' ') || text.startsWith('to')) {
85
+ tableData[0][x - 1] = (tableData[0][x - 1] + ' ' + text.trim()).replace('continued', '').trim()
86
+ tableData[0][x] = ''
87
+ }
88
+ }
89
89
 
90
- let pageData = []
91
- let smallTable = rowStarts.length === 2
90
+ for (let x = 1; x < colCount; x++) {
91
+ if (!tableData[0][x]) tableData[0][x] = tableData[0][x - 1]
92
+ }
92
93
 
93
- return pageData
94
+ return tableData
95
+ })
94
96
  })
95
-
96
- return pages[0]
97
-
98
- // return pages.map(page => {
99
- // let maxSize = Math.max(...page.map(row => row.length))
100
- // let blankCells = Array(maxSize).fill('')
101
-
102
- // return page.map(row => row.map(g => g.replace(/ +/g, ' ').trim()).concat(blankCells).slice(0, maxSize))
103
- // })
104
97
  }
105
98
 
106
99
  read() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transportme/vline-nsp-reader",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "main": "lib.mjs",
5
5
  "scripts": {
6
6
  "test": "mocha './{,!(node_modules)/**}/*.test.mjs'"