From 690467e96068495777759dbe153180619bad88e3 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 20 Sep 2023 10:21:10 +0100 Subject: [PATCH 1/3] Adding log statement to the flip text blocks method. --- src/cpr_data_access/parser_models.py | 36 ++++++++++++++++------------ 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/cpr_data_access/parser_models.py b/src/cpr_data_access/parser_models.py index 2998394..22c4607 100644 --- a/src/cpr_data_access/parser_models.py +++ b/src/cpr_data_access/parser_models.py @@ -328,21 +328,27 @@ def vertically_flip_text_block_coords(self: _PO) -> _PO: page.page_number: page.dimensions[1] for page in self.pdf_data.page_metadata } - for text_block in self.pdf_data.text_blocks: - if text_block.coords is not None and text_block.page_number is not None: - text_block.coords = [ - (x, page_height_map[text_block.page_number] - y) - for x, y in text_block.coords - ] - - # flip top and bottom so y values are still increasing as you go - # through the coordinates list - text_block.coords = [ - text_block.coords[3], - text_block.coords[2], - text_block.coords[1], - text_block.coords[0], - ] + try: + for text_block in self.pdf_data.text_blocks: + if text_block.coords is not None and text_block.page_number is not None: + text_block.coords = [ + (x, page_height_map[text_block.page_number] - y) + for x, y in text_block.coords + ] + + # flip top and bottom so y values are still increasing as you go + # through the coordinates list + text_block.coords = [ + text_block.coords[3], + text_block.coords[2], + text_block.coords[1], + text_block.coords[0], + ] + except Exception: + logger.exception( + "Error flipping text block coordinates.", + extra={"props": {"document_id": self.document_id}}, + ) return self From 07a46a3b78da903a9dddc5296f7018c27811455b Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 20 Sep 2023 10:21:46 +0100 Subject: [PATCH 2/3] Re-raising the exception that was initially raised. --- src/cpr_data_access/parser_models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cpr_data_access/parser_models.py b/src/cpr_data_access/parser_models.py index 22c4607..9b57677 100644 --- a/src/cpr_data_access/parser_models.py +++ b/src/cpr_data_access/parser_models.py @@ -349,6 +349,7 @@ def vertically_flip_text_block_coords(self: _PO) -> _PO: "Error flipping text block coordinates.", extra={"props": {"document_id": self.document_id}}, ) + raise return self From bd3a3dd0ee54ef9fff79371c6d82042ea5b81b52 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 20 Sep 2023 11:22:09 +0100 Subject: [PATCH 3/3] Removing the raising of the exception. --- src/cpr_data_access/parser_models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cpr_data_access/parser_models.py b/src/cpr_data_access/parser_models.py index 9b57677..22c4607 100644 --- a/src/cpr_data_access/parser_models.py +++ b/src/cpr_data_access/parser_models.py @@ -349,7 +349,6 @@ def vertically_flip_text_block_coords(self: _PO) -> _PO: "Error flipping text block coordinates.", extra={"props": {"document_id": self.document_id}}, ) - raise return self