Skip to content

Commit

Permalink
Fixup II
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Sep 11, 2024
1 parent b8d237b commit f6a7cca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
29 changes: 15 additions & 14 deletions src/ert/shared/storage/summary_key_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,6 @@ class SummaryKeyType(Enum):
def determine_key_type(key: str) -> "SummaryKeyType":
if key in special_keys:
return SummaryKeyType.MISC
default_case = {
"A": SummaryKeyType.AQUIFER,
"B": SummaryKeyType.BLOCK,
"C": SummaryKeyType.COMPLETION,
"F": SummaryKeyType.FIELD,
"G": SummaryKeyType.GROUP,
"N": SummaryKeyType.NETWORK,
"S": SummaryKeyType.SEGMENT,
"W": SummaryKeyType.WELL,
}

if key.startswith("L"):
secondary = key[1] if len(key) > 1 else ""
Expand All @@ -154,16 +144,27 @@ def determine_key_type(key: str) -> "SummaryKeyType":
return SummaryKeyType.REGION

# default cases or miscellaneous if not matched
return default_case.get(key[0], SummaryKeyType.MISC)
return {
"A": SummaryKeyType.AQUIFER,
"B": SummaryKeyType.BLOCK,
"C": SummaryKeyType.COMPLETION,
"F": SummaryKeyType.FIELD,
"G": SummaryKeyType.GROUP,
"N": SummaryKeyType.NETWORK,
"S": SummaryKeyType.SEGMENT,
"W": SummaryKeyType.WELL,
}.get(key[0], SummaryKeyType.MISC)


def match_keyword_vector(start: int, rate_keys: List[str], keyword: str) -> bool:
# Get the suffix of keyword starting from 'start' index (if not out of range)
suffix = keyword[start:] if len(keyword) > start else ""
return any(suffix.startswith(key) for key in rate_keys)
if len(keyword) < start:
return False
return any(keyword[start:].startswith(key) for key in rate_keys)


def match_keyword_string(start: int, rate_string: str, keyword: str) -> bool:
if len(keyword) < start:
return False
return keyword[start:].startswith(rate_string)


Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/shared/test_rate_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ def test_is_rate_determmines_rate_key(example):


@given(key=summary_variables())
def test_rate_determination_is_consinsent(key):
def test_rate_determination_is_consistent(key):
assert Summary.is_rate(key) == is_rate(key)

0 comments on commit f6a7cca

Please sign in to comment.