-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Module containing class for dictionary object""" | ||
import json | ||
from typing import Dict | ||
from sumo.wrapper import SumoClient | ||
from fmu.sumo.explorer.objects._child import Child | ||
|
||
|
||
class Dictionary(Child): | ||
"""Class representig a dictionary object in Sumo""" | ||
|
||
_parsed: dict | ||
|
||
def __init__(self, sumo: SumoClient, metadata: Dict) -> None: | ||
""" | ||
Args: | ||
sumo (SumoClient): connection to Sumo | ||
metadata (dict): dictionary metadata | ||
""" | ||
self._parsed = None | ||
|
||
super().__init__(sumo, metadata) | ||
|
||
@property | ||
def blob(self) -> bytes: | ||
"""Object blob""" | ||
if self._blob is None: | ||
res = self._sumo.get(f"/objects('{self.uuid}')/blob") | ||
self._blob = res | ||
|
||
return self._blob | ||
|
||
def parse(self) -> Dict: | ||
if self._parsed is None: | ||
self._parsed = json.loads(self.blob.decode("utf-8")) | ||
|
||
return self._parsed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"""Module containing class for colection of dictionaries """ | ||
from typing import Union, List, Dict | ||
from sumo.wrapper import SumoClient | ||
from fmu.sumo.explorer.objects._child_collection import ChildCollection | ||
from fmu.sumo.explorer.pit import Pit | ||
from fmu.sumo.explorer.objects.dictionary import Dictionary | ||
|
||
|
||
class DictionaryCollection(ChildCollection): | ||
"""Class for representing a collection of dictionaries objects in Sumo""" | ||
|
||
def __init__( | ||
self, | ||
sumo: SumoClient, | ||
case_uuid: str, | ||
query: Dict = None, | ||
pit: Pit = None, | ||
): | ||
""" | ||
Args: | ||
sumo (SumoClient): connection to Sumo | ||
case_uuid (str): parent case uuid | ||
query (dict): elastic query object | ||
pit (Pit): point in time | ||
""" | ||
super().__init__("dictionary", sumo, case_uuid, query, pit) | ||
|
||
def __getitem__(self, index) -> Dictionary: | ||
doc = super().__getitem__(index) | ||
return Dictionary(self._sumo, doc) | ||
|
||
def filter( | ||
self, | ||
name: Union[str, List[str], bool] = None, | ||
tagname: Union[str, List[str], bool] = None, | ||
iteration: Union[str, List[str], bool] = None, | ||
realization: Union[int, List[int], bool] = None, | ||
aggregation: Union[str, List[str], bool] = None, | ||
stage: Union[str, List[str], bool] = None, | ||
uuid: Union[str, List[str], bool] = None, | ||
) -> "DictionaryCollection": | ||
"""Filter dictionaries | ||
Args: | ||
name (Union[str, List[str], bool]): polygon name | ||
tagname (Union[str, List[str], bool]): polygon tagname | ||
iteration (Union[int, List[int], bool]): iteration id | ||
realization Union[int, List[int], bool]: realization id | ||
uuid (Union[str, List[str], bool]): polygons object uuid | ||
Returns: | ||
DictionaryCollection: A filtered DictionaryCollection | ||
""" | ||
query = super()._add_filter( | ||
name=name, | ||
tagname=tagname, | ||
iteration=iteration, | ||
realization=realization, | ||
aggregation=aggregation, | ||
stage=stage, | ||
uuid=uuid, | ||
) | ||
|
||
return DictionaryCollection( | ||
self._sumo, self._case_uuid, query, self._pit | ||
) |