|
9 | 9 | from pystac_monty.geocoding import MontyGeoCoder
|
10 | 10 |
|
11 | 11 |
|
| 12 | +class TransformSummaryInProgressException(Exception): ... |
| 13 | + |
| 14 | + |
| 15 | +@dataclass |
| 16 | +class TransformSummary: |
| 17 | + total_rows: int = 0 |
| 18 | + failed_rows: int = 0 |
| 19 | + is_completed: bool = False |
| 20 | + |
| 21 | + def increment_rows(self, increment=1): |
| 22 | + self.total_rows += increment |
| 23 | + |
| 24 | + def increment_failed_rows(self, increment=1): |
| 25 | + self.failed_rows += increment |
| 26 | + |
| 27 | + def mark_as_complete(self): |
| 28 | + self.is_completed = True |
| 29 | + |
| 30 | + def mark_as_started(self): |
| 31 | + self.is_completed = False |
| 32 | + self.total_rows = 0 |
| 33 | + self.failed_rows = 0 |
| 34 | + |
| 35 | + @property |
| 36 | + def success_rows(self) -> int: |
| 37 | + if not self.is_completed: |
| 38 | + raise TransformSummaryInProgressException() |
| 39 | + return self.total_rows - self.failed_rows |
| 40 | + |
| 41 | + |
12 | 42 | @dataclass
|
13 | 43 | class MontyDataSource:
|
14 | 44 | source_url: str
|
@@ -60,6 +90,8 @@ def __init__(self, data_source: DataSource, geocoder: MontyGeoCoder):
|
60 | 90 |
|
61 | 91 | self.geocoder = geocoder
|
62 | 92 |
|
| 93 | + self.transform_summary = TransformSummary() |
| 94 | + |
63 | 95 | def get_event_collection(self) -> Collection:
|
64 | 96 | """Get event collection"""
|
65 | 97 | if self._event_collection_cache is None:
|
@@ -108,5 +140,9 @@ def get_impact_collection(self) -> Collection:
|
108 | 140 | self._impact_collection_cache = collection
|
109 | 141 | return self._impact_collection_cache
|
110 | 142 |
|
| 143 | + # FIXME: This method is deprecated |
111 | 144 | @abc.abstractmethod
|
112 | 145 | def make_items(self) -> list[Item]: ...
|
| 146 | + |
| 147 | + @abc.abstractmethod |
| 148 | + def get_stac_items(self) -> typing.Generator[Item, None, None]: ... |
0 commit comments