Skip to content

Commit

Permalink
LGVISIUM-102: add TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvermeeren-swisstopo committed Nov 12, 2024
1 parent 04cc5ef commit 4223b96
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/stratigraphy/depthcolumn/depthcolumnentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
from __future__ import annotations

import re
from dataclasses import dataclass
from typing import Any

import fitz
from stratigraphy.lines.line import TextWord


@dataclass
class DepthColumnEntry: # noqa: D101
"""Class to represent a depth column entry."""

def __init__(self, rect: fitz.Rect, value: float):
self.rect = rect
self.value = value
rect: fitz.Rect
value: float

def __repr__(self) -> str:
return str(self.value)
Expand Down Expand Up @@ -61,23 +62,25 @@ def find_in_words(cls, all_words: list[TextWord], include_splits: bool) -> list[
entries.append(DepthColumnEntry(word.rect, value))
elif include_splits:
# support for e.g. "1.10-1.60m" extracted as a single word
layer_depth_column_entry = AToBDepthColumnEntry.from_text(input_string, word.rect)
a_to_b_depth_column_entry = AToBDepthColumnEntry.from_text(input_string, word.rect)
entries.extend(
[layer_depth_column_entry.start, layer_depth_column_entry.end]
if layer_depth_column_entry
[a_to_b_depth_column_entry.start, a_to_b_depth_column_entry.end]
if a_to_b_depth_column_entry
else []
)
except ValueError:
pass
return entries


@dataclass
class AToBDepthColumnEntry: # noqa: D101
"""Class to represent a layer depth column entry."""
"""Class to represent a depth column entry of the form "1m - 3m"."""

def __init__(self, start: DepthColumnEntry, end: DepthColumnEntry):
self.start = start
self.end = end
# TODO do we need both this class as well as AToBInterval, or can we combine the two classes?

start: DepthColumnEntry
end: DepthColumnEntry

def __repr__(self) -> str:
return f"{self.start.value}-{self.end.value}"
Expand All @@ -89,11 +92,7 @@ def rect(self) -> fitz.Rect:

def to_json(self) -> dict[str, Any]:
"""Convert the layer depth column entry to a JSON serializable format."""
return {
"start": self.start.to_json(),
"end": self.end.to_json(),
"rect": [self.rect.x0, self.rect.y0, self.rect.x1, self.rect.y1],
}
return {"start": self.start.to_json(), "end": self.end.to_json()}

@classmethod
def from_json(cls, data: dict) -> AToBDepthColumnEntry:
Expand Down
1 change: 1 addition & 0 deletions src/stratigraphy/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def process_page(
rect=pair.block.rect,
page=page_number,
),
# TODO don't automatically convert any interval to an AAboveBInterval
depth_interval=AAboveBInterval(start=pair.depth_interval.start, end=pair.depth_interval.end)
if pair.depth_interval
else None,
Expand Down

0 comments on commit 4223b96

Please sign in to comment.