Skip to content

Commit 1170b04

Browse files
committed
protocol parsing fixes
1 parent cb2cea8 commit 1170b04

3 files changed

Lines changed: 74 additions & 90 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ FROM ghcr.io/hasadna/knesset-data-pipelines/knesset-data-pipelines:8028b98004108
1010
#COPY Pipfile.lock /pipelines/
1111
#RUN pipenv install --system --deploy --ignore-pipfile
1212
#RUN python3 -m pip install jupyterlab
13-
RUN KNESSET_DATA_COMMIT=3e3141ff76eabf20a72d16fc098544759f5952a8 &&\
13+
RUN KNESSET_DATA_COMMIT=ea2fdf261d96accef4441ba93a841bf870c87494 &&\
1414
pip uninstall -y knesset-data &&\
1515
pip install -e "git+https://github.com/hasadna/knesset-data-python.git@${KNESSET_DATA_COMMIT}#egg=knesset-data" &&\
1616
echo "__version__ = '${KNESSET_DATA_COMMIT}'" >> /pipelines/src/knesset-data/knesset_data/__init__.py

airflow/knesset_data_pipelines/committees/parsed_document_committee_sessions.py

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,63 +8,41 @@
88
from .. import db, config
99

1010

11-
def legacy_fix(type_, row):
12-
session_id = str(row['CommitteeSessionID'])
13-
document_session_id = str(row['DocumentCommitteeSessionID'])
14-
ext = 'txt' if type_ == 'text' else 'csv'
15-
basepath = os.path.join(
16-
config.KNESSET_PIPELINES_DATA_PATH,
17-
'committees', f'meeting_protocols_{type_}', 'files',
18-
)
19-
legacy_file = os.path.join(
20-
basepath, session_id[0], session_id[1], f'{session_id}.{ext}'
21-
)
22-
legacy_hash_file = f'{legacy_file}.hash'
23-
legacy_hash_retry_file = f'{legacy_hash_file}.retry'
24-
new_file = os.path.join(
25-
basepath, document_session_id[0], document_session_id[1], f'{document_session_id}.{ext}'
26-
)
27-
new_hash_file = f'{new_file}.hash'
28-
new_relfile = os.path.join(
29-
'files', document_session_id[0], document_session_id[1], f'{document_session_id}.{ext}'
30-
)
31-
if os.path.exists(legacy_file):
32-
row[f'{type_}_parsed_filename'] = new_relfile
33-
os.makedirs(os.path.dirname(new_file), exist_ok=True)
34-
shutil.move(legacy_file, new_file)
35-
if os.path.exists(legacy_hash_file):
36-
shutil.move(legacy_hash_file, new_hash_file)
37-
if os.path.exists(legacy_hash_file):
38-
os.remove(legacy_hash_file)
39-
if os.path.exists(legacy_hash_retry_file):
40-
os.remove(legacy_hash_retry_file)
41-
42-
43-
def parse_retry(type_, error, document_session_id, retry_report):
11+
def parse_retry_error(type_, error, document_session_id, group_type_id, application_desc, stats):
4412
document_session_id = str(document_session_id)
13+
group_type_id = str(group_type_id)
14+
application_desc = str(application_desc)
4515
if error:
4616
ext = 'txt' if type_ == 'text' else 'csv'
47-
hash_file = os.path.join(
17+
download_filepath = os.path.join(
18+
config.KNESSET_PIPELINES_DATA_PATH,
19+
'committees', 'download_document_committee_session', 'files', group_type_id,
20+
document_session_id[0], document_session_id[1], f'{document_session_id}.{application_desc}'
21+
)
22+
parsed_filepath = os.path.join(
4823
config.KNESSET_PIPELINES_DATA_PATH,
4924
'committees', f'meeting_protocols_{type_}', 'files',
5025
document_session_id[0], document_session_id[1], f'{document_session_id}.{ext}.hash'
5126
)
52-
if os.path.exists(hash_file):
53-
hash_retry_file = f'{hash_file}.retry'
54-
if os.path.exists(hash_retry_file):
55-
with open(hash_retry_file) as f:
56-
retry = int(f.read().strip())
57-
else:
58-
retry = 0
59-
retry += 1
60-
if retry > 10:
61-
print(f'document session {document_session_id} {type_} exceeded max retries')
62-
retry_report.append(f'session {document_session_id} {type_} exceeded max retries')
63-
else:
64-
with open(hash_retry_file, 'w') as f:
65-
f.write(str(retry))
66-
os.remove(hash_file)
67-
print(f'document session {document_session_id} {type_} retry {retry}')
27+
hash_filepath = f'{parsed_filepath}.hash'
28+
retry_filepath = f'{parsed_filepath}.retry'
29+
if os.path.exists(retry_filepath):
30+
with open(retry_filepath, 'r') as f:
31+
retry_num = int(f.read().strip())
32+
else:
33+
retry_num = 0
34+
if retry_num >= 10:
35+
print(f'parse_retry_error({type_}): document session id {document_session_id} exceeded max retries')
36+
stats[f'parse_retry_error({type_}): exceeded max retries'] += 1
37+
else:
38+
retry_num += 1
39+
print(f'parse_retry_error({type_}): document session id {document_session_id} retry {retry_num}')
40+
stats[f'parse_retry_error({type_}): will retry'] += 1
41+
for filepath in [download_filepath, parsed_filepath, hash_filepath]:
42+
if os.path.exists(filepath):
43+
os.remove(filepath)
44+
with open(retry_filepath, 'w') as f:
45+
f.write(str(retry_num))
6846

6947

7048
def update_row_stats(row, stats):
@@ -89,7 +67,6 @@ def update_row_stats(row, stats):
8967

9068
def process_rows(rows):
9169
stats = defaultdict(int)
92-
retry_report = []
9370
protocol_session_rows = {}
9471
for row in rows:
9572
stats['total_rows'] += 1
@@ -102,17 +79,15 @@ def process_rows(rows):
10279
else:
10380
stats['protocol_rows'] += 1
10481
update_row_stats(row, stats)
105-
# parse_retry('text', row['text_error'], row['DocumentCommitteeSessionID'], retry_report)
106-
# parse_retry('parts', row['parts_error'], row['DocumentCommitteeSessionID'], retry_report)
82+
parse_retry_error('text', row['text_error'], row['DocumentCommitteeSessionID'], row['GroupTypeID'], row['ApplicationDesc'], stats)
83+
parse_retry_error('parts', row['parts_error'], row['DocumentCommitteeSessionID'], row['GroupTypeID'], row['ApplicationDesc'], stats)
10784
protocol_session_rows.setdefault(row['CommitteeSessionID'], []).append(row)
10885
for session_id, rows in protocol_session_rows.items():
10986
if len(rows) > 1:
11087
good_rows = [row for row in rows if row['text_filesize'] > 0]
11188
if len(good_rows) > 0:
11289
rows = good_rows
11390
row = rows[0]
114-
# legacy_fix('text', row)
115-
# legacy_fix('parts', row)
11691
stats['yielded_protocol_rows'] += 1
11792
yield row
11893
for k, v in stats.items():

committees/knesset.source-spec.yaml

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -329,39 +329,8 @@ sync-documents:
329329
target: "gs://knesset-data-pipelines/data/committees/meeting_protocols_parts"
330330

331331

332-
kns_committeesession:
333-
description: |
334-
כל ישיבות הועדה, כולל מידע מקושר וקישור לפרוטוקול הישיבה בפורמטים שונים.
335-
הפרוטוקולים זמינים בפורמטים הבאים: קבצי המקור, קבצים טקסטואליים וקובץ מחולק לפי דוברים.
336-
ניתן להוריד את הקבצים מהתיקיות הבאות באמצעות הוספת הנתיב שמופיע בנתונים לכתובות הבאות:
337-
עבור קבצי טקסט - https://production.oknesset.org/pipelines/data/committees/meeting_protocols_text/
338-
עבור קבצים מחולקים לדוברים - https://production.oknesset.org/pipelines/data/committees/meeting_protocols_parts/
339-
dependencies:
340-
- pipeline: ./committees/kns_committee
341-
- datapackage: data/committees/kns_committee/datapackage.json
342-
- pipeline: ./committees/kns_cmtsessionitem
343-
- datapackage: data/committees/kns_cmtsessionitem/datapackage.json
344-
# - pipeline: ./committees/kns_documentcommitteesession
345-
- datapackage: data/committees/committees_parsed_document_committee_sessions/datapackage.json
346-
- pipeline: ./bills/kns_bill
347-
- datapackage: data/bills/kns_bill/datapackage.json
348-
pre-steps:
349-
- run: load_resource
350-
parameters:
351-
url: ../data/committees/kns_committee/datapackage.json
352-
resource: kns_committee
353-
- run: load_resource
354-
parameters:
355-
url: ../data/committees/kns_cmtsessionitem/datapackage.json
356-
resource: kns_cmtsessionitem
357-
- run: load_resource
358-
parameters:
359-
url: ../data/committees/committees_parsed_document_committee_sessions/datapackage.json
360-
resource: kns_documentcommitteesession
361-
- run: load_resource
362-
parameters:
363-
url: ../data/bills/kns_bill/datapackage.json
364-
resource: kns_bill
332+
kns_committeesession_dataservice:
333+
dpp_disabled: true # migrated to airflow
365334
pipeline-type: knesset dataservice
366335
schemas-bucket: "committees"
367336
dataservice-parameters:
@@ -423,7 +392,47 @@ kns_committeesession:
423392
source: "{name}"
424393
type: datetime
425394
description: תאריך עדכון אחרון
426-
additional-steps:
395+
396+
397+
kns_committeesession:
398+
description: |
399+
כל ישיבות הועדה, כולל מידע מקושר וקישור לפרוטוקול הישיבה בפורמטים שונים.
400+
הפרוטוקולים זמינים בפורמטים הבאים: קבצי המקור, קבצים טקסטואליים וקובץ מחולק לפי דוברים.
401+
ניתן להוריד את הקבצים מהתיקיות הבאות באמצעות הוספת הנתיב שמופיע בנתונים לכתובות הבאות:
402+
עבור קבצי טקסט - https://production.oknesset.org/pipelines/data/committees/meeting_protocols_text/
403+
עבור קבצים מחולקים לדוברים - https://production.oknesset.org/pipelines/data/committees/meeting_protocols_parts/
404+
dependencies:
405+
- pipeline: ./committees/kns_committee
406+
- datapackage: data/committees/kns_committee/datapackage.json
407+
- pipeline: ./committees/kns_cmtsessionitem
408+
- datapackage: data/committees/kns_cmtsessionitem/datapackage.json
409+
# - pipeline: ./committees/kns_documentcommitteesession
410+
- datapackage: data/committees/committees_parsed_document_committee_sessions/datapackage.json
411+
- pipeline: ./bills/kns_bill
412+
- datapackage: data/bills/kns_bill/datapackage.json
413+
- pipeline: ./committees/kns_committeesession_dataservice
414+
- datapackage: data/committees/kns_committeesession_dataservice/datapackage.json
415+
pipeline:
416+
- run: load_resource
417+
parameters:
418+
url: ../data/committees/kns_committee/datapackage.json
419+
resource: kns_committee
420+
- run: load_resource
421+
parameters:
422+
url: ../data/committees/kns_cmtsessionitem/datapackage.json
423+
resource: kns_cmtsessionitem
424+
- run: load_resource
425+
parameters:
426+
url: ../data/committees/committees_parsed_document_committee_sessions/datapackage.json
427+
resource: kns_documentcommitteesession
428+
- run: load_resource
429+
parameters:
430+
url: ../data/bills/kns_bill/datapackage.json
431+
resource: kns_bill
432+
- run: load_resource
433+
parameters:
434+
url: ../data/committees/kns_committeesession_dataservice/datapackage.json
435+
resource: kns_committeesession_dataservice
427436
- run: filter_document_committee_sessions
428437
- run: join
429438
parameters:

0 commit comments

Comments
 (0)