1+ import abc
12import json
3+ import typing
24from dataclasses import dataclass
3- from typing import Any
45
56import requests
6- from pystac import Collection
7+ from pystac import Collection , Item
8+
9+ from pystac_monty .geocoding import MontyGeoCoder
710
811
912@dataclass
1013class MontyDataSource :
1114 source_url : str
12- data : Any
15+ data : typing . Any
1316
14- def __init__ (self , source_url : str , data : Any ):
17+ def __init__ (self , source_url : str , data : typing . Any ):
1518 self .source_url = source_url
1619 self .data = data
1720
1821 def get_source_url (self ) -> str :
1922 return self .source_url
2023
21- def get_data (self ) -> Any :
24+ def get_data (self ) -> typing . Any :
2225 return self .data
2326
2427
28+ DataSource = typing .TypeVar ("DataSource" )
29+
30+
2531@dataclass
26- class MontyDataTransformer :
27- events_collection_id : str
28- events_collection_url : str
29- hazards_collection_id : str
30- hazards_collection_url : str
31- impacts_collection_id : str
32- impacts_collection_url : str
32+ class MontyDataTransformer (typing .Generic [DataSource ]):
33+ # FIXME: Add a validation in subclass so that source_name is always defined
34+ source_name : str
35+
36+ _event_collection_cache : Collection | None = None
37+ _hazard_collection_cache : Collection | None = None
38+ _impact_collection_cache : Collection | None = None
39+
40+ # FIXME: Get this from submodule
41+ base_collection_url = "https://github.com/IFRCGo/monty-stac-extension/raw/refs/heads/main/examples"
3342
3443 # FIXME: we might have to get ids and urls manually
35- def __init__ (self , source_name : str ):
36- self .events_collection_id = f"{ source_name } -events"
37- self .hazards_collection_id = f"{ source_name } -hazards"
38- self .impacts_collection_id = f"{ source_name } -impacts"
44+ def __init__ (self , data_source : DataSource , geocoder : MontyGeoCoder ):
45+ self .events_collection_id = f"{ self .source_name } -events"
46+ self .hazards_collection_id = f"{ self .source_name } -hazards"
47+ self .impacts_collection_id = f"{ self .source_name } -impacts"
48+
49+ self .data_source = data_source
3950
4051 self .events_collection_url = (
4152 f"{ MontyDataTransformer .base_collection_url } /{ self .events_collection_id } /{ self .events_collection_id } .json"
@@ -47,10 +58,7 @@ def __init__(self, source_name: str):
4758 f"{ MontyDataTransformer .base_collection_url } /{ self .impacts_collection_id } /{ self .impacts_collection_id } .json"
4859 )
4960
50- _event_collection_cache = None
51- _hazard_collection_cache = None
52- _impact_collection_cache = None
53- base_collection_url = "https://github.com/IFRCGo/monty-stac-extension/raw/refs/heads/main/examples"
61+ self .geocoder = geocoder
5462
5563 def get_event_collection (self ) -> Collection :
5664 """Get event collection"""
@@ -99,3 +107,6 @@ def get_impact_collection(self) -> Collection:
99107 collection .set_self_href (self .impacts_collection_url )
100108 self ._impact_collection_cache = collection
101109 return self ._impact_collection_cache
110+
111+ @abc .abstractmethod
112+ def make_items (self ) -> list [Item ]: ...
0 commit comments