Skip to content
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

ignore ahb tables where no pruefi is provided #371

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/kohlrahbi/ahb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ def extract_pruefis_from_table(table: Table) -> list[str]:

def table_header_contains_text_pruefidentifikator(table: Table) -> bool:
"""Checks if the table header contains the text 'Prüfidentifikator'."""
return table.row_cells(0)[-1].paragraphs[-1].text.startswith("Prüfidentifikator") # type:ignore[no-any-return]
pattern = r"Prüfidentifikator(?:\t){0,10}\t\d+"
# "matches "Prüfidentifikator" followed by at least 1 tab separated numbers, max 11 pruefis is chosen arbitrarily
return bool(re.search(pattern, table.row_cells(0)[-1].text))
Comment on lines +192 to +194
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hf-kklein gab es hier nicht noch ein anderes pattern was das pattern irgendwie compiled hat?
Ziel war es dass das regex nur einmal ausgeführt werden muss.

Oft haben wir das pattern global ausgelagert und dann in der Funktion nur angewendet.

Weißt du was ich meine?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my_pattern = re.comile(r"Prüfidentifikator(?:\t){0,10}\t\d+")

und dann mypattern.search(...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bringt dann was, wenn die funktion sehr oft aufgerufen wird. wobei auch so der regex-teil einen internen cache hat iirc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. Die Funktion wir in jeder Tabelle aufgerufen. Aber wenn sie einen internen Cache hat passt das.



def get_pruefi_to_file_mapping(basic_input_path: Path, format_version: EdifactFormatVersion) -> dict[str, str]:
Expand Down