-
Notifications
You must be signed in to change notification settings - Fork 29
More Data From the PDF #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
36ffd0a
9693ceb
7c39c8f
3119fc9
a1d77d3
08287d8
041a0a4
22c4ea5
dccbedb
4cc3fb5
8affc3e
72685fa
38f7b9a
d533ba4
f0df18c
0670291
3faf413
50791e9
159329e
b48bab8
6c303da
11c2b5d
a1d3ea4
6819696
df67298
024eefa
4feb0bd
d965145
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| const { chartToArrayBuilder } = require('./chartToArrayBuilder'); | ||
| const { getFromArr } = require('./parsersUtils'); | ||
| const log = require('../../../log'); | ||
|
|
||
| // this function look for the correct columns for the given headers, and returns a factory embedded with these findings | ||
| const rowAbstractFactoryChart1_7 = (firstPageOfTable, headersStartIndex) => { | ||
| // clean the headers | ||
| firstPageOfTable = firstPageOfTable.map(row => row.map(cell => cell.replace(/\n/g, ' ') | ||
| .replace(/ {2}/g, ' ') | ||
| .trim())); | ||
|
|
||
| if (headersStartIndex === -1) { | ||
| // it's an error | ||
| log.error('didn\'t find headers for some char 1.6'); | ||
| return () => {}; | ||
| } | ||
|
|
||
| const header = firstPageOfTable[headersStartIndex]; | ||
|
|
||
| const kindIdx = header.findIndex(title => title.includes('סוג המסמך')); | ||
| const containsIdx = header.findIndex(title => title.includes('תחולה')); | ||
| const scaleIdx = header.findIndex(title => title.includes('קנה מידה')); | ||
| const numberOfPagesIdx = header.findIndex(title => title.includes('מספר עמודים')); | ||
| const editDateIdx = header.findIndex(title => title.includes('תאריך עריכה')); | ||
| const editorIdx = header.findIndex(title => title.includes('עורך המסמך')); | ||
| const creationDateIdx = header.findIndex(title => title.includes('תאריך יצירה')); | ||
| const descriptionIdx = header.findIndex(title => title.includes('תיאור המסמך')); | ||
| const includedIdx = header.findIndex(title => title.includes('נכלל בהוראות התכנית')); | ||
|
|
||
|
|
||
|
|
||
| return (row) => { | ||
| return { | ||
| kind: getFromArr(row, kindIdx), | ||
| contains: getFromArr(row, containsIdx), | ||
| scale: getFromArr(row, scaleIdx), | ||
| number_of_pages: getFromArr(row, numberOfPagesIdx), | ||
| edit_date: getFromArr(row, editDateIdx), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. snake casing in purpose?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, for the db. By using snake casing we don't need to change the map's keys when inserting into the db. |
||
| editor: getFromArr(row, editorIdx), | ||
| creation_date: getFromArr(row, creationDateIdx), | ||
| description: getFromArr(row, descriptionIdx), | ||
| included: getFromArr(row, includedIdx), | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| const extractChartOneSeven = (pageTables) => { | ||
| return chartToArrayBuilder({ | ||
| pageTables, | ||
| rowAbstractFactory: rowAbstractFactoryChart1_7, | ||
| startOfChartPred: (cell) => cell.includes('מסמכי התכנית') && cell.includes('1.7'), | ||
| offsetOfRowWithDataInChart: 1, | ||
| chartDonePredicate: (row) => row.some(cell => cell.includes('כל מסמכי התכנית מהווים חלק בלתי נפרד ממנה')), | ||
| getHeaderRowIndex: (page, searchFrom) => page.slice(searchFrom).findIndex(row => row.some(cell => cell.includes('סוג המסמך'))) + searchFrom, | ||
| rowTrimmer: (row) => row.map((cell) => cell.replace(/\n/g, ' ').replace(/ {2}/g, ' ').trim()), | ||
| identifier: '1.7' | ||
| }); | ||
| }; | ||
|
|
||
| module.exports = { | ||
| extractChartOneSeven | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| const { chartToArrayBuilder } = require('./chartToArrayBuilder'); | ||
| const { getFromArr } = require('./parsersUtils'); | ||
| const log = require('../../../log'); | ||
|
|
||
| // this function look for the correct columns for the given headers, and returns a factory embedded with these findings | ||
| const rowAbstractFactoryChart1_6 = (firstPageOfTable, headersStartIndex) => { | ||
| // clean the headers | ||
| firstPageOfTable = firstPageOfTable.map(row => row.map(cell => cell.replace(/\n/g, ' ') | ||
| .replace(/ {2}/g, ' ') | ||
| .trim())); | ||
|
|
||
| if (headersStartIndex === -1) { | ||
| // it's an error | ||
| log.error('didn\'t find headers for some char 1.6'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please add planId to the log so we can assign to a process for investigation?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing a planId here requires me to pass planId into more software layers (at least 2 more) and change at least 25 lines in at least 15 different files. It will be a bit complicated. |
||
| return () => {}; | ||
| } | ||
|
|
||
| const header = firstPageOfTable[headersStartIndex]; | ||
|
|
||
| const planNumberIdx = header.findIndex(title => title.includes('מספר תכנית מאושרת')); | ||
| const kindIdx = header.findIndex(title => title.includes('סוג יחס')); | ||
| const commentIdx = header.findIndex(title => title.includes('הערה ליחס')); | ||
| const yalkootNumberIdx = header.findIndex(title => title.includes('מספר ילקוט פרסומים')); | ||
| const yalkootPageNumberIdx = header.findIndex(title => title.includes('עמוד בילקוט פרסומים')); | ||
| const dateIdx = header.findIndex(title => title.includes('תאריך')); | ||
|
|
||
|
|
||
| return (row) => { | ||
| return { | ||
| prev_plan_number: getFromArr(row, planNumberIdx), | ||
| kind: getFromArr(row, kindIdx), | ||
| comment: getFromArr(row, commentIdx), | ||
| yalkoot_number: getFromArr(row, yalkootNumberIdx), | ||
| yalkoot_page_number: getFromArr(row, yalkootPageNumberIdx), | ||
| date: getFromArr(row, dateIdx), | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| const extractChartOneSix = (pageTables) => { | ||
| return chartToArrayBuilder({ | ||
| pageTables, | ||
| rowAbstractFactory: rowAbstractFactoryChart1_6, | ||
| startOfChartPred: (cell) => cell.includes('יחס בין התכנית לבין תכניות מאושרות קודמות') && cell.includes('1.6'), | ||
| offsetOfRowWithDataInChart: 1, | ||
| chartDonePredicate: (row) => row.some(cell => cell.includes('מסמכי התכנית') && cell.includes('1.7')), | ||
| getHeaderRowIndex: (page, searchFrom) => page.slice(searchFrom).findIndex(row => row.some(cell => cell.includes('סוג יחס'))) + searchFrom, | ||
| rowTrimmer: (row) => row.map((cell) => cell.replace(/\n/g, ' ').replace(/ {2}/g, ' ').trim()), | ||
| identifier: '1.6' | ||
| }); | ||
| }; | ||
|
|
||
| module.exports = { | ||
| extractChartOneSix | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| const { chartToArrayBuilder } = require('./chartToArrayBuilder'); | ||
| const { getFromArr } = require('./parsersUtils'); | ||
| const log = require('../../../log'); | ||
|
|
||
| // this function look for the correct columns for the given headers, and returns a factory embedded with these findings | ||
| const rowAbstractFactoryChart7_1 = (firstPageOfTable, headersStartIndex) => { | ||
| // clean the headers | ||
| firstPageOfTable = firstPageOfTable.map(row => row.map(cell => cell.replace(/\n/g, ' ') | ||
| .replace(/ {2}/g, ' ') | ||
| .trim())); | ||
|
|
||
| if (headersStartIndex === -1) { | ||
| // it's an error | ||
| log.error('didn\'t find headers for some chart 3.1_without_change'); | ||
| return () => {}; | ||
| } | ||
|
|
||
| const header = firstPageOfTable[headersStartIndex]; | ||
|
|
||
| const phaseIndex = header.findIndex(title => title.includes('מספר שלב')); | ||
| const phaseDescription = header.findIndex(title => title.includes('תאור שלב')); | ||
| const conditioning = header.findIndex(title => title.includes('התנייה')); | ||
|
|
||
| return (row) => { | ||
| return { | ||
| phase: getFromArr(row, phaseIndex), | ||
| phase_description: getFromArr(row, phaseDescription), | ||
| conditioning: getFromArr(row, conditioning), | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
|
|
||
| const extractChartSevenOne = (pageTables) => { | ||
| const rowsFromBuilder = chartToArrayBuilder({ | ||
| pageTables, | ||
| rowAbstractFactory: rowAbstractFactoryChart7_1, | ||
| startOfChartPred: (cell) => cell.includes('7.1') && cell.includes('שלבי ביצוע'), | ||
| offsetOfRowWithDataInChart: 1, | ||
| chartDonePredicate: (row) => row.some(cell => cell.includes('7.2') && cell.includes('מימוש התכנית')), | ||
| getHeaderRowIndex: (page, searchFrom) => page.slice(searchFrom).findIndex(row => row.some(cell => cell.includes('מספר שלב')) && | ||
| row.some(cell => cell.includes('תאור שלב')) && | ||
| row.some(cell => cell.includes('התנייה'))) + searchFrom, | ||
| rowTrimmer: (row) => row.map((cell) => cell.replace(/\n/g, ' ').replace(/ {2}/g, ' ').trim()), | ||
| identifier: '7.1' | ||
| }); | ||
|
|
||
| const newRows = []; | ||
|
|
||
| for (let i = 0; i < rowsFromBuilder.length; i++) { | ||
| const currRow = rowsFromBuilder[i]; | ||
|
|
||
| if (currRow.phase === '' && newRows.length > 0) { | ||
| const lastFromNewRows = newRows[newRows.length - 1]; | ||
|
|
||
| lastFromNewRows.phase_description += ' ' + currRow.phase_description; | ||
| lastFromNewRows.conditioning += ' ' + currRow.conditioning; | ||
| } | ||
|
|
||
| else { | ||
| newRows.push(currRow); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return newRows; | ||
|
|
||
| }; | ||
|
|
||
| module.exports = { | ||
| extractChartSevenOne | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if firstPageOfTable is undefined or not an array?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's always an array. We can add a check beforehand, but we firstPageOfTable comes from the PDF extension and it's consistent.
Adding a check here will require adding the same check on at least 10 places.