Skip to content

Commit

Permalink
Correctly handle .cases for null context (explorer).
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond Wiker committed Sep 12, 2024
1 parent 752bb1a commit 6d6a841
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/fmu/sumo/explorer/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def __init__(
DeprecationWarning,
)

@property
def cases(self):
return self._context_for_class("case")

def get_permissions(self, asset: str = None):
"""Get permissions
Expand Down
1 change: 1 addition & 0 deletions src/fmu/sumo/explorer/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from fmu.sumo.explorer.objects._search_context import SearchContext
from fmu.sumo.explorer.objects.case import Case
from fmu.sumo.explorer.objects.cases import Cases
from fmu.sumo.explorer.objects.cube import Cube
from fmu.sumo.explorer.objects.dictionary import Dictionary
from fmu.sumo.explorer.objects.surface import Surface
Expand Down
3 changes: 2 additions & 1 deletion src/fmu/sumo/explorer/objects/_search_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,8 @@ def _context_for_class(self, cls):

@property
def cases(self):
return self._context_for_class("case")
"""Cases from current selection."""
return objects.Cases(self)

@property
def iterations(self):
Expand Down
79 changes: 79 additions & 0 deletions src/fmu/sumo/explorer/objects/cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
""" Module for searchcontext for collection of cases. """

from typing import Dict, List
from fmu.sumo.explorer.objects.case import Case
from fmu.sumo.explorer.objects._search_context import SearchContext

class Cases(SearchContext):
def __init__(self, sc):
super().__init__(sc._sumo, sc._must, sc._must_not)
return

def __len__(self):
if self._length is None:
if self._hits is None:
self._hits = self._search_all(select=False)
pass
self._length = len(self._hits)
pass
return self._length

async def length_async(self):
if self._length is None:
if self._hits is None:
self._hits = self._search_all(select=False)
pass
self._length = len(self._hits)
pass
return self._length

def _search_all(self, select=False):
return self._get_field_values("fmu.case.uuid.keyword")

async def _search_all_async(self, select=False):
return await self._get_field_values_async("fmu.case.uuid.keyword")

def _maybe_prefetch(self, index):
return

async def _maybe_prefetch_async(self, index):
return

# def get_object(self, uuid: str, select: List[str] = None) -> Dict:
# """Get metadata object by uuid

# Args:
# uuid (str): uuid of metadata object
# select (List[str]): list of metadata fields to return

# Returns:
# Dict: a metadata object
# """
# obj = self._cache.get(uuid)
# if obj is None:
# obj = self.get_case_by_uuid(uuid)
# self._cache.put(uuid, obj)
# pass

# return obj

# async def get_object_async(
# self, uuid: str, select: List[str] = None
# ) -> Dict:
# """Get metadata object by uuid

# Args:
# uuid (str): uuid of metadata object
# select (List[str]): list of metadata fields to return

# Returns:
# Dict: a metadata object
# """

# obj = self._cache.get(uuid)
# if obj is None:
# obj = await self.get_case_by_uuid_async(uuid)
# self._cache.put(uuid, obj)

# return obj

0 comments on commit 6d6a841

Please sign in to comment.