Skip to content

Commit

Permalink
Remove wildcard keys from stored response configs
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Oct 23, 2024
1 parent be83598 commit 229cb35
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/ert/storage/local_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from functools import cached_property
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, Generator, List, Optional
from typing import TYPE_CHECKING, Any, Dict, Generator, List, Optional, TypedDict
from uuid import UUID

import numpy as np
Expand Down Expand Up @@ -37,6 +37,15 @@
from ert.config.responses_index import responses_index


class ResponseConfigDict(TypedDict):
keys: List[str]


def _remove_wildcard_keys(configs: Dict[str, ResponseConfigDict]):
for d in configs.values():
d["keys"] = [k for k in d["keys"] if k != "*"]


class _Index(BaseModel):
id: UUID
name: str
Expand Down Expand Up @@ -134,9 +143,12 @@ def create(
json.dumps(parameter_data, indent=2).encode("utf-8"),
)

response_data = {}
response_data: Dict[str, ResponseConfigDict] = {}
for response in responses or []:
response_data.update({response.response_type: response.to_dict()})

_remove_wildcard_keys(response_data)

storage._write_transaction(
path / cls._responses_file,
json.dumps(response_data, default=str, indent=2).encode("utf-8"),
Expand Down Expand Up @@ -335,9 +347,6 @@ def response_key_to_response_type(self) -> Dict[str, str]:
mapping = {}
for config in self.response_configuration.values():
for key in config.keys:
if key == "*":
continue

mapping[key] = config.response_type

return mapping
Expand Down Expand Up @@ -368,13 +377,16 @@ def _update_response_keys(

if diff:
config.keys = sorted(set(config.keys).union(set(new_response_keys)))
response_config_dicts = {
c.response_type: c.to_dict() for c in responses_configuration.values()
}

_remove_wildcard_keys(response_config_dicts)

self._storage._write_transaction(
self._path / self._responses_file,
json.dumps(
{
c.response_type: c.to_dict()
for c in responses_configuration.values()
},
response_config_dicts,
default=str,
indent=2,
).encode("utf-8"),
Expand Down

0 comments on commit 229cb35

Please sign in to comment.