From f42cc6cdef723ad21cc7b1087e24df7b5b1362d7 Mon Sep 17 00:00:00 2001 From: anders-albert Date: Sun, 6 Oct 2024 07:50:02 +0200 Subject: [PATCH 001/122] tmp: happy mypy locally --- cognite/client/data_classes/assets.py | 2 +- cognite/client/utils/_concurrency.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cognite/client/data_classes/assets.py b/cognite/client/data_classes/assets.py index 146fa8399..beb3b3a9a 100644 --- a/cognite/client/data_classes/assets.py +++ b/cognite/client/data_classes/assets.py @@ -890,7 +890,7 @@ def _count_subtree(xid: str, count: int = 0) -> int: counts.sort(key=lambda args: -args[-1]) # The count for the fictitious "root of roots" is just len(assets), so we remove it: (count_dct := dict(counts)).pop(None, None) - return count_dct + return count_dct # type: ignore[return-value] def _on_error(self, on_error: Literal["ignore", "warn", "raise"], message: str) -> None: if on_error == "warn": diff --git a/cognite/client/utils/_concurrency.py b/cognite/client/utils/_concurrency.py index e0684ad66..b3277ab5a 100644 --- a/cognite/client/utils/_concurrency.py +++ b/cognite/client/utils/_concurrency.py @@ -184,7 +184,7 @@ def uses_mainthread(cls) -> bool: @classmethod def get_executor(cls, max_workers: int) -> TaskExecutor: if cls.uses_threadpool(): - return cls.get_thread_pool_executor(max_workers) + return cls.get_thread_pool_executor(max_workers) # type: ignore[return-value] elif cls.uses_mainthread(): return cls.get_mainthread_executor() raise RuntimeError(f"Invalid executor type '{cls.executor_type}'") From 8e936c227f7a8f7bd378457e5eef9cdc69575c50 Mon Sep 17 00:00:00 2001 From: anders-albert Date: Sun, 6 Oct 2024 07:51:23 +0200 Subject: [PATCH 002/122] refactor: generated data and api classes --- cognite/client/_api/simulators/simulators.py | 133 +++++++ .../data_classes/simulators/simulators.py | 342 ++++++++++++++++++ 2 files changed, 475 insertions(+) create mode 100644 cognite/client/_api/simulators/simulators.py create mode 100644 cognite/client/data_classes/simulators/simulators.py diff --git a/cognite/client/_api/simulators/simulators.py b/cognite/client/_api/simulators/simulators.py new file mode 100644 index 000000000..24a8e03c0 --- /dev/null +++ b/cognite/client/_api/simulators/simulators.py @@ -0,0 +1,133 @@ +from __future__ import annotations + +from collections.abc import Iterator +from typing import TYPE_CHECKING, Any, Sequence, overload + +from cognite.client._api_client import APIClient +from cognite.client._constants import DEFAULT_LIMIT_READ +from cognite_gen.client.data_classes.simulators.simulators import Simulator, SimulatorList, SimulatorUpdate, SimulatorWrite +from cognite.client.utils._experimental import FeaturePreviewWarning +from cognite.client.utils._identifier import IdentifierSequence +from cognite.client.utils.useful_types import SequenceNotStr + +if TYPE_CHECKING: + from cognite.client import ClientConfig, CogniteClient + + +class SimulatorsAPI(APIClient): + _RESOURCE_PATH = "/simulators" + def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: + super().__init__(config, api_version, cognite_client) + self._warning = FeaturePreviewWarning( + api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators" + ) + + def create(self, simulator_create_command: SimulatorWrite | Sequence[SimulatorWrite]) -> Simulator: + """`Create Simulators `_ + + Create a simulator entry in the Simulator Integration framework. + + Args: + simulator_create_command (SimulatorWrite | Sequence[SimulatorWrite]): None + + Returns: + Simulator: None + + Examples: + + Create simulator: + + >>> from cognite.client import CogniteClient + >>> from cognite.client.data_classes.simulators import SimulatorWrite + >>> client = CogniteClient() + >>> simulator = SimulatorWrite() + >>> res = client.hosted_extractors.destinations.create(simulator) + + """ + self._warning.warn() + return self._create_multiple( + list_cls=SimulatorList, + resource_cls=Simulator, + items=simulator_create_command, + input_resource_cls=SimulatorWrite, + headers={"cdf-version": "beta"}, + ) + + def update(self, simulator_update_command: SimulatorUpdate | Sequence[SimulatorUpdate]) -> Simulator: + """`Update Simulators `_ + + Update simulators + + Args: + simulator_update_command (SimulatorUpdate | Sequence[SimulatorUpdate]): None + + Returns: + Simulator: None + + Examples: + + Update simulator: + + >>> from cognite.client import CogniteClient + >>> from cognite.client.data_classes.simulators import SimulatorUpdate + >>> client = CogniteClient() + >>> update = SimulatorUpdate('mySimulator'). + >>> res = client.simulators.update(update) + + """ + self._warning.warn() + return self._update_multiple( + items=simulator_update_command, + list_cls=SimulatorList, + resource_cls=Simulator, + update_cls=SimulatorUpdate, + headers={"cdf-version": "beta"}, + ) + + def delete(self, unknown: Unknown) -> EmptyResponse | None: + """`Delete Simulators `_ + + Delete simulators + + Args: + unknown (Unknown): None + + Returns: + EmptyResponse | None: None + + Examples: + + Delete simulator: + + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> client.simulators.delete(["mySimulator", "mySimulator2"]) + + + """ + self._warning.warn() + return self._delete_multiple( + identifiers=IdentifierSequence.load(unknowns=unknown), + wrap_ids=False, + returns_items=False, + headers={"cdf-version": "beta"}, + ) + + def filter(self, limit: int, filter: ListSimulatorsFilters | None = None) -> Simulator: + """`Filter Simulators `_ + + List simulators + + Args: + limit (int): None + filter (ListSimulatorsFilters | None): None + + Returns: + Simulator: None + + Examples: + + + + """ + "" diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py new file mode 100644 index 000000000..cd459d9b2 --- /dev/null +++ b/cognite/client/data_classes/simulators/simulators.py @@ -0,0 +1,342 @@ +from __future__ import annotations + +from abc import ABC +from dataclasses import dataclass +from typing import TYPE_CHECKING, Any, NoReturn, Sequence + +from typing_extensions import Self + +from cognite.client.utils.useful_types import SequenceNotStr +from cognite.client.data_classes._base import ( + CogniteObject, + CognitePrimitiveUpdate, + CogniteResource, + CogniteResourceList, + CogniteUpdate, + ExternalIDTransformerMixin, + PropertySpec, + WriteableCogniteResource, + WriteableCogniteResourceList, +) + +if TYPE_CHECKING: + from cognite.client import CogniteClient + + +@dataclass +class SimulatorUnitEntry(CogniteObject): + label: str + name: str + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + label=resource["label"], + name=resource["name"], + ) + + +@dataclass +class SimulatorStepOption(CogniteObject): + label: str + value: str + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + label=resource["label"], + value=resource["value"], + ) + + + + +@dataclass +class SimulatorModelType(CogniteObject): + name: str + key: str + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + name=resource["name"], + key=resource["key"], + ) + + + + +@dataclass +class SimulatorQuantity(CogniteObject): + name: str + label: str + units: SimulatorUnitEntry | Sequence[SimulatorUnitEntry] + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + name=resource["name"], + label=resource["label"], + units=SimulatorUnitEntry._load(resource["units"], cognite_client), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + output = super().dump(camel_case=camel_case) + output["units"] = self.units.dump(camel_case=camel_case) + + return output + + + +@dataclass +class SimulatorStepField(CogniteObject): + name: str + label: str + info: str + options: SimulatorStepOption | Sequence[SimulatorStepOption] | None + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + name=resource["name"], + label=resource["label"], + info=resource["info"], + options=SimulatorStepOption._load(resource["options"], cognite_client) if "options" in resource else None, + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + output = super().dump(camel_case=camel_case) + if isinstance(self.options, SimulatorStepOption): + output["options"] = self.options.dump(camel_case=camel_case) + + return output + + + +@dataclass +class SimulatorStep(CogniteObject): + step_type: str + fields: SimulatorStepField | Sequence[SimulatorStepField] + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + step_type=resource["stepType"], + fields=SimulatorStepField._load(resource["fields"], cognite_client), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + output = super().dump(camel_case=camel_case) + output["fields"] = self.fields.dump(camel_case=camel_case) + + return output + + +class _SimulatorCore(WriteableCogniteResource["SimulatorWrite"], ABC): + def __init__(self, external_id: str, name: str, file_extension_types: str | SequenceNotStr[str], model_types: SimulatorModelType | Sequence[SimulatorModelType], step_fields: SimulatorStep | Sequence[SimulatorStep], unit_quantities: SimulatorQuantity | Sequence[SimulatorQuantity] | None = None) -> None: + self.external_id = external_id + self.name = name + self.file_extension_types = file_extension_types + self.model_types = model_types + self.step_fields = step_fields + self.unit_quantities = unit_quantities + + +class SimulatorWrite(_SimulatorCore): + """The simulator resource contains the definitions necessary for Cognite Data Fusion (CDF) to interact with a given simulator. + + It serves as a central contract that allows APIs, UIs, and integrations (connectors) to utilize the same definitions + when dealing with a specific simulator. Each simulator is uniquely identified and can be associated with various + file extension types, model types, step fields, and unit quantities. Simulators are essential for managing data + flows between CDF and external simulation tools, ensuring consistency and reliability in data handling. #### + Limitations: - A project can have a maximum of 100 simulators + + This is the write/request format of the simulator. + + Args: + external_id (str): External id of the simulator + name (str): Name of the simulator + file_extension_types (str | SequenceNotStr[str]): File extension types supported by the simulator + model_types (SimulatorModelType | Sequence[SimulatorModelType]): Model types supported by the simulator + step_fields (SimulatorStep | Sequence[SimulatorStep]): Step types supported by the simulator when creating routines + unit_quantities (SimulatorQuantity | Sequence[SimulatorQuantity] | None): Quantities and their units supported by the simulator + + """ + + def __init__(self, external_id: str, name: str, file_extension_types: str | SequenceNotStr[str], model_types: SimulatorModelType | Sequence[SimulatorModelType], step_fields: SimulatorStep | Sequence[SimulatorStep], unit_quantities: SimulatorQuantity | Sequence[SimulatorQuantity] | None = None) -> None: + super().__init__( + external_id=external_id, + name=name, + file_extension_types=file_extension_types, + model_types=model_types, + step_fields=step_fields, + unit_quantities=unit_quantities, + ) + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + external_id=resource["externalId"], + name=resource["name"], + file_extension_types=resource["fileExtensionTypes"], + model_types=SimulatorModelType._load(resource["modelTypes"], cognite_client), + step_fields=SimulatorStep._load(resource["stepFields"], cognite_client), + unit_quantities=SimulatorQuantity._load(resource["unitQuantities"], cognite_client) if "unitQuantities" in resource else None, + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + output = super().dump(camel_case=camel_case) + output["modelTypes" if camel_case else "model_types"] = self.model_types.dump(camel_case=camel_case) + output["stepFields" if camel_case else "step_fields"] = self.step_fields.dump(camel_case=camel_case) + if isinstance(self.unit_quantities, SimulatorQuantity): + output["unitQuantities" if camel_case else "unit_quantities"] = self.unit_quantities.dump(camel_case=camel_case) + + return output + def as_write(self) -> SimulatorWrite: + return self + + + +class Simulator(_SimulatorCore): + """The simulator resource contains the definitions necessary for Cognite Data Fusion (CDF) to interact with a given simulator. + + It serves as a central contract that allows APIs, UIs, and integrations (connectors) to utilize the same definitions + when dealing with a specific simulator. Each simulator is uniquely identified and can be associated with various + file extension types, model types, step fields, and unit quantities. Simulators are essential for managing data + flows between CDF and external simulation tools, ensuring consistency and reliability in data handling. #### + Limitations: - A project can have a maximum of 100 simulators + + This is the read/response format of the simulator. + + Args: + id (int): A unique id of a simulator + external_id (str): External id of the simulator + name (str): Name of the simulator + file_extension_types (str | SequenceNotStr[str]): File extension types supported by the simulator + model_types (SimulatorModelType | Sequence[SimulatorModelType] | None): Model types supported by the simulator + step_fields (SimulatorStep | Sequence[SimulatorStep] | None): Step types supported by the simulator when creating routines + unit_quantities (SimulatorQuantity | Sequence[SimulatorQuantity] | None): Quantities and their units supported by the simulator + created_time (int): None + last_updated_time (int): None + + """ + + def __init__(self, id: int, external_id: str, name: str, file_extension_types: str | SequenceNotStr[str], created_time: int, last_updated_time: int, model_types: SimulatorModelType | Sequence[SimulatorModelType] | None = None, step_fields: SimulatorStep | Sequence[SimulatorStep] | None = None, unit_quantities: SimulatorQuantity | Sequence[SimulatorQuantity] | None = None) -> None: + super().__init__( + external_id=external_id, + name=name, + file_extension_types=file_extension_types, + model_types=model_types, + step_fields=step_fields, + unit_quantities=unit_quantities, + ) + self.id = id + self.created_time = created_time + self.last_updated_time = last_updated_time + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + id=resource["id"], + external_id=resource["externalId"], + name=resource["name"], + file_extension_types=resource["fileExtensionTypes"], + created_time=resource["createdTime"], + last_updated_time=resource["lastUpdatedTime"], + model_types=SimulatorModelType._load(resource["modelTypes"], cognite_client) if "modelTypes" in resource else None, + step_fields=SimulatorStep._load(resource["stepFields"], cognite_client) if "stepFields" in resource else None, + unit_quantities=SimulatorQuantity._load(resource["unitQuantities"], cognite_client) if "unitQuantities" in resource else None, + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + output = super().dump(camel_case=camel_case) + if isinstance(self.model_types, SimulatorModelType): + output["modelTypes" if camel_case else "model_types"] = self.model_types.dump(camel_case=camel_case) + if isinstance(self.step_fields, SimulatorStep): + output["stepFields" if camel_case else "step_fields"] = self.step_fields.dump(camel_case=camel_case) + if isinstance(self.unit_quantities, SimulatorQuantity): + output["unitQuantities" if camel_case else "unit_quantities"] = self.unit_quantities.dump(camel_case=camel_case) + + return output + + + def as_write(self) -> SimulatorWrite: + return SimulatorWrite( + unit_quantities=self.unit_quantities, + name=self.name, + model_types=self.model_types, + external_id=self.external_id, + step_fields=self.step_fields, + file_extension_types=self.file_extension_types, + ) + + +class SimulatorUpdate(CogniteUpdate): + def __init__(self, id: int) -> None: + super().__init__( + id = id, + ) + + class _UpdateSetAnnotatedStringConstraintsUpdate(CognitePrimitiveUpdate): + def set(self, value: UpdateSetAnnotatedStringConstraints | None) -> SimulatorUpdate: + return self._set(value.dump() if isinstance(value, UpdateSetAnnotatedStringConstraints) else value) + + class _UpdateSetListUpdate(CognitePrimitiveUpdate): + def set(self, value: UpdateSetList | None) -> SimulatorUpdate: + return self._set(value.dump() if isinstance(value, UpdateSetList) else value) + + class _UpdateSetListSimulatorModelTypeUpdate(CognitePrimitiveUpdate): + def set(self, value: UpdateSetListSimulatorModelType | None) -> SimulatorUpdate: + return self._set(value.dump() if isinstance(value, UpdateSetListSimulatorModelType) else value) + + class _UpdateSetListSimulatorStepUpdate(CognitePrimitiveUpdate): + def set(self, value: UpdateSetListSimulatorStep | None) -> SimulatorUpdate: + return self._set(value.dump() if isinstance(value, UpdateSetListSimulatorStep) else value) + + class _UpdateSetList1kSimulatorQuantityUpdate(CognitePrimitiveUpdate): + def set(self, value: UpdateSetList1kSimulatorQuantity | None) -> SimulatorUpdate: + return self._set(value.dump() if isinstance(value, UpdateSetList1kSimulatorQuantity) else value) + + + @property + def name(self) -> SimulatorUpdate._UpdateSetAnnotatedStringConstraintsUpdate: + return self._UpdateSetAnnotatedStringConstraintsUpdate(self, "name") + + @property + def file_extension_types(self) -> SimulatorUpdate._UpdateSetListUpdate: + return self._UpdateSetListUpdate(self, "file_extension_types") + + @property + def model_types(self) -> SimulatorUpdate._UpdateSetListSimulatorModelTypeUpdate: + return self._UpdateSetListSimulatorModelTypeUpdate(self, "model_types") + + @property + def step_fields(self) -> SimulatorUpdate._UpdateSetListSimulatorStepUpdate: + return self._UpdateSetListSimulatorStepUpdate(self, "step_fields") + + @property + def unit_quantities(self) -> SimulatorUpdate._UpdateSetList1kSimulatorQuantityUpdate: + return self._UpdateSetList1kSimulatorQuantityUpdate(self, "unit_quantities") + + + @classmethod + def _get_update_properties(cls, item: CogniteResource | None = None) -> list[PropertySpec]: + return [ + PropertySpec("name", is_nullable=True), + PropertySpec("file_extension_types", is_nullable=True), + PropertySpec("model_types", is_nullable=True), + PropertySpec("step_fields", is_nullable=True), + PropertySpec("unit_quantities", is_nullable=True), + ] + + +class SimulatorWriteList(CogniteResourceList[SimulatorWrite]): + _RESOURCE = SimulatorWrite + + +class SimulatorList(WriteableCogniteResourceList[SimulatorWrite, Simulator]): + _RESOURCE = Simulator + + def as_write(self) -> SimulatorWriteList: + return SimulatorWriteList([item.as_write() for item in self.data]) + From 67f36801ca06834b4630698dce6a6d0e7b5948d9 Mon Sep 17 00:00:00 2001 From: anders-albert Date: Sun, 6 Oct 2024 08:01:31 +0200 Subject: [PATCH 003/122] refactor: remove crud methods --- cognite/client/_api/simulators/simulators.py | 121 +------- .../data_classes/simulators/simulators.py | 259 +++++------------- 2 files changed, 76 insertions(+), 304 deletions(-) diff --git a/cognite/client/_api/simulators/simulators.py b/cognite/client/_api/simulators/simulators.py index 24a8e03c0..5499482e0 100644 --- a/cognite/client/_api/simulators/simulators.py +++ b/cognite/client/_api/simulators/simulators.py @@ -1,14 +1,11 @@ from __future__ import annotations -from collections.abc import Iterator -from typing import TYPE_CHECKING, Any, Sequence, overload +from typing import TYPE_CHECKING from cognite.client._api_client import APIClient from cognite.client._constants import DEFAULT_LIMIT_READ -from cognite_gen.client.data_classes.simulators.simulators import Simulator, SimulatorList, SimulatorUpdate, SimulatorWrite +from cognite.client.data_classes.simulators.simulators import Simulator, SimulatorList from cognite.client.utils._experimental import FeaturePreviewWarning -from cognite.client.utils._identifier import IdentifierSequence -from cognite.client.utils.useful_types import SequenceNotStr if TYPE_CHECKING: from cognite.client import ClientConfig, CogniteClient @@ -16,118 +13,30 @@ class SimulatorsAPI(APIClient): _RESOURCE_PATH = "/simulators" + def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: super().__init__(config, api_version, cognite_client) - self._warning = FeaturePreviewWarning( - api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators" - ) - - def create(self, simulator_create_command: SimulatorWrite | Sequence[SimulatorWrite]) -> Simulator: - """`Create Simulators `_ - - Create a simulator entry in the Simulator Integration framework. - - Args: - simulator_create_command (SimulatorWrite | Sequence[SimulatorWrite]): None - - Returns: - Simulator: None - - Examples: - - Create simulator: - - >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes.simulators import SimulatorWrite - >>> client = CogniteClient() - >>> simulator = SimulatorWrite() - >>> res = client.hosted_extractors.destinations.create(simulator) - - """ - self._warning.warn() - return self._create_multiple( - list_cls=SimulatorList, - resource_cls=Simulator, - items=simulator_create_command, - input_resource_cls=SimulatorWrite, - headers={"cdf-version": "beta"}, - ) - - def update(self, simulator_update_command: SimulatorUpdate | Sequence[SimulatorUpdate]) -> Simulator: - """`Update Simulators `_ - - Update simulators - - Args: - simulator_update_command (SimulatorUpdate | Sequence[SimulatorUpdate]): None - - Returns: - Simulator: None - - Examples: - - Update simulator: - - >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes.simulators import SimulatorUpdate - >>> client = CogniteClient() - >>> update = SimulatorUpdate('mySimulator'). - >>> res = client.simulators.update(update) + self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") - """ - self._warning.warn() - return self._update_multiple( - items=simulator_update_command, - list_cls=SimulatorList, - resource_cls=Simulator, - update_cls=SimulatorUpdate, - headers={"cdf-version": "beta"}, - ) + def list(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorList: + """`Filter Simulators `_ - def delete(self, unknown: Unknown) -> EmptyResponse | None: - """`Delete Simulators `_ + List simulators - Delete simulators + Args: + limit (int): The maximum number of simulators to return. Defaults to 25. Set to -1, float("inf") or None - Args: - unknown (Unknown): None - Returns: - EmptyResponse | None: None + SimulatorList: List of simulators Examples: - Delete simulator: - - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> client.simulators.delete(["mySimulator", "mySimulator2"]) + List simulators: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.list() """ self._warning.warn() - return self._delete_multiple( - identifiers=IdentifierSequence.load(unknowns=unknown), - wrap_ids=False, - returns_items=False, - headers={"cdf-version": "beta"}, - ) - - def filter(self, limit: int, filter: ListSimulatorsFilters | None = None) -> Simulator: - """`Filter Simulators `_ - - List simulators - - Args: - limit (int): None - filter (ListSimulatorsFilters | None): None - - Returns: - Simulator: None - - Examples: - - - - """ - "" + return self._list(method="POST", limit=limit, resource_cls=Simulator, list_cls=SimulatorList) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index cd459d9b2..9571e182a 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -1,23 +1,16 @@ from __future__ import annotations -from abc import ABC from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, NoReturn, Sequence +from typing import TYPE_CHECKING, Any, Sequence from typing_extensions import Self -from cognite.client.utils.useful_types import SequenceNotStr from cognite.client.data_classes._base import ( CogniteObject, - CognitePrimitiveUpdate, CogniteResource, CogniteResourceList, - CogniteUpdate, - ExternalIDTransformerMixin, - PropertySpec, - WriteableCogniteResource, - WriteableCogniteResourceList, ) +from cognite.client.utils.useful_types import SequenceNotStr if TYPE_CHECKING: from cognite.client import CogniteClient @@ -27,7 +20,7 @@ class SimulatorUnitEntry(CogniteObject): label: str name: str - + @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: return cls( @@ -40,52 +33,47 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = class SimulatorStepOption(CogniteObject): label: str value: str - + @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: return cls( label=resource["label"], value=resource["value"], ) - - @dataclass class SimulatorModelType(CogniteObject): name: str key: str - + @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: return cls( name=resource["name"], key=resource["key"], ) - - @dataclass class SimulatorQuantity(CogniteObject): name: str label: str - units: SimulatorUnitEntry | Sequence[SimulatorUnitEntry] - + units: Sequence[SimulatorUnitEntry] + @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: return cls( name=resource["name"], label=resource["label"], - units=SimulatorUnitEntry._load(resource["units"], cognite_client), + units=[SimulatorUnitEntry._load(unit_, cognite_client) for unit_ in resource["units"]], ) - + def dump(self, camel_case: bool = True) -> dict[str, Any]: output = super().dump(camel_case=camel_case) - output["units"] = self.units.dump(camel_case=camel_case) - - return output + output["units"] = [unit_.dump(camel_case=camel_case) for unit_ in self.units] + return output @dataclass @@ -93,111 +81,47 @@ class SimulatorStepField(CogniteObject): name: str label: str info: str - options: SimulatorStepOption | Sequence[SimulatorStepOption] | None - + options: Sequence[SimulatorStepOption] | None = None + @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: return cls( name=resource["name"], label=resource["label"], info=resource["info"], - options=SimulatorStepOption._load(resource["options"], cognite_client) if "options" in resource else None, + options=[SimulatorStepOption._load(option_, cognite_client) for option_ in resource["options"]] + if "options" in resource + else None, ) - + def dump(self, camel_case: bool = True) -> dict[str, Any]: output = super().dump(camel_case=camel_case) - if isinstance(self.options, SimulatorStepOption): - output["options"] = self.options.dump(camel_case=camel_case) - - return output + if self.options is not None: + output["options"] = [option_.dump(camel_case=camel_case) for option_ in self.options] + return output @dataclass class SimulatorStep(CogniteObject): step_type: str - fields: SimulatorStepField | Sequence[SimulatorStepField] - + fields: Sequence[SimulatorStepField] + @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: return cls( step_type=resource["stepType"], - fields=SimulatorStepField._load(resource["fields"], cognite_client), + fields=[SimulatorStepField._load(field_, cognite_client) for field_ in resource["fields"]], ) - - def dump(self, camel_case: bool = True) -> dict[str, Any]: - output = super().dump(camel_case=camel_case) - output["fields"] = self.fields.dump(camel_case=camel_case) - - return output - -class _SimulatorCore(WriteableCogniteResource["SimulatorWrite"], ABC): - def __init__(self, external_id: str, name: str, file_extension_types: str | SequenceNotStr[str], model_types: SimulatorModelType | Sequence[SimulatorModelType], step_fields: SimulatorStep | Sequence[SimulatorStep], unit_quantities: SimulatorQuantity | Sequence[SimulatorQuantity] | None = None) -> None: - self.external_id = external_id - self.name = name - self.file_extension_types = file_extension_types - self.model_types = model_types - self.step_fields = step_fields - self.unit_quantities = unit_quantities - - -class SimulatorWrite(_SimulatorCore): - """The simulator resource contains the definitions necessary for Cognite Data Fusion (CDF) to interact with a given simulator. - - It serves as a central contract that allows APIs, UIs, and integrations (connectors) to utilize the same definitions - when dealing with a specific simulator. Each simulator is uniquely identified and can be associated with various - file extension types, model types, step fields, and unit quantities. Simulators are essential for managing data - flows between CDF and external simulation tools, ensuring consistency and reliability in data handling. #### - Limitations: - A project can have a maximum of 100 simulators - - This is the write/request format of the simulator. - - Args: - external_id (str): External id of the simulator - name (str): Name of the simulator - file_extension_types (str | SequenceNotStr[str]): File extension types supported by the simulator - model_types (SimulatorModelType | Sequence[SimulatorModelType]): Model types supported by the simulator - step_fields (SimulatorStep | Sequence[SimulatorStep]): Step types supported by the simulator when creating routines - unit_quantities (SimulatorQuantity | Sequence[SimulatorQuantity] | None): Quantities and their units supported by the simulator - - """ - - def __init__(self, external_id: str, name: str, file_extension_types: str | SequenceNotStr[str], model_types: SimulatorModelType | Sequence[SimulatorModelType], step_fields: SimulatorStep | Sequence[SimulatorStep], unit_quantities: SimulatorQuantity | Sequence[SimulatorQuantity] | None = None) -> None: - super().__init__( - external_id=external_id, - name=name, - file_extension_types=file_extension_types, - model_types=model_types, - step_fields=step_fields, - unit_quantities=unit_quantities, - ) - - @classmethod - def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - return cls( - external_id=resource["externalId"], - name=resource["name"], - file_extension_types=resource["fileExtensionTypes"], - model_types=SimulatorModelType._load(resource["modelTypes"], cognite_client), - step_fields=SimulatorStep._load(resource["stepFields"], cognite_client), - unit_quantities=SimulatorQuantity._load(resource["unitQuantities"], cognite_client) if "unitQuantities" in resource else None, - ) - def dump(self, camel_case: bool = True) -> dict[str, Any]: output = super().dump(camel_case=camel_case) - output["modelTypes" if camel_case else "model_types"] = self.model_types.dump(camel_case=camel_case) - output["stepFields" if camel_case else "step_fields"] = self.step_fields.dump(camel_case=camel_case) - if isinstance(self.unit_quantities, SimulatorQuantity): - output["unitQuantities" if camel_case else "unit_quantities"] = self.unit_quantities.dump(camel_case=camel_case) - - return output - def as_write(self) -> SimulatorWrite: - return self + output["fields"] = [field_.dump(camel_case=camel_case) for field_ in self.fields] + return output -class Simulator(_SimulatorCore): +class Simulator(CogniteResource): """The simulator resource contains the definitions necessary for Cognite Data Fusion (CDF) to interact with a given simulator. It serves as a central contract that allows APIs, UIs, and integrations (connectors) to utilize the same definitions @@ -213,23 +137,32 @@ class Simulator(_SimulatorCore): external_id (str): External id of the simulator name (str): Name of the simulator file_extension_types (str | SequenceNotStr[str]): File extension types supported by the simulator + created_time (int): None + last_updated_time (int): None model_types (SimulatorModelType | Sequence[SimulatorModelType] | None): Model types supported by the simulator step_fields (SimulatorStep | Sequence[SimulatorStep] | None): Step types supported by the simulator when creating routines unit_quantities (SimulatorQuantity | Sequence[SimulatorQuantity] | None): Quantities and their units supported by the simulator - created_time (int): None - last_updated_time (int): None """ - def __init__(self, id: int, external_id: str, name: str, file_extension_types: str | SequenceNotStr[str], created_time: int, last_updated_time: int, model_types: SimulatorModelType | Sequence[SimulatorModelType] | None = None, step_fields: SimulatorStep | Sequence[SimulatorStep] | None = None, unit_quantities: SimulatorQuantity | Sequence[SimulatorQuantity] | None = None) -> None: - super().__init__( - external_id=external_id, - name=name, - file_extension_types=file_extension_types, - model_types=model_types, - step_fields=step_fields, - unit_quantities=unit_quantities, - ) + def __init__( + self, + id: int, + external_id: str, + name: str, + file_extension_types: str | SequenceNotStr[str], + created_time: int, + last_updated_time: int, + model_types: SimulatorModelType | Sequence[SimulatorModelType] | None = None, + step_fields: SimulatorStep | Sequence[SimulatorStep] | None = None, + unit_quantities: SimulatorQuantity | Sequence[SimulatorQuantity] | None = None, + ) -> None: + self.external_id = external_id + self.name = name + self.file_extension_types = file_extension_types + self.model_types = model_types + self.step_fields = step_fields + self.unit_quantities = unit_quantities self.id = id self.created_time = created_time self.last_updated_time = last_updated_time @@ -243,10 +176,16 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = file_extension_types=resource["fileExtensionTypes"], created_time=resource["createdTime"], last_updated_time=resource["lastUpdatedTime"], - model_types=SimulatorModelType._load(resource["modelTypes"], cognite_client) if "modelTypes" in resource else None, - step_fields=SimulatorStep._load(resource["stepFields"], cognite_client) if "stepFields" in resource else None, - unit_quantities=SimulatorQuantity._load(resource["unitQuantities"], cognite_client) if "unitQuantities" in resource else None, - ) + model_types=SimulatorModelType._load(resource["modelTypes"], cognite_client) + if "modelTypes" in resource + else None, + step_fields=SimulatorStep._load(resource["stepFields"], cognite_client) + if "stepFields" in resource + else None, + unit_quantities=SimulatorQuantity._load(resource["unitQuantities"], cognite_client) + if "unitQuantities" in resource + else None, + ) def dump(self, camel_case: bool = True) -> dict[str, Any]: output = super().dump(camel_case=camel_case) @@ -255,88 +194,12 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: if isinstance(self.step_fields, SimulatorStep): output["stepFields" if camel_case else "step_fields"] = self.step_fields.dump(camel_case=camel_case) if isinstance(self.unit_quantities, SimulatorQuantity): - output["unitQuantities" if camel_case else "unit_quantities"] = self.unit_quantities.dump(camel_case=camel_case) - - return output - + output["unitQuantities" if camel_case else "unit_quantities"] = self.unit_quantities.dump( + camel_case=camel_case + ) - def as_write(self) -> SimulatorWrite: - return SimulatorWrite( - unit_quantities=self.unit_quantities, - name=self.name, - model_types=self.model_types, - external_id=self.external_id, - step_fields=self.step_fields, - file_extension_types=self.file_extension_types, - ) - - -class SimulatorUpdate(CogniteUpdate): - def __init__(self, id: int) -> None: - super().__init__( - id = id, - ) - - class _UpdateSetAnnotatedStringConstraintsUpdate(CognitePrimitiveUpdate): - def set(self, value: UpdateSetAnnotatedStringConstraints | None) -> SimulatorUpdate: - return self._set(value.dump() if isinstance(value, UpdateSetAnnotatedStringConstraints) else value) - - class _UpdateSetListUpdate(CognitePrimitiveUpdate): - def set(self, value: UpdateSetList | None) -> SimulatorUpdate: - return self._set(value.dump() if isinstance(value, UpdateSetList) else value) - - class _UpdateSetListSimulatorModelTypeUpdate(CognitePrimitiveUpdate): - def set(self, value: UpdateSetListSimulatorModelType | None) -> SimulatorUpdate: - return self._set(value.dump() if isinstance(value, UpdateSetListSimulatorModelType) else value) - - class _UpdateSetListSimulatorStepUpdate(CognitePrimitiveUpdate): - def set(self, value: UpdateSetListSimulatorStep | None) -> SimulatorUpdate: - return self._set(value.dump() if isinstance(value, UpdateSetListSimulatorStep) else value) - - class _UpdateSetList1kSimulatorQuantityUpdate(CognitePrimitiveUpdate): - def set(self, value: UpdateSetList1kSimulatorQuantity | None) -> SimulatorUpdate: - return self._set(value.dump() if isinstance(value, UpdateSetList1kSimulatorQuantity) else value) - - - @property - def name(self) -> SimulatorUpdate._UpdateSetAnnotatedStringConstraintsUpdate: - return self._UpdateSetAnnotatedStringConstraintsUpdate(self, "name") - - @property - def file_extension_types(self) -> SimulatorUpdate._UpdateSetListUpdate: - return self._UpdateSetListUpdate(self, "file_extension_types") - - @property - def model_types(self) -> SimulatorUpdate._UpdateSetListSimulatorModelTypeUpdate: - return self._UpdateSetListSimulatorModelTypeUpdate(self, "model_types") - - @property - def step_fields(self) -> SimulatorUpdate._UpdateSetListSimulatorStepUpdate: - return self._UpdateSetListSimulatorStepUpdate(self, "step_fields") - - @property - def unit_quantities(self) -> SimulatorUpdate._UpdateSetList1kSimulatorQuantityUpdate: - return self._UpdateSetList1kSimulatorQuantityUpdate(self, "unit_quantities") - - - @classmethod - def _get_update_properties(cls, item: CogniteResource | None = None) -> list[PropertySpec]: - return [ - PropertySpec("name", is_nullable=True), - PropertySpec("file_extension_types", is_nullable=True), - PropertySpec("model_types", is_nullable=True), - PropertySpec("step_fields", is_nullable=True), - PropertySpec("unit_quantities", is_nullable=True), - ] - - -class SimulatorWriteList(CogniteResourceList[SimulatorWrite]): - _RESOURCE = SimulatorWrite + return output -class SimulatorList(WriteableCogniteResourceList[SimulatorWrite, Simulator]): +class SimulatorList(CogniteResourceList[Simulator]): _RESOURCE = Simulator - - def as_write(self) -> SimulatorWriteList: - return SimulatorWriteList([item.as_write() for item in self.data]) - From 2852e9f913b7fa67b52c1351b7a0c680607974aa Mon Sep 17 00:00:00 2001 From: anders-albert Date: Sun, 6 Oct 2024 08:05:10 +0200 Subject: [PATCH 004/122] refactor: setup shell --- cognite/client/_api/simulators/__init__.py | 3 +++ cognite/client/_cognite_client.py | 2 ++ cognite/client/testing.py | 3 +++ .../test_api/test_simulators/__init__.py | 0 .../test_api/test_simulators/test_simulators.py | 8 ++++++++ 5 files changed, 16 insertions(+) create mode 100644 cognite/client/_api/simulators/__init__.py create mode 100644 tests/tests_integration/test_api/test_simulators/__init__.py create mode 100644 tests/tests_integration/test_api/test_simulators/test_simulators.py diff --git a/cognite/client/_api/simulators/__init__.py b/cognite/client/_api/simulators/__init__.py new file mode 100644 index 000000000..5f0738825 --- /dev/null +++ b/cognite/client/_api/simulators/__init__.py @@ -0,0 +1,3 @@ +from .simulators import SimulatorsAPI + +__all__ = ["SimulatorsAPI"] diff --git a/cognite/client/_cognite_client.py b/cognite/client/_cognite_client.py index 12d83162f..df7d6b411 100644 --- a/cognite/client/_cognite_client.py +++ b/cognite/client/_cognite_client.py @@ -22,6 +22,7 @@ from cognite.client._api.raw import RawAPI from cognite.client._api.relationships import RelationshipsAPI from cognite.client._api.sequences import SequencesAPI +from cognite.client._api.simulators import SimulatorsAPI from cognite.client._api.templates import TemplatesAPI from cognite.client._api.three_d import ThreeDAPI from cognite.client._api.time_series import TimeSeriesAPI @@ -81,6 +82,7 @@ def __init__(self, config: ClientConfig | None = None) -> None: self.documents = DocumentsAPI(self._config, self._API_VERSION, self) self.workflows = WorkflowAPI(self._config, self._API_VERSION, self) self.units = UnitAPI(self._config, self._API_VERSION, self) + self.simulators = SimulatorsAPI(self._config, self._API_VERSION, self) # APIs just using base_url: self._api_client = APIClient(self._config, api_version=None, cognite_client=self) diff --git a/cognite/client/testing.py b/cognite/client/testing.py index 0cb8b382c..49147ff8b 100644 --- a/cognite/client/testing.py +++ b/cognite/client/testing.py @@ -39,6 +39,7 @@ from cognite.client._api.raw import RawAPI, RawDatabasesAPI, RawRowsAPI, RawTablesAPI from cognite.client._api.relationships import RelationshipsAPI from cognite.client._api.sequences import SequencesAPI, SequencesDataAPI +from cognite.client._api.simulators import SimulatorsAPI from cognite.client._api.synthetic_time_series import SyntheticDatapointsAPI from cognite.client._api.templates import ( TemplateGroupsAPI, @@ -138,6 +139,8 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.relationships = MagicMock(spec_set=RelationshipsAPI) + self.simulators = MagicMock(spec=SimulatorsAPI) + self.sequences = MagicMock(spec=SequencesAPI) self.sequences.data = MagicMock(spec_set=SequencesDataAPI) diff --git a/tests/tests_integration/test_api/test_simulators/__init__.py b/tests/tests_integration/test_api/test_simulators/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py new file mode 100644 index 000000000..415239aa3 --- /dev/null +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -0,0 +1,8 @@ +from cognite.client import CogniteClient + + +class TestSimulators: + def test_list(self, cognite_client: CogniteClient) -> None: + simulators = cognite_client.simulators.list(limit=5) + + assert len(simulators) > 0 From 4fb77282eda92d61d375ec5f84b51a277bfdd440 Mon Sep 17 00:00:00 2001 From: anders-albert Date: Sun, 6 Oct 2024 08:07:28 +0200 Subject: [PATCH 005/122] fix: added forgotten --- cognite/client/_api/simulators/simulators.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulators.py b/cognite/client/_api/simulators/simulators.py index 5499482e0..691ebcc0e 100644 --- a/cognite/client/_api/simulators/simulators.py +++ b/cognite/client/_api/simulators/simulators.py @@ -39,4 +39,6 @@ def list(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorList: """ self._warning.warn() - return self._list(method="POST", limit=limit, resource_cls=Simulator, list_cls=SimulatorList) + return self._list( + method="POST", limit=limit, resource_cls=Simulator, list_cls=SimulatorList, headers={"cdf-version": "beta"} + ) From 8a967997efa8e054530d575102848cd4386f12c8 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Fri, 1 Nov 2024 18:48:29 +0100 Subject: [PATCH 006/122] add support for integrations and models listing --- cognite/client/_api/simulators/__init__.py | 17 ++- .../_api/simulators/simulator_integrations.py | 52 +++++++ .../_api/simulators/simulator_models.py | 52 +++++++ cognite/client/_api/simulators/simulators.py | 7 +- cognite/client/data_classes/_base.py | 26 ++++ .../data_classes/simulators/simulators.py | 144 +++++++++++++++++- .../test_simulators/test_simulators.py | 16 +- 7 files changed, 305 insertions(+), 9 deletions(-) create mode 100644 cognite/client/_api/simulators/simulator_integrations.py create mode 100644 cognite/client/_api/simulators/simulator_models.py diff --git a/cognite/client/_api/simulators/__init__.py b/cognite/client/_api/simulators/__init__.py index 5f0738825..97fc50740 100644 --- a/cognite/client/_api/simulators/__init__.py +++ b/cognite/client/_api/simulators/__init__.py @@ -1,3 +1,16 @@ -from .simulators import SimulatorsAPI +from __future__ import annotations -__all__ = ["SimulatorsAPI"] +from typing import TYPE_CHECKING + +from cognite.client._api.simulators.simulator_integrations import SimulatorIntegrationsAPI +from cognite.client._api.simulators.simulator_models import SimulatorModelsAPI +from cognite.client._api.simulators.simulators import SimulatorsResourceAPI + +if TYPE_CHECKING: + from cognite.client import CogniteClient + from cognite.client.config import ClientConfig + + +class SimulatorsAPI(SimulatorsResourceAPI, SimulatorIntegrationsAPI, SimulatorModelsAPI): + def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: + super().__init__(config, api_version, cognite_client) diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py new file mode 100644 index 000000000..5d5023836 --- /dev/null +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -0,0 +1,52 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from cognite.client._api_client import APIClient +from cognite.client._constants import DEFAULT_LIMIT_READ +from cognite.client.data_classes.simulators.simulators import ( + SimulatorIntegration, + SimulatorIntegrationList, +) +from cognite.client.utils._experimental import FeaturePreviewWarning + +if TYPE_CHECKING: + from cognite.client import ClientConfig, CogniteClient + + +class SimulatorIntegrationsAPI(APIClient): + _RESOURCE_PATH = "/simulators/integrations" + + def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: + super().__init__(config, api_version, cognite_client) + self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") + + def list_integrations(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorIntegrationList: + """`Filter Simulators `_ + + List simulators + + Args: + limit (int): The maximum number of simulators to return. Defaults to 25. Set to -1, float("inf") or None + + Returns: + SimulatorIntegrationList: List of simulators + + Examples: + + List simulators: + + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.list_integrations() + + """ + self._warning.warn() + return self._list( + method="POST", + limit=limit, + url_path="/simulators/integrations/list", + resource_cls=SimulatorIntegration, + list_cls=SimulatorIntegrationList, + headers={"cdf-version": "beta"}, + ) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py new file mode 100644 index 000000000..7d30358f8 --- /dev/null +++ b/cognite/client/_api/simulators/simulator_models.py @@ -0,0 +1,52 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from cognite.client._api_client import APIClient +from cognite.client._constants import DEFAULT_LIMIT_READ +from cognite.client.data_classes.simulators.simulators import ( + SimulatorModel, + SimulatorModelList, +) +from cognite.client.utils._experimental import FeaturePreviewWarning + +if TYPE_CHECKING: + from cognite.client import ClientConfig, CogniteClient + + +class SimulatorModelsAPI(APIClient): + _RESOURCE_PATH = "/simulators/models" + + def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: + super().__init__(config, api_version, cognite_client) + self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") + + def list_models(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorModelList: + """`Filter Simulators `_ + + List simulators + + Args: + limit (int): The maximum number of simulators to return. Defaults to 25. Set to -1, float("inf") or None + + Returns: + SimulatorModelList: List of simulator models + + Examples: + + List simulators: + + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.list_models() + + """ + self._warning.warn() + return self._list( + method="POST", + limit=limit, + url_path="/simulators/models/list", + resource_cls=SimulatorModel, + list_cls=SimulatorModelList, + headers={"cdf-version": "beta"}, + ) diff --git a/cognite/client/_api/simulators/simulators.py b/cognite/client/_api/simulators/simulators.py index 691ebcc0e..e32d4803c 100644 --- a/cognite/client/_api/simulators/simulators.py +++ b/cognite/client/_api/simulators/simulators.py @@ -4,14 +4,17 @@ from cognite.client._api_client import APIClient from cognite.client._constants import DEFAULT_LIMIT_READ -from cognite.client.data_classes.simulators.simulators import Simulator, SimulatorList +from cognite.client.data_classes.simulators.simulators import ( + Simulator, + SimulatorList, +) from cognite.client.utils._experimental import FeaturePreviewWarning if TYPE_CHECKING: from cognite.client import ClientConfig, CogniteClient -class SimulatorsAPI(APIClient): +class SimulatorsResourceAPI(APIClient): _RESOURCE_PATH = "/simulators" def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: diff --git a/cognite/client/data_classes/_base.py b/cognite/client/data_classes/_base.py index 0e2c7027e..95856f0a3 100644 --- a/cognite/client/data_classes/_base.py +++ b/cognite/client/data_classes/_base.py @@ -175,6 +175,32 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = """ return fast_dict_load(cls, resource, cognite_client=cognite_client) + @classmethod + def _load_list_or_dict( + cls, resource: dict[str, Any] | list[dict[str, Any]], cognite_client: CogniteClient | None = None + ) -> Self | list[Self]: + """ + This is the internal load method that is called by the public load method. + It has a default implementation that can be overridden by subclasses. + + The typical use case for overriding this method is to handle nested resources, + or to handle resources that have required fields as the default implementation assumes + all fields are optional. + + Note that the base class takes care of loading from YAML/JSON strings and error handling. + + Args: + resource (dict[str, Any] | list[dict[str, Any]]): The resource to load. + cognite_client (CogniteClient | None): Cognite client to associate with the resource. + + Returns: + Self | list[Self]: The loaded resource. + """ + if isinstance(resource, list): + return [fast_dict_load(cls, res, cognite_client=cognite_client) for res in resource] + + return fast_dict_load(cls, resource, cognite_client=cognite_client) + class UnknownCogniteObject(CogniteObject): def __init__(self, data: dict[str, Any]) -> None: diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 9571e182a..bd767676c 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -48,12 +48,21 @@ class SimulatorModelType(CogniteObject): key: str @classmethod - def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> SimulatorModelType: return cls( name=resource["name"], key=resource["key"], ) + @classmethod + def _load_list_or_dict( + cls, resource: dict[str, Any] | list[dict[str, Any]], cognite_client: CogniteClient | None = None + ) -> SimulatorModelType | list[SimulatorModelType]: + if isinstance(resource, list): + return [cls._load(res, cognite_client) for res in resource] + + return cls._load(resource, cognite_client) + @dataclass class SimulatorQuantity(CogniteObject): @@ -69,6 +78,15 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = units=[SimulatorUnitEntry._load(unit_, cognite_client) for unit_ in resource["units"]], ) + @classmethod + def _load_list_or_dict( + cls, resource: dict[str, Any] | list[dict[str, Any]], cognite_client: CogniteClient | None = None + ) -> SimulatorQuantity | list[SimulatorQuantity]: + if isinstance(resource, list): + return [cls._load(res, cognite_client) for res in resource] + + return cls._load(resource, cognite_client) + def dump(self, camel_case: bool = True) -> dict[str, Any]: output = super().dump(camel_case=camel_case) output["units"] = [unit_.dump(camel_case=camel_case) for unit_ in self.units] @@ -114,6 +132,15 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = fields=[SimulatorStepField._load(field_, cognite_client) for field_ in resource["fields"]], ) + @classmethod + def _load_list_or_dict( + cls, resource: dict[str, Any] | list[dict[str, Any]], cognite_client: CogniteClient | None = None + ) -> SimulatorStep | list[SimulatorStep]: + if isinstance(resource, list): + return [cls._load(res, cognite_client) for res in resource] + + return cls._load(resource, cognite_client) + def dump(self, camel_case: bool = True) -> dict[str, Any]: output = super().dump(camel_case=camel_case) output["fields"] = [field_.dump(camel_case=camel_case) for field_ in self.fields] @@ -176,13 +203,13 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = file_extension_types=resource["fileExtensionTypes"], created_time=resource["createdTime"], last_updated_time=resource["lastUpdatedTime"], - model_types=SimulatorModelType._load(resource["modelTypes"], cognite_client) + model_types=SimulatorModelType._load_list_or_dict(resource["modelTypes"], cognite_client) if "modelTypes" in resource else None, - step_fields=SimulatorStep._load(resource["stepFields"], cognite_client) + step_fields=SimulatorStep._load_list_or_dict(resource["stepFields"], cognite_client) if "stepFields" in resource else None, - unit_quantities=SimulatorQuantity._load(resource["unitQuantities"], cognite_client) + unit_quantities=SimulatorQuantity._load_list_or_dict(resource["unitQuantities"], cognite_client) if "unitQuantities" in resource else None, ) @@ -201,5 +228,114 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return output +class SimulatorIntegration(CogniteResource): + def __init__( + self, + id: int, + external_id: str, + simulator_external_id: str, + heartbeat: int, + active: bool, + data_set_id: int, + connector_version: str, + log_id: int, + created_time: int, + last_updated_time: int, + license_status: str | None = None, + simulator_version: str | None = None, + license_last_checked_time: int | None = None, + connector_status: str | None = None, + connector_status_updated_time: int | None = None, + ) -> None: + self.id = id + self.external_id = external_id + self.simulator_external_id = simulator_external_id + self.heartbeat = heartbeat + self.active = active + self.data_set_id = data_set_id + self.connector_version = connector_version + self.log_id = log_id + self.created_time = created_time + self.last_updated_time = last_updated_time + self.license_status = license_status + self.simulator_version = simulator_version + self.license_last_checked_time = license_last_checked_time + self.connector_status = connector_status + self.connector_status_updated_time = connector_status_updated_time + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + id=resource["id"], + external_id=resource["externalId"], + simulator_external_id=resource["simulatorExternalId"], + heartbeat=resource["heartbeat"], + active=resource["active"], + data_set_id=resource["dataSetId"], + connector_version=resource["connectorVersion"], + log_id=resource["logId"], + created_time=resource["createdTime"], + last_updated_time=resource["lastUpdatedTime"], + license_status=resource.get("licenseStatus"), + simulator_version=resource.get("simulatorVersion"), + license_last_checked_time=resource.get("licenseLastCheckedTime"), + connector_status=resource.get("connectorStatus"), + connector_status_updated_time=resource.get("connectorStatusUpdatedTime"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +class SimulatorModel(CogniteResource): + def __init__( + self, + id: int, + external_id: str, + simulator_external_id: str, + name: str, + data_set_id: int, + created_time: int, + last_updated_time: int, + type_key: str | None = None, + description: str | None = None, + ) -> None: + self.id = id + self.external_id = external_id + self.simulator_external_id = simulator_external_id + self.data_set_id = data_set_id + self.data_set_id = data_set_id + self.created_time = created_time + self.last_updated_time = last_updated_time + self.name = name + self.type_key = type_key + self.description = description + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + id=resource["id"], + external_id=resource["externalId"], + simulator_external_id=resource["simulatorExternalId"], + name=resource["name"], + data_set_id=resource["dataSetId"], + created_time=resource["createdTime"], + last_updated_time=resource["lastUpdatedTime"], + type_key=resource.get("typeKey"), + description=resource.get("description"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + class SimulatorList(CogniteResourceList[Simulator]): _RESOURCE = Simulator + + +class SimulatorIntegrationList(CogniteResourceList[SimulatorIntegration]): + _RESOURCE = SimulatorIntegration + + +class SimulatorModelList(CogniteResourceList[SimulatorModel]): + _RESOURCE = SimulatorModel diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 415239aa3..2819275ba 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -2,7 +2,21 @@ class TestSimulators: - def test_list(self, cognite_client: CogniteClient) -> None: + def test_list_simulators(self, cognite_client: CogniteClient) -> None: simulators = cognite_client.simulators.list(limit=5) assert len(simulators) > 0 + + +class TestSimulatorIntegrations: + def test_list_integrations(self, cognite_client: CogniteClient) -> None: + integrations = cognite_client.simulators.list_integrations(limit=5) + + assert len(integrations) > 0 + + +class TestSimulatorModels: + def test_list_models(self, cognite_client: CogniteClient) -> None: + models = cognite_client.simulators.list_models(limit=5) + + assert len(models) > 0 From f06199608b5d03749a76a87b833931bf35e4138a Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Fri, 1 Nov 2024 19:32:11 +0100 Subject: [PATCH 007/122] filtering for simulator integrations --- .../_api/simulators/simulator_integrations.py | 16 ++++++++++++++-- .../client/data_classes/simulators/simulators.py | 14 ++++++++++++++ .../test_api/test_simulators/test_simulators.py | 15 +++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index 5d5023836..3ce793401 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -1,11 +1,12 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any from cognite.client._api_client import APIClient from cognite.client._constants import DEFAULT_LIMIT_READ from cognite.client.data_classes.simulators.simulators import ( SimulatorIntegration, + SimulatorIntegrationFilter, SimulatorIntegrationList, ) from cognite.client.utils._experimental import FeaturePreviewWarning @@ -21,13 +22,18 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client super().__init__(config, api_version, cognite_client) self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") - def list_integrations(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorIntegrationList: + def list_integrations( + self, + limit: int = DEFAULT_LIMIT_READ, + filter: SimulatorIntegrationFilter | dict[str, Any] | None = None, + ) -> SimulatorIntegrationList: """`Filter Simulators `_ List simulators Args: limit (int): The maximum number of simulators to return. Defaults to 25. Set to -1, float("inf") or None + filter (SimulatorIntegrationFilter | dict[str, Any] | None): The filter to narrow down assets integrations. Returns: SimulatorIntegrationList: List of simulators @@ -41,6 +47,7 @@ def list_integrations(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorIntegra >>> res = client.simulators.list_integrations() """ + self._warning.warn() return self._list( method="POST", @@ -49,4 +56,9 @@ def list_integrations(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorIntegra resource_cls=SimulatorIntegration, list_cls=SimulatorIntegrationList, headers={"cdf-version": "beta"}, + filter=filter.dump() + if isinstance(filter, SimulatorIntegrationFilter) + else filter + if isinstance(filter, dict) + else None, # fix this ) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index bd767676c..3cfb6008e 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -6,6 +6,7 @@ from typing_extensions import Self from cognite.client.data_classes._base import ( + CogniteFilter, CogniteObject, CogniteResource, CogniteResourceList, @@ -287,6 +288,19 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) +class SimulatorIntegrationFilter(CogniteFilter): + def __init__( + self, + simulator_external_ids: Sequence[str] | None = None, + active: bool | None = None, + ) -> None: + self.simulator_external_ids = simulator_external_ids + self.active = active + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + class SimulatorModel(CogniteResource): def __init__( self, diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 2819275ba..b229d144d 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -1,4 +1,5 @@ from cognite.client import CogniteClient +from cognite.client.data_classes.simulators.simulators import SimulatorIntegrationFilter class TestSimulators: @@ -14,6 +15,20 @@ def test_list_integrations(self, cognite_client: CogniteClient) -> None: assert len(integrations) > 0 + def test_filter_integrations(self, cognite_client: CogniteClient) -> None: + all_integrations = cognite_client.simulators.list_integrations() + active_integrations = cognite_client.simulators.list_integrations( + filter=SimulatorIntegrationFilter(active=True) + ) + dwsim_integrations = cognite_client.simulators.list_integrations( + filter=SimulatorIntegrationFilter(simulator_external_ids=["DWSIM"]) + ) + + assert len(active_integrations) > 0 + assert len(all_integrations) != len(active_integrations) + assert len(dwsim_integrations) > 0 + assert len(all_integrations) != len(dwsim_integrations) + class TestSimulatorModels: def test_list_models(self, cognite_client: CogniteClient) -> None: From 2a67cb5c6a0e96b84863f52bbc62850c08f46d8a Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 5 Nov 2024 11:47:32 +0100 Subject: [PATCH 008/122] listing revisions --- cognite/client/_api/simulators/__init__.py | 3 +- .../_api/simulators/simulator_integrations.py | 4 +- .../_api/simulators/simulator_models.py | 60 ++++++- .../_api/simulators/simulator_routines.py | 52 ++++++ .../data_classes/simulators/simulators.py | 158 ++++++++++++++++++ .../test_simulators/test_simulators.py | 11 ++ 6 files changed, 280 insertions(+), 8 deletions(-) create mode 100644 cognite/client/_api/simulators/simulator_routines.py diff --git a/cognite/client/_api/simulators/__init__.py b/cognite/client/_api/simulators/__init__.py index 97fc50740..99292652d 100644 --- a/cognite/client/_api/simulators/__init__.py +++ b/cognite/client/_api/simulators/__init__.py @@ -4,6 +4,7 @@ from cognite.client._api.simulators.simulator_integrations import SimulatorIntegrationsAPI from cognite.client._api.simulators.simulator_models import SimulatorModelsAPI +from cognite.client._api.simulators.simulator_routines import SimulatorRoutinesAPI from cognite.client._api.simulators.simulators import SimulatorsResourceAPI if TYPE_CHECKING: @@ -11,6 +12,6 @@ from cognite.client.config import ClientConfig -class SimulatorsAPI(SimulatorsResourceAPI, SimulatorIntegrationsAPI, SimulatorModelsAPI): +class SimulatorsAPI(SimulatorsResourceAPI, SimulatorIntegrationsAPI, SimulatorModelsAPI, SimulatorRoutinesAPI): def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: super().__init__(config, api_version, cognite_client) diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index 3ce793401..ec820e0dc 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -32,8 +32,8 @@ def list_integrations( List simulators Args: - limit (int): The maximum number of simulators to return. Defaults to 25. Set to -1, float("inf") or None - filter (SimulatorIntegrationFilter | dict[str, Any] | None): The filter to narrow down assets integrations. + limit (int): The maximum number of simulators to return. Defaults to 100. + filter (SimulatorIntegrationFilter | dict[str, Any] | None): The filter to narrow down simulator integrations. Returns: SimulatorIntegrationList: List of simulators diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 7d30358f8..beaa53e4f 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -1,12 +1,16 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any from cognite.client._api_client import APIClient from cognite.client._constants import DEFAULT_LIMIT_READ from cognite.client.data_classes.simulators.simulators import ( SimulatorModel, SimulatorModelList, + SimulatorModelRevision, + SimulatorModelRevisionList, + SimulatorModelRevisionsFilter, + SimulatorModelsFilter, ) from cognite.client.utils._experimental import FeaturePreviewWarning @@ -21,13 +25,16 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client super().__init__(config, api_version, cognite_client) self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") - def list_models(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorModelList: - """`Filter Simulators `_ + def list_models( + self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelsFilter | dict[str, Any] | None = None + ) -> SimulatorModelList: + """`Filter Simulator Models `_ - List simulators + List all simulation models Args: - limit (int): The maximum number of simulators to return. Defaults to 25. Set to -1, float("inf") or None + limit (int): The maximum number of simulator models to return. Defaults to 100. + filter (SimulatorModelsFilter | dict[str, Any] | None): The filter to narrow down simulator models. Returns: SimulatorModelList: List of simulator models @@ -49,4 +56,47 @@ def list_models(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorModelList: resource_cls=SimulatorModel, list_cls=SimulatorModelList, headers={"cdf-version": "beta"}, + filter=filter.dump() + if isinstance(filter, SimulatorModelsFilter) + else filter + if isinstance(filter, dict) + else None, # fix this + ) + + def list_model_revisions( + self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelRevisionsFilter | dict[str, Any] | None = None + ) -> SimulatorModelRevisionList: + """`Filter simulator model revisions `_ + + List all simulation model revisions + + Args: + limit (int): The maximum number of model revisions to return. Defaults to 100. + filter (SimulatorModelRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator model revisions. + + Returns: + SimulatorModelRevisionList: List all simulation model revisions + + Examples: + + List simulators: + + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.list_model_revisions() + + """ + self._warning.warn() + return self._list( + method="POST", + limit=limit, + url_path="/simulators/models/revisions/list", + resource_cls=SimulatorModelRevision, + list_cls=SimulatorModelRevisionList, + headers={"cdf-version": "beta"}, + filter=filter.dump() + if isinstance(filter, SimulatorModelRevisionsFilter) + else filter + if isinstance(filter, dict) + else None, # fix this ) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py new file mode 100644 index 000000000..3f33a4fbe --- /dev/null +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -0,0 +1,52 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from cognite.client._api_client import APIClient +from cognite.client._constants import DEFAULT_LIMIT_READ +from cognite.client.data_classes.simulators.simulators import ( + SimulatorRoutine, + SimulatorRoutineList, +) +from cognite.client.utils._experimental import FeaturePreviewWarning + +if TYPE_CHECKING: + from cognite.client import ClientConfig, CogniteClient + + +class SimulatorRoutinesAPI(APIClient): + _RESOURCE_PATH = "/simulators/routines" + + def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: + super().__init__(config, api_version, cognite_client) + self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") + + def list_routines(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorRoutineList: + """`Filter Simulators `_ + + List simulators + + Args: + limit (int): The maximum number of simulators to return. Defaults to 25. Set to -1, float("inf") or None + + Returns: + SimulatorRoutineList: List of simulator routines + + Examples: + + List simulators: + + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.list_models() + + """ + self._warning.warn() + return self._list( + method="POST", + limit=limit, + url_path="/simulators/routines/list", + resource_cls=SimulatorRoutine, + list_cls=SimulatorRoutineList, + headers={"cdf-version": "beta"}, + ) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 3cfb6008e..4490b34e5 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -301,6 +301,112 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) +class SimulatorModelsFilter(CogniteFilter): + def __init__( + self, + simulator_external_ids: Sequence[str] | None = None, + ) -> None: + self.simulator_external_ids = simulator_external_ids + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +class SimulatorModelRevisionsFilter(CogniteFilter): + def __init__( + self, + model_external_ids: Sequence[str] | None = None, + all_versions: bool | None = None, + ) -> None: + self.model_external_ids = model_external_ids + self.all_versions = all_versions + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +class SimulatorModelRevision(CogniteResource): + def __init__( + self, + id: int, + external_id: str, + simulator_external_id: str, + model_external_id: str, + data_set_id: int, + file_id: int, + created_by_user_id: str, + status: str, + created_time: int, + last_updated_time: int, + version_number: int, + log_id: int, + description: str | None = None, + status_message: str | None = None, + ) -> None: + self.id = id + self.external_id = external_id + self.simulator_external_id = simulator_external_id + self.model_external_id = model_external_id + self.data_set_id = data_set_id + self.file_id = file_id + self.created_by_user_id = created_by_user_id + self.status = status + self.created_time = created_time + self.last_updated_time = last_updated_time + self.version_number = version_number + self.log_id = log_id + self.description = description + self.status_message = status_message + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + id=resource["id"], + external_id=resource["externalId"], + simulator_external_id=resource["simulatorExternalId"], + model_external_id=resource["modelExternalId"], + data_set_id=resource["dataSetId"], + file_id=resource["fileId"], + created_by_user_id=resource["createdByUserId"], + status=resource["status"], + created_time=resource["createdTime"], + last_updated_time=resource["lastUpdatedTime"], + version_number=resource["versionNumber"], + log_id=resource["logId"], + description=resource.get("description"), + status_message=resource.get("statusMessage"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +class SimulatorRoutineRevision(CogniteResource): + def __init__( + self, + id: int, + external_id: str, + simulator_external_id: str, + routine_external_id: str, + simulator_integration_external_id: str, + model_external_id: str, + data_set_id: int, + created_by_user_id: str, + version_number: int, + created_time: int, + ) -> None: + self.id = id + self.external_id = external_id + self.simulator_external_id = simulator_external_id + self.routine_external_id = routine_external_id + self.simulator_integration_external_id = simulator_integration_external_id + self.model_external_id = model_external_id + self.data_set_id = data_set_id + self.created_by_user_id = created_by_user_id + self.version_number = version_number + self.created_time = created_time + + class SimulatorModel(CogniteResource): def __init__( self, @@ -343,6 +449,54 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) +class SimulatorRoutine(CogniteResource): + def __init__( + self, + id: int, + external_id: str, + simulator_external_id: str, + model_external_id: str, + simulator_integration_external_id: str, + name: str, + data_set_id: int, + created_time: int, + last_updated_time: int, + description: str | None = None, + ) -> None: + self.id = id + self.external_id = external_id + self.simulator_external_id = simulator_external_id + self.model_external_id = model_external_id + self.simulator_integration_external_id = simulator_integration_external_id + self.name = name + self.data_set_id = data_set_id + self.created_time = created_time + self.last_updated_time = last_updated_time + self.description = description + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + id=resource["id"], + external_id=resource["externalId"], + simulator_external_id=resource["simulatorExternalId"], + model_external_id=resource["modelExternalId"], + simulator_integration_external_id=resource["simulatorIntegrationExternalId"], + name=resource["name"], + data_set_id=resource["dataSetId"], + created_time=resource["createdTime"], + last_updated_time=resource["lastUpdatedTime"], + description=resource.get("description"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +class SimulatorRoutineList(CogniteResourceList[SimulatorRoutine]): + _RESOURCE = SimulatorRoutine + + class SimulatorList(CogniteResourceList[Simulator]): _RESOURCE = Simulator @@ -353,3 +507,7 @@ class SimulatorIntegrationList(CogniteResourceList[SimulatorIntegration]): class SimulatorModelList(CogniteResourceList[SimulatorModel]): _RESOURCE = SimulatorModel + + +class SimulatorModelRevisionList(CogniteResourceList[SimulatorModelRevision]): + _RESOURCE = SimulatorModelRevision diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index b229d144d..7ff3dd925 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -35,3 +35,14 @@ def test_list_models(self, cognite_client: CogniteClient) -> None: models = cognite_client.simulators.list_models(limit=5) assert len(models) > 0 + + def test_list_model_revisions(self, cognite_client: CogniteClient) -> None: + revisions = cognite_client.simulators.list_model_revisions(limit=5) + + assert len(revisions) > 0 + + +class TestSimulatorRoutines: + def test_list_routines(self, cognite_client: CogniteClient) -> None: + routines = cognite_client.simulators.list_routines(limit=5) + assert len(routines) > 0 From 966f31da6c70ae20c0d66d274173eb7ff92295c7 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 5 Nov 2024 13:35:05 +0100 Subject: [PATCH 009/122] docstrings --- .../data_classes/simulators/simulators.py | 83 ++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 4490b34e5..ddcbcbd85 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -230,6 +230,33 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: class SimulatorIntegration(CogniteResource): + """ + The simulator integration resource represents a simulator connector in Cognite Data Fusion (CDF). It provides information about the configured connectors for a given simulator, including their status and additional details such as dataset, name, license status, connector version, simulator version, and more. This resource is essential for monitoring and managing the interactions between CDF and external simulators, ensuring proper data flow and integration. + + Limitations: - A project can have a maximum of 100 simulators + + This is the read/response format of the simulator integration. + + Args: + + id (int): A unique id of a simulator integration + external_id (str): External id of the simulator integration + simulator_external_id (str): External id of the associated simulator + heartbeat (int): The interval in seconds between the last heartbeat and the current time + active (bool): Whether the simulator integration is active + data_set_id (int): The id of the dataset associated with the simulator integration + connector_version (str): The version of the connector + log_id (int): The id of the log associated with the simulator integration + created_time (int): The time when the simulator integration was created + last_updated_time (int): The time when the simulator integration was last updated + license_status (str | None): The status of the license + simulator_version (str | None): The version of the simulator + license_last_checked_time (int | None): The time when the license was last checked + connector_status (str | None): The status of the connector + connector_status_updated_time (int | None): The time when the connector status was last updated + + """ + def __init__( self, id: int, @@ -408,15 +435,39 @@ def __init__( class SimulatorModel(CogniteResource): + """ + The simulator model resource represents an asset modeled in a simulator. This asset could range from a pump or well to a complete processing facility or refinery. The simulator model is the root of its associated revisions, routines, runs, and results. The dataset assigned to a model is inherited by its children. Deleting a model also deletes all its children, thereby maintaining the integrity and hierarchy of the simulation data. + + Simulator model revisions track changes and updates to a simulator model over time. Each revision ensures that modifications to models are traceable and allows users to understand the evolution of a given model. + + Limitations: + - A project can have a maximum of 1000 simulator models + - Each simulator model can have a maximum of 200 revisions + + + This is the read/response format of a simulator model. + + Args: + id (int): A unique id of a simulator model + external_id (str): External id of the simulator model + simulator_external_id (str): External id of the associated simulator + data_set_id (int): The id of the dataset associated with the simulator model + created_time (int): The time when the simulator model was created + last_updated_time (int): The time when the simulator model was last updated + name (str): The name of the simulator model + type_key (str | None): The type key of the simulator model + description (str | None): The description of the simulator model + """ + def __init__( self, id: int, external_id: str, simulator_external_id: str, - name: str, data_set_id: int, created_time: int, last_updated_time: int, + name: str, type_key: str | None = None, description: str | None = None, ) -> None: @@ -424,7 +475,6 @@ def __init__( self.external_id = external_id self.simulator_external_id = simulator_external_id self.data_set_id = data_set_id - self.data_set_id = data_set_id self.created_time = created_time self.last_updated_time = last_updated_time self.name = name @@ -450,6 +500,35 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: class SimulatorRoutine(CogniteResource): + """ + The simulator routine resource defines instructions on interacting with a simulator model. A simulator routine includes: + + * Inputs (values set into the simulator model) + * Commands (actions to be performed by the simulator) + * Outputs (values read from the simulator model) + + Simulator routines can have multiple revisions, enabling users to track changes and evolve the routine over time. Each model can have multiple routines, each performing different objectives such as calculating optimal operation setpoints, forecasting production, benchmarking asset performance, and more. + + Limitations: + - Each simulator model can have a maximum of 10 simulator routines + + Each simulator routine can have a maximum of 10 revisions + + This is the read/response format of a simulator routine. + + Args: + id (int): A unique id of a simulator routine + external_id (str): External id of the simulator routine + simulator_external_id (str): External id of the associated simulator + model_external_id (str): External id of the associated simulator model + simulator_integration_external_id (str): External id of the associated simulator integration + name (str): The name of the simulator routine + data_set_id (int): The id of the dataset associated with the simulator routine + created_time (int): The time when the simulator routine was created + last_updated_time (int): The time when the simulator routine was last updated + description (str | None): The description of the simulator routine + """ + def __init__( self, id: int, From 947c0c2355095eab34b7cc5849e0b5b2760d5ee6 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 5 Nov 2024 15:53:38 +0100 Subject: [PATCH 010/122] routine revisions --- .../_api/simulators/simulator_routines.py | 32 ++ .../data_classes/simulators/simulators.py | 313 +++++++++++++++++- .../test_simulators/test_simulators.py | 6 + 3 files changed, 347 insertions(+), 4 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 3f33a4fbe..f5fb6d7cb 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -7,6 +7,8 @@ from cognite.client.data_classes.simulators.simulators import ( SimulatorRoutine, SimulatorRoutineList, + SimulatorRoutineRevision, + SimulatorRoutineRevisionsList, ) from cognite.client.utils._experimental import FeaturePreviewWarning @@ -50,3 +52,33 @@ def list_routines(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorRoutineList list_cls=SimulatorRoutineList, headers={"cdf-version": "beta"}, ) + + def list_routine_revisions(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorRoutineRevisionsList: + """`Filter Simulators `_ + + List simulators + + Args: + limit (int): The maximum number of simulators to return. Defaults to 25. Set to -1, float("inf") or None + + Returns: + SimulatorRoutineRevisionsList: List of simulator routines + + Examples: + + List simulators: + + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.list_models() + + """ + self._warning.warn() + return self._list( + method="POST", + limit=limit, + url_path="/simulators/routines/revisions/list", + resource_cls=SimulatorRoutineRevision, + list_cls=SimulatorRoutineRevisionsList, + headers={"cdf-version": "beta"}, + ) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index ddcbcbd85..fdd1e88e8 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -17,6 +17,269 @@ from cognite.client import CogniteClient +@dataclass +class SimulationValueUnitInput(CogniteObject): + name: str + quantity: str | None = None + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + name=resource["name"], + quantity=resource.get("quantity"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +@dataclass +class SimulatorRoutineInputTimeseries(CogniteObject): + name: str + reference_id: str + source_external_id: str + aggregate: str | None = None + save_timeseries_external_id: str | None = None + unit: SimulationValueUnitInput | None = None + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + name=resource["name"], + reference_id=resource["referenceId"], + source_external_id=resource["sourceExternalId"], + aggregate=resource.get("aggregate"), + save_timeseries_external_id=resource.get("saveTimeseriesExternalId"), + unit=SimulationValueUnitInput._load(resource["unit"], cognite_client) if "unit" in resource else None, + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + output = super().dump(camel_case=camel_case) + if self.unit is not None: + output["unit"] = self.unit.dump(camel_case=camel_case) + + return output + + +@dataclass +class SimulatorRoutineInputConstant(CogniteObject): + name: str + reference_id: str + value: str + value_type: str + unit: SimulationValueUnitInput | None = None + save_timeseries_external_id: str | None = None + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + name=resource["name"], + reference_id=resource["referenceId"], + value=resource["value"], + value_type=resource["valueType"], + unit=SimulationValueUnitInput._load(resource["unit"], cognite_client) if "unit" in resource else None, + save_timeseries_external_id=resource.get("saveTimeseriesExternalId"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + output = super().dump(camel_case=camel_case) + if self.unit is not None: + output["unit"] = self.unit.dump(camel_case=camel_case) + + return output + + +@dataclass +class SimulatorRoutineOutput(CogniteObject): + name: str + reference_id: str + value_type: str + unit: SimulationValueUnitInput | None = None + save_timeseries_external_id: str | None = None + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + name=resource["name"], + reference_id=resource["referenceId"], + value_type=resource["valueType"], + unit=SimulationValueUnitInput._load(resource["unit"], cognite_client) if "unit" in resource else None, + save_timeseries_external_id=resource.get("saveTimeseriesExternalId"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + output = super().dump(camel_case=camel_case) + if self.unit is not None: + output["unit"] = self.unit.dump(camel_case=camel_case) + + return output + + +@dataclass +class SimulatorRoutineSchedule(CogniteObject): + enabled: bool + cron_expression: str | None = None + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + enabled=resource["enabled"], + cron_expression=resource.get("cronExpression"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +@dataclass +class SimulatorRoutineDataSampling(CogniteObject): + enabled: bool + validation_window: int | None = None + sampling_window: int | None = None + granularity: str | None = None + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + enabled=resource["enabled"], + validation_window=resource.get("validationWindow"), + sampling_window=resource.get("samplingWindow"), + granularity=resource.get("granularity"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +@dataclass +class SimulatorRoutineLogicalCheckEnabled(CogniteObject): + enabled: bool + timeseries_external_id: str | None = None + aggregate: str | None = None + operator: str | None = None + value: float | None = None + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + enabled=resource["enabled"], + timeseries_external_id=resource.get("timeseriesExternalId"), + aggregate=resource.get("aggregate"), + operator=resource.get("operator"), + value=resource.get("value"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +@dataclass +class SimulatorRoutineSteadyStateDetectionEnabled(CogniteObject): + enabled: bool + timeseries_external_id: str | None = None + aggregate: str | None = None + min_section_size: int | None = None + var_threshold: float | None = None + slope_threshold: float | None = None + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + enabled=resource["enabled"], + timeseries_external_id=resource.get("timeseriesExternalId"), + aggregate=resource.get("aggregate"), + min_section_size=resource.get("minSectionSize"), + var_threshold=resource.get("varThreshold"), + slope_threshold=resource.get("slopeThreshold"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +@dataclass +class SimulatorRoutineConfiguration(CogniteObject): + schedule: SimulatorRoutineSchedule + data_sampling: SimulatorRoutineDataSampling + logical_check: list[SimulatorRoutineLogicalCheckEnabled] + steady_state_detection: list[SimulatorRoutineSteadyStateDetectionEnabled] + inputs: list[SimulatorRoutineInputConstant | SimulatorRoutineInputTimeseries] + outputs: list[SimulatorRoutineOutput] + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + schedule=SimulatorRoutineSchedule._load(resource["schedule"], cognite_client), + data_sampling=SimulatorRoutineDataSampling._load(resource["dataSampling"], cognite_client), + logical_check=[ + SimulatorRoutineLogicalCheckEnabled._load(check_, cognite_client) for check_ in resource["logicalCheck"] + ], + steady_state_detection=[ + SimulatorRoutineSteadyStateDetectionEnabled._load(detection_, cognite_client) + for detection_ in resource["steadyStateDetection"] + ], + inputs=[ + SimulatorRoutineInputConstant._load(input_, cognite_client) + if "value" in input_ + else SimulatorRoutineInputTimeseries._load(input_, cognite_client) + for input_ in resource["inputs"] + ], + outputs=[SimulatorRoutineOutput._load(output_, cognite_client) for output_ in resource["outputs"]], + ) + + +@dataclass +class SimulatorRoutineStepArguments(CogniteObject): + reference_id: str | None = None + object_name: str | None = None + object_property: str | None = None + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + reference_id=resource.get("referenceId"), + object_name=resource.get("objectName"), + object_property=resource.get("objectProperty"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +@dataclass +class SimulatorRoutineStep(CogniteObject): + step_type: str + arguments: dict[str, Any] + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + step_type=resource["stepType"], + arguments=resource["arguments"], + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +@dataclass +class SimulatorRoutineStage(CogniteObject): + order: int + steps: list[SimulatorRoutineStep] + description: str | None + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + order=resource["order"], + steps=[SimulatorRoutineStep._load(step_, cognite_client) for step_ in resource["steps"]], + description=resource.get("description"), + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + @dataclass class SimulatorUnitEntry(CogniteObject): label: str @@ -231,7 +494,10 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: class SimulatorIntegration(CogniteResource): """ - The simulator integration resource represents a simulator connector in Cognite Data Fusion (CDF). It provides information about the configured connectors for a given simulator, including their status and additional details such as dataset, name, license status, connector version, simulator version, and more. This resource is essential for monitoring and managing the interactions between CDF and external simulators, ensuring proper data flow and integration. + The simulator integration resource represents a simulator connector in Cognite Data Fusion (CDF). + It provides information about the configured connectors for a given simulator, including their status and additional + details such as dataset, name, license status, connector version, simulator version, and more. This resource is essential + for monitoring and managing the interactions between CDF and external simulators, ensuring proper data flow and integration. Limitations: - A project can have a maximum of 100 simulators @@ -421,6 +687,8 @@ def __init__( created_by_user_id: str, version_number: int, created_time: int, + configuration: SimulatorRoutineConfiguration, + script: list[SimulatorRoutineStage], ) -> None: self.id = id self.external_id = external_id @@ -432,13 +700,44 @@ def __init__( self.created_by_user_id = created_by_user_id self.version_number = version_number self.created_time = created_time + self.configuration = configuration + self.script = script + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + id=resource["id"], + external_id=resource["externalId"], + simulator_external_id=resource["simulatorExternalId"], + routine_external_id=resource["routineExternalId"], + simulator_integration_external_id=resource["simulatorIntegrationExternalId"], + model_external_id=resource["modelExternalId"], + data_set_id=resource["dataSetId"], + created_by_user_id=resource["createdByUserId"], + version_number=resource["versionNumber"], + created_time=resource["createdTime"], + configuration=SimulatorRoutineConfiguration._load(resource["configuration"], cognite_client), + script=[SimulatorRoutineStage._load(stage_, cognite_client) for stage_ in resource["script"]], + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + output = super().dump(camel_case=camel_case) + output["configuration"] = self.configuration.dump(camel_case=camel_case) + output["script"] = [stage_.dump(camel_case=camel_case) for stage_ in self.script] + + return output class SimulatorModel(CogniteResource): """ - The simulator model resource represents an asset modeled in a simulator. This asset could range from a pump or well to a complete processing facility or refinery. The simulator model is the root of its associated revisions, routines, runs, and results. The dataset assigned to a model is inherited by its children. Deleting a model also deletes all its children, thereby maintaining the integrity and hierarchy of the simulation data. + The simulator model resource represents an asset modeled in a simulator. + This asset could range from a pump or well to a complete processing facility or refinery. + The simulator model is the root of its associated revisions, routines, runs, and results. + The dataset assigned to a model is inherited by its children. Deleting a model also deletes all its children, thereby + maintaining the integrity and hierarchy of the simulation data. - Simulator model revisions track changes and updates to a simulator model over time. Each revision ensures that modifications to models are traceable and allows users to understand the evolution of a given model. + Simulator model revisions track changes and updates to a simulator model over time. + Each revision ensures that modifications to models are traceable and allows users to understand the evolution of a given model. Limitations: - A project can have a maximum of 1000 simulator models @@ -507,7 +806,9 @@ class SimulatorRoutine(CogniteResource): * Commands (actions to be performed by the simulator) * Outputs (values read from the simulator model) - Simulator routines can have multiple revisions, enabling users to track changes and evolve the routine over time. Each model can have multiple routines, each performing different objectives such as calculating optimal operation setpoints, forecasting production, benchmarking asset performance, and more. + Simulator routines can have multiple revisions, enabling users to track changes and evolve the routine over time. + Each model can have multiple routines, each performing different objectives such as calculating optimal + operation setpoints, forecasting production, benchmarking asset performance, and more. Limitations: - Each simulator model can have a maximum of 10 simulator routines @@ -576,6 +877,10 @@ class SimulatorRoutineList(CogniteResourceList[SimulatorRoutine]): _RESOURCE = SimulatorRoutine +class SimulatorRoutineRevisionsList(CogniteResourceList[SimulatorRoutineRevision]): + _RESOURCE = SimulatorRoutineRevision + + class SimulatorList(CogniteResourceList[Simulator]): _RESOURCE = Simulator diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 7ff3dd925..eb461b2c0 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -46,3 +46,9 @@ class TestSimulatorRoutines: def test_list_routines(self, cognite_client: CogniteClient) -> None: routines = cognite_client.simulators.list_routines(limit=5) assert len(routines) > 0 + + def test_list_routine_revisions(self, cognite_client: CogniteClient) -> None: + revisions = cognite_client.simulators.list_routine_revisions(limit=5) + assert revisions[0].configuration is not None + assert revisions[0].script is not None + assert len(revisions) > 0 From f25b46dea5586990e045f3fb66a09e0195cc89cc Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 5 Nov 2024 16:03:04 +0100 Subject: [PATCH 011/122] move filters to its own file --- .../_api/simulators/simulator_integrations.py | 2 +- .../_api/simulators/simulator_models.py | 3 +- .../data_classes/simulators/__init__.py | 0 .../client/data_classes/simulators/filters.py | 42 +++++++++++++++++++ .../data_classes/simulators/simulators.py | 38 ----------------- .../test_simulators/test_simulators.py | 2 +- 6 files changed, 45 insertions(+), 42 deletions(-) create mode 100644 cognite/client/data_classes/simulators/__init__.py create mode 100644 cognite/client/data_classes/simulators/filters.py diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index ec820e0dc..8e5d43799 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -4,9 +4,9 @@ from cognite.client._api_client import APIClient from cognite.client._constants import DEFAULT_LIMIT_READ +from cognite.client.data_classes.simulators.filters import SimulatorIntegrationFilter from cognite.client.data_classes.simulators.simulators import ( SimulatorIntegration, - SimulatorIntegrationFilter, SimulatorIntegrationList, ) from cognite.client.utils._experimental import FeaturePreviewWarning diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index beaa53e4f..a3a49c095 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -4,13 +4,12 @@ from cognite.client._api_client import APIClient from cognite.client._constants import DEFAULT_LIMIT_READ +from cognite.client.data_classes.simulators.filters import SimulatorModelRevisionsFilter, SimulatorModelsFilter from cognite.client.data_classes.simulators.simulators import ( SimulatorModel, SimulatorModelList, SimulatorModelRevision, SimulatorModelRevisionList, - SimulatorModelRevisionsFilter, - SimulatorModelsFilter, ) from cognite.client.utils._experimental import FeaturePreviewWarning diff --git a/cognite/client/data_classes/simulators/__init__.py b/cognite/client/data_classes/simulators/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cognite/client/data_classes/simulators/filters.py b/cognite/client/data_classes/simulators/filters.py new file mode 100644 index 000000000..fd238f1a9 --- /dev/null +++ b/cognite/client/data_classes/simulators/filters.py @@ -0,0 +1,42 @@ +from __future__ import annotations + +from typing import Any, Sequence + +from cognite.client.data_classes._base import CogniteFilter + + +class SimulatorIntegrationFilter(CogniteFilter): + def __init__( + self, + simulator_external_ids: Sequence[str] | None = None, + active: bool | None = None, + ) -> None: + self.simulator_external_ids = simulator_external_ids + self.active = active + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +class SimulatorModelsFilter(CogniteFilter): + def __init__( + self, + simulator_external_ids: Sequence[str] | None = None, + ) -> None: + self.simulator_external_ids = simulator_external_ids + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +class SimulatorModelRevisionsFilter(CogniteFilter): + def __init__( + self, + model_external_ids: Sequence[str] | None = None, + all_versions: bool | None = None, + ) -> None: + self.model_external_ids = model_external_ids + self.all_versions = all_versions + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index fdd1e88e8..7db1ab75c 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -6,7 +6,6 @@ from typing_extensions import Self from cognite.client.data_classes._base import ( - CogniteFilter, CogniteObject, CogniteResource, CogniteResourceList, @@ -581,43 +580,6 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) -class SimulatorIntegrationFilter(CogniteFilter): - def __init__( - self, - simulator_external_ids: Sequence[str] | None = None, - active: bool | None = None, - ) -> None: - self.simulator_external_ids = simulator_external_ids - self.active = active - - def dump(self, camel_case: bool = True) -> dict[str, Any]: - return super().dump(camel_case=camel_case) - - -class SimulatorModelsFilter(CogniteFilter): - def __init__( - self, - simulator_external_ids: Sequence[str] | None = None, - ) -> None: - self.simulator_external_ids = simulator_external_ids - - def dump(self, camel_case: bool = True) -> dict[str, Any]: - return super().dump(camel_case=camel_case) - - -class SimulatorModelRevisionsFilter(CogniteFilter): - def __init__( - self, - model_external_ids: Sequence[str] | None = None, - all_versions: bool | None = None, - ) -> None: - self.model_external_ids = model_external_ids - self.all_versions = all_versions - - def dump(self, camel_case: bool = True) -> dict[str, Any]: - return super().dump(camel_case=camel_case) - - class SimulatorModelRevision(CogniteResource): def __init__( self, diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index eb461b2c0..335fd8038 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -1,5 +1,5 @@ from cognite.client import CogniteClient -from cognite.client.data_classes.simulators.simulators import SimulatorIntegrationFilter +from cognite.client.data_classes.simulators.filters import SimulatorIntegrationFilter class TestSimulators: From 741c6a063e562781b9f4238b9973f3de2dcc54a3 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Wed, 6 Nov 2024 12:51:24 +0100 Subject: [PATCH 012/122] filters --- .../_api/simulators/simulator_routines.py | 25 ++++++++++++--- cognite/client/data_classes/assets.py | 2 +- .../client/data_classes/simulators/filters.py | 32 +++++++++++++++++++ 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index f5fb6d7cb..290c66f8b 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -1,9 +1,10 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any from cognite.client._api_client import APIClient from cognite.client._constants import DEFAULT_LIMIT_READ +from cognite.client.data_classes.simulators.filters import SimulatorRoutineRevisionsFilter, SimulatorRoutinesFilter from cognite.client.data_classes.simulators.simulators import ( SimulatorRoutine, SimulatorRoutineList, @@ -23,13 +24,16 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client super().__init__(config, api_version, cognite_client) self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") - def list_routines(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorRoutineList: + def list_routines( + self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutinesFilter | dict[str, Any] | None = None + ) -> SimulatorRoutineList: """`Filter Simulators `_ List simulators Args: - limit (int): The maximum number of simulators to return. Defaults to 25. Set to -1, float("inf") or None + limit (int): The maximum number of simulators to return. Defaults to 100. + filter (SimulatorRoutinesFilter | dict[str, Any] | None): The filter to narrow down simulator routines. Returns: SimulatorRoutineList: List of simulator routines @@ -51,15 +55,23 @@ def list_routines(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorRoutineList resource_cls=SimulatorRoutine, list_cls=SimulatorRoutineList, headers={"cdf-version": "beta"}, + filter=filter.dump() + if isinstance(filter, SimulatorRoutinesFilter) + else filter + if isinstance(filter, dict) + else None, # fix this ) - def list_routine_revisions(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorRoutineRevisionsList: + def list_routine_revisions( + self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutineRevisionsFilter | dict[str, Any] | None = None + ) -> SimulatorRoutineRevisionsList: """`Filter Simulators `_ List simulators Args: limit (int): The maximum number of simulators to return. Defaults to 25. Set to -1, float("inf") or None + filter (SimulatorRoutineRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator routine revisions. Returns: SimulatorRoutineRevisionsList: List of simulator routines @@ -81,4 +93,9 @@ def list_routine_revisions(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorRo resource_cls=SimulatorRoutineRevision, list_cls=SimulatorRoutineRevisionsList, headers={"cdf-version": "beta"}, + filter=filter.dump() + if isinstance(filter, SimulatorRoutineRevisionsFilter) + else filter + if isinstance(filter, dict) + else None, # fix this ) diff --git a/cognite/client/data_classes/assets.py b/cognite/client/data_classes/assets.py index beb3b3a9a..146fa8399 100644 --- a/cognite/client/data_classes/assets.py +++ b/cognite/client/data_classes/assets.py @@ -890,7 +890,7 @@ def _count_subtree(xid: str, count: int = 0) -> int: counts.sort(key=lambda args: -args[-1]) # The count for the fictitious "root of roots" is just len(assets), so we remove it: (count_dct := dict(counts)).pop(None, None) - return count_dct # type: ignore[return-value] + return count_dct def _on_error(self, on_error: Literal["ignore", "warn", "raise"], message: str) -> None: if on_error == "warn": diff --git a/cognite/client/data_classes/simulators/filters.py b/cognite/client/data_classes/simulators/filters.py index fd238f1a9..6ec06c9ec 100644 --- a/cognite/client/data_classes/simulators/filters.py +++ b/cognite/client/data_classes/simulators/filters.py @@ -40,3 +40,35 @@ def __init__( def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) + + +class SimulatorRoutinesFilter(CogniteFilter): + def __init__( + self, + model_external_ids: Sequence[str] | None = None, + simulator_integration_external_ids: Sequence[str] | None = None, + ) -> None: + self.model_external_ids = model_external_ids + self.simulator_integration_external_ids = simulator_integration_external_ids + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +class SimulatorRoutineRevisionsFilter(CogniteFilter): + def __init__( + self, + routine_external_ids: Sequence[str] | None = None, + all_versions: bool | None = None, + model_external_ids: Sequence[str] | None = None, + simulator_integration_external_ids: Sequence[str] | None = None, + simulator_external_ids: Sequence[str] | None = None, + ) -> None: + self.model_external_ids = model_external_ids + self.all_versions = all_versions + self.routine_external_ids = routine_external_ids + self.simulator_integration_external_ids = simulator_integration_external_ids + self.simulator_external_ids = simulator_external_ids + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) From 346078184e8bed9d8ee15a285a73ac6ccd893a5d Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Thu, 7 Nov 2024 00:15:26 +0100 Subject: [PATCH 013/122] retrieve byids --- cognite/client/_api/simulators/__init__.py | 5 +- .../client/_api/simulators/simulation_runs.py | 58 ++++++++++ .../_api/simulators/simulator_models.py | 63 ++++++++++ .../_api/simulators/simulator_routines.py | 37 +++++- .../client/data_classes/simulators/filters.py | 16 ++- .../data_classes/simulators/simulators.py | 109 +++++++++++++++++- .../test_simulators/test_simulators.py | 26 ++++- 7 files changed, 307 insertions(+), 7 deletions(-) create mode 100644 cognite/client/_api/simulators/simulation_runs.py diff --git a/cognite/client/_api/simulators/__init__.py b/cognite/client/_api/simulators/__init__.py index 99292652d..0baf77e81 100644 --- a/cognite/client/_api/simulators/__init__.py +++ b/cognite/client/_api/simulators/__init__.py @@ -2,6 +2,7 @@ from typing import TYPE_CHECKING +from cognite.client._api.simulators.simulation_runs import SimulatorRunsAPI from cognite.client._api.simulators.simulator_integrations import SimulatorIntegrationsAPI from cognite.client._api.simulators.simulator_models import SimulatorModelsAPI from cognite.client._api.simulators.simulator_routines import SimulatorRoutinesAPI @@ -12,6 +13,8 @@ from cognite.client.config import ClientConfig -class SimulatorsAPI(SimulatorsResourceAPI, SimulatorIntegrationsAPI, SimulatorModelsAPI, SimulatorRoutinesAPI): +class SimulatorsAPI( + SimulatorsResourceAPI, SimulatorIntegrationsAPI, SimulatorModelsAPI, SimulatorRoutinesAPI, SimulatorRunsAPI +): def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: super().__init__(config, api_version, cognite_client) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py new file mode 100644 index 000000000..cb566c360 --- /dev/null +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -0,0 +1,58 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any + +from cognite.client._api_client import APIClient +from cognite.client._constants import DEFAULT_LIMIT_READ +from cognite.client.data_classes.simulators.filters import SimulationRunsFilter +from cognite.client.data_classes.simulators.simulators import SimulationRun, SimulationRunsList +from cognite.client.utils._experimental import FeaturePreviewWarning + +if TYPE_CHECKING: + from cognite.client import ClientConfig, CogniteClient + + +class SimulatorRunsAPI(APIClient): + _RESOURCE_PATH = "/simulators/runs" + + def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: + super().__init__(config, api_version, cognite_client) + self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") + + def list_runs( + self, limit: int = DEFAULT_LIMIT_READ, filter: SimulationRunsFilter | dict[str, Any] | None = None + ) -> SimulationRunsList: + """`Filter simulation runs `_ + + List all simulation runs + + Args: + limit (int): The maximum number of simulation runs to return. Defaults to 100. + filter (SimulationRunsFilter | dict[str, Any] | None): The filter to narrow down simulator models. + + Returns: + SimulationRunsList: List of simulator models + + Examples: + + List simulators: + + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.list_runs() + + """ + self._warning.warn() + return self._list( + method="POST", + limit=limit, + url_path="/simulators/runs/list", + resource_cls=SimulationRun, + list_cls=SimulationRunsList, + headers={"cdf-version": "beta"}, + filter=filter.dump() + if isinstance(filter, SimulationRunsFilter) + else filter + if isinstance(filter, dict) + else None, # fix this + ) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index a3a49c095..e1233b4e5 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -12,6 +12,7 @@ SimulatorModelRevisionList, ) from cognite.client.utils._experimental import FeaturePreviewWarning +from cognite.client.utils._identifier import IdentifierSequence if TYPE_CHECKING: from cognite.client import ClientConfig, CogniteClient @@ -62,6 +63,36 @@ def list_models( else None, # fix this ) + def retrieve_model(self, id: int | None = None, external_id: str | None = None) -> SimulatorModel | None: + """`Retrieve Simulator Model `_ + + Get a simulator model by id/externalId + + Args: + id (int | None): The id of the simulator model. + external_id (str | None): The external id of the simulator model. + + Returns: + SimulatorModel | None: Requested simulator model + + Examples: + + List simulators: + + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.retrieve_model() + + """ + identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() + return self._retrieve_multiple( + list_cls=SimulatorModelList, + resource_cls=SimulatorModel, + identifiers=identifiers, + resource_path="/simulators/models", + headers={"cdf-version": "beta"}, + ) + def list_model_revisions( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelRevisionsFilter | dict[str, Any] | None = None ) -> SimulatorModelRevisionList: @@ -99,3 +130,35 @@ def list_model_revisions( if isinstance(filter, dict) else None, # fix this ) + + def retrieve_model_revision( + self, id: int | None = None, external_id: str | None = None + ) -> SimulatorModelRevision | None: + """`Retrieve Simulator Model Revisions `_ + + Retrieve simulator model revisions by IDs or external IDs + + Args: + id (int | None): The id of the simulator model revision. + external_id (str | None): The external id of the simulator model revision. + + Returns: + SimulatorModelRevision | None: Requested simulator model revision + + Examples: + + List simulators: + + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.retrieve_model_revision() + + """ + identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() + return self._retrieve_multiple( + list_cls=SimulatorModelRevisionList, + resource_cls=SimulatorModelRevision, + identifiers=identifiers, + resource_path="/simulators/models/revisions", + headers={"cdf-version": "beta"}, + ) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 290c66f8b..53fe45aaf 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -12,6 +12,7 @@ SimulatorRoutineRevisionsList, ) from cognite.client.utils._experimental import FeaturePreviewWarning +from cognite.client.utils._identifier import IdentifierSequence if TYPE_CHECKING: from cognite.client import ClientConfig, CogniteClient @@ -44,7 +45,7 @@ def list_routines( >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.list_models() + >>> res = client.simulators.list_routines() """ self._warning.warn() @@ -82,7 +83,7 @@ def list_routine_revisions( >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.list_models() + >>> res = client.simulators.list_routine_revisions() """ self._warning.warn() @@ -99,3 +100,35 @@ def list_routine_revisions( if isinstance(filter, dict) else None, # fix this ) + + def retrieve_routine_revision( + self, id: int | None = None, external_id: str | None = None + ) -> SimulatorRoutineRevision | None: + """`Retrieve Simulator Routine Revisions `_ + + Retrieve Simulator Routine Revisions + + Args: + id (int | None): The id of the simulator routine revision. + external_id (str | None): The external id of the simulator routine revision. + + Returns: + SimulatorRoutineRevision | None: Requested simulator routine revision + + Examples: + + List simulators: + + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.retrieve_routine_revision() + + """ + identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() + return self._retrieve_multiple( + resource_cls=SimulatorRoutineRevision, + list_cls=SimulatorRoutineRevisionsList, + identifiers=identifiers, + resource_path="/simulators/routines/revisions", + headers={"cdf-version": "beta"}, + ) diff --git a/cognite/client/data_classes/simulators/filters.py b/cognite/client/data_classes/simulators/filters.py index 6ec06c9ec..d5961acd9 100644 --- a/cognite/client/data_classes/simulators/filters.py +++ b/cognite/client/data_classes/simulators/filters.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import Any, Sequence +from collections.abc import Sequence +from typing import Any from cognite.client.data_classes._base import CogniteFilter @@ -72,3 +73,16 @@ def __init__( def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) + + +class SimulationRunsFilter(CogniteFilter): + def __init__( + self, + model_external_ids: Sequence[str] | None = None, + all_versions: bool | None = None, + ) -> None: + self.model_external_ids = model_external_ids + self.all_versions = all_versions + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 7db1ab75c..82258e937 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -1,7 +1,8 @@ from __future__ import annotations +from collections.abc import Sequence from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Sequence +from typing import TYPE_CHECKING, Any from typing_extensions import Self @@ -760,6 +761,108 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) +class SimulationRun(CogniteResource): + """ + Every time a simulation routine executes, a simulation run object is created. + This object ensures that each execution of a routine is documented and traceable. + Each run has an associated simulation data resource, which stores the inputs and outputs of a + simulation run, capturing the values set into and read from the simulator model to ensure + the traceability and integrity of the simulation data. + + Simulation runs provide a historical record of the simulations performed, allowing users to analyze + and compare different runs, track changes over time, and make informed decisions based on the simulation results. + + Limitations: + * A retention policy is in place for simulation runs, allowing up to 100000 entries. + * Once this limit is reached, the oldest runs will be deleted to accommodate new runs. + + This is the read/response format of a simulation run. + + Args: + id (int): A unique id of a simulation run + simulator_external_id (str): External id of the associated simulator + simulator_integration_external_id (str): External id of the associated simulator integration + model_external_id (str): External id of the associated simulator model + model_revision_external_id (str): External id of the associated simulator model revision + routine_external_id (str): External id of the associated simulator routine + routine_revision_external_id (str): External id of the associated simulator routine revision + run_time (int | None): Run time in milliseconds. Reference timestamp used for data pre-processing and data sampling. + simulation_time (int | None): Simulation time in milliseconds. Timestamp when the input data was sampled. Used for indexing input and output time series. + status (str): The status of the simulation run + status_message (str | None): The status message of the simulation run + data_set_id (int): The id of the dataset associated with the simulation run + run_type (str): The type of the simulation run + user_id (str): The id of the user who executed the simulation run + log_id (int): The id of the log associated with the simulation run + created_time (int): The number of milliseconds since epoch + last_updated_time (int): The number of milliseconds since epoch + + """ + + def __init__( + self, + id: int, + simulator_external_id: str, + simulator_integration_external_id: str, + model_external_id: str, + model_revision_external_id: str, + routine_external_id: str, + routine_revision_external_id: str, + run_time: int | None, + simulation_time: int | None, + status: str, + status_message: str | None, + data_set_id: int, + run_type: str, + user_id: str, + log_id: int, + created_time: int, + last_updated_time: int, + ) -> None: + self.id = id + self.simulator_external_id = simulator_external_id + self.simulator_integration_external_id = simulator_integration_external_id + self.model_external_id = model_external_id + self.model_revision_external_id = model_revision_external_id + self.routine_external_id = routine_external_id + self.routine_revision_external_id = routine_revision_external_id + self.run_time = run_time + self.simulation_time = simulation_time + self.status = status + self.status_message = status_message + self.data_set_id = data_set_id + self.run_type = run_type + self.user_id = user_id + self.log_id = log_id + self.created_time = created_time + self.last_updated_time = last_updated_time + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + return cls( + id=resource["id"], + simulator_external_id=resource["simulatorExternalId"], + simulator_integration_external_id=resource["simulatorIntegrationExternalId"], + model_external_id=resource["modelExternalId"], + model_revision_external_id=resource["modelRevisionExternalId"], + routine_external_id=resource["routineExternalId"], + routine_revision_external_id=resource["routineRevisionExternalId"], + run_time=resource.get("runTime"), + simulation_time=resource.get("simulationTime"), + status=resource["status"], + status_message=resource.get("statusMessage"), + data_set_id=resource["dataSetId"], + run_type=resource["runType"], + user_id=resource["userId"], + log_id=resource["logId"], + created_time=resource["createdTime"], + last_updated_time=resource["lastUpdatedTime"], + ) + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + class SimulatorRoutine(CogniteResource): """ The simulator routine resource defines instructions on interacting with a simulator model. A simulator routine includes: @@ -857,3 +960,7 @@ class SimulatorModelList(CogniteResourceList[SimulatorModel]): class SimulatorModelRevisionList(CogniteResourceList[SimulatorModelRevision]): _RESOURCE = SimulatorModelRevision + + +class SimulationRunsList(CogniteResourceList[SimulationRun]): + _RESOURCE = SimulationRun diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 335fd8038..48ff2edcd 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -10,6 +10,9 @@ def test_list_simulators(self, cognite_client: CogniteClient) -> None: class TestSimulatorIntegrations: + # test list + # test filter + # test retrieve def test_list_integrations(self, cognite_client: CogniteClient) -> None: integrations = cognite_client.simulators.list_integrations(limit=5) @@ -33,14 +36,22 @@ def test_filter_integrations(self, cognite_client: CogniteClient) -> None: class TestSimulatorModels: def test_list_models(self, cognite_client: CogniteClient) -> None: models = cognite_client.simulators.list_models(limit=5) - assert len(models) > 0 + def test_retrieve_model(self, cognite_client: CogniteClient) -> None: + model = cognite_client.simulators.retrieve_model(external_id="TEST_WORKFLOWS_SIMINT_INTEGRATION_MODEL") + assert model is not None + assert model.external_id == "TEST_WORKFLOWS_SIMINT_INTEGRATION_MODEL" + def test_list_model_revisions(self, cognite_client: CogniteClient) -> None: revisions = cognite_client.simulators.list_model_revisions(limit=5) - assert len(revisions) > 0 + def test_retrieve_model_revision(self, cognite_client: CogniteClient) -> None: + model = cognite_client.simulators.retrieve_model_revision(external_id="Shower_mixer-1") + assert model is not None + assert model.external_id == "Shower_mixer-1" + class TestSimulatorRoutines: def test_list_routines(self, cognite_client: CogniteClient) -> None: @@ -52,3 +63,14 @@ def test_list_routine_revisions(self, cognite_client: CogniteClient) -> None: assert revisions[0].configuration is not None assert revisions[0].script is not None assert len(revisions) > 0 + + def test_retrieve_routine_revision(self, cognite_client: CogniteClient) -> None: + revision = cognite_client.simulators.retrieve_routine_revision(external_id="ShowerMixerForTests-1") + assert revision is not None + assert revision.external_id == "ShowerMixerForTests-1" + + +class TestSimulationRuns: + def test_list_runs(self, cognite_client: CogniteClient) -> None: + routines = cognite_client.simulators.list_runs(limit=5) + assert len(routines) > 0 From 7d5e13c0e60379ef93ded77efcbd769a013d2976 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Thu, 7 Nov 2024 00:15:26 +0100 Subject: [PATCH 014/122] retrieve byids --- cognite/client/_api/simulators/__init__.py | 3 + .../client/_api/simulators/simulation_runs.py | 4 +- .../_api/simulators/simulator_integrations.py | 2 +- .../_api/simulators/simulator_models.py | 14 +- .../_api/simulators/simulator_routines.py | 10 +- cognite/client/_api/simulators/simulators.py | 13 +- cognite/client/_cognite_client.py | 2 +- cognite/client/data_classes/_base.py | 26 - .../data_classes/simulators/simulators.py | 41 +- cognite/client/testing.py | 2 +- .../test_simulators/seed/ShowerMixer.dwxmz | Bin 0 -> 15807 bytes .../test_api/test_simulators/seed/data.py | 740 ++++++++++++++++++ .../test_simulators/test_simulators.py | 82 +- 13 files changed, 867 insertions(+), 72 deletions(-) create mode 100644 tests/tests_integration/test_api/test_simulators/seed/ShowerMixer.dwxmz create mode 100644 tests/tests_integration/test_api/test_simulators/seed/data.py diff --git a/cognite/client/_api/simulators/__init__.py b/cognite/client/_api/simulators/__init__.py index 0baf77e81..02c835809 100644 --- a/cognite/client/_api/simulators/__init__.py +++ b/cognite/client/_api/simulators/__init__.py @@ -1,3 +1,4 @@ +<<<<<<< HEAD from __future__ import annotations from typing import TYPE_CHECKING @@ -18,3 +19,5 @@ class SimulatorsAPI( ): def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: super().__init__(config, api_version, cognite_client) +======= +>>>>>>> a7c607cf (retrieve byids) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py index cb566c360..df6b0e0cd 100644 --- a/cognite/client/_api/simulators/simulation_runs.py +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -19,7 +19,7 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client super().__init__(config, api_version, cognite_client) self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") - def list_runs( + def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulationRunsFilter | dict[str, Any] | None = None ) -> SimulationRunsList: """`Filter simulation runs `_ @@ -39,7 +39,7 @@ def list_runs( >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.list_runs() + >>> res = client.simulators.list() """ self._warning.warn() diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index 8e5d43799..e329791d4 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -22,7 +22,7 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client super().__init__(config, api_version, cognite_client) self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") - def list_integrations( + def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorIntegrationFilter | dict[str, Any] | None = None, diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index e1233b4e5..7d14adb3f 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -25,7 +25,7 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client super().__init__(config, api_version, cognite_client) self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") - def list_models( + def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelsFilter | dict[str, Any] | None = None ) -> SimulatorModelList: """`Filter Simulator Models `_ @@ -63,7 +63,7 @@ def list_models( else None, # fix this ) - def retrieve_model(self, id: int | None = None, external_id: str | None = None) -> SimulatorModel | None: + def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModel | None: """`Retrieve Simulator Model `_ Get a simulator model by id/externalId @@ -93,7 +93,7 @@ def retrieve_model(self, id: int | None = None, external_id: str | None = None) headers={"cdf-version": "beta"}, ) - def list_model_revisions( + def list_revisions( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelRevisionsFilter | dict[str, Any] | None = None ) -> SimulatorModelRevisionList: """`Filter simulator model revisions `_ @@ -113,7 +113,7 @@ def list_model_revisions( >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.list_model_revisions() + >>> res = client.simulators.list_revisions() """ self._warning.warn() @@ -131,9 +131,7 @@ def list_model_revisions( else None, # fix this ) - def retrieve_model_revision( - self, id: int | None = None, external_id: str | None = None - ) -> SimulatorModelRevision | None: + def retrieve_revision(self, id: int | None = None, external_id: str | None = None) -> SimulatorModelRevision | None: """`Retrieve Simulator Model Revisions `_ Retrieve simulator model revisions by IDs or external IDs @@ -151,7 +149,7 @@ def retrieve_model_revision( >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.retrieve_model_revision() + >>> res = client.simulators.retrieve_revision() """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 53fe45aaf..148a21853 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -25,7 +25,7 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client super().__init__(config, api_version, cognite_client) self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") - def list_routines( + def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutinesFilter | dict[str, Any] | None = None ) -> SimulatorRoutineList: """`Filter Simulators `_ @@ -63,7 +63,7 @@ def list_routines( else None, # fix this ) - def list_routine_revisions( + def list_revisions( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutineRevisionsFilter | dict[str, Any] | None = None ) -> SimulatorRoutineRevisionsList: """`Filter Simulators `_ @@ -83,7 +83,7 @@ def list_routine_revisions( >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.list_routine_revisions() + >>> res = client.simulators.list_revisions() """ self._warning.warn() @@ -101,7 +101,7 @@ def list_routine_revisions( else None, # fix this ) - def retrieve_routine_revision( + def retrieve_revision( self, id: int | None = None, external_id: str | None = None ) -> SimulatorRoutineRevision | None: """`Retrieve Simulator Routine Revisions `_ @@ -121,7 +121,7 @@ def retrieve_routine_revision( >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.retrieve_routine_revision() + >>> res = client.simulators.retrieve_revision() """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() diff --git a/cognite/client/_api/simulators/simulators.py b/cognite/client/_api/simulators/simulators.py index e32d4803c..3b77a57d0 100644 --- a/cognite/client/_api/simulators/simulators.py +++ b/cognite/client/_api/simulators/simulators.py @@ -2,6 +2,10 @@ from typing import TYPE_CHECKING +from cognite.client._api.simulators.simulation_runs import SimulatorRunsAPI +from cognite.client._api.simulators.simulator_integrations import SimulatorIntegrationsAPI +from cognite.client._api.simulators.simulator_models import SimulatorModelsAPI +from cognite.client._api.simulators.simulator_routines import SimulatorRoutinesAPI from cognite.client._api_client import APIClient from cognite.client._constants import DEFAULT_LIMIT_READ from cognite.client.data_classes.simulators.simulators import ( @@ -11,14 +15,19 @@ from cognite.client.utils._experimental import FeaturePreviewWarning if TYPE_CHECKING: - from cognite.client import ClientConfig, CogniteClient + from cognite.client import CogniteClient + from cognite.client.config import ClientConfig -class SimulatorsResourceAPI(APIClient): +class SimulatorsAPI(APIClient): _RESOURCE_PATH = "/simulators" def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: super().__init__(config, api_version, cognite_client) + self.models = SimulatorModelsAPI(config, api_version, cognite_client) + self.runs = SimulatorRunsAPI(config, api_version, cognite_client) + self.integrations = SimulatorIntegrationsAPI(config, api_version, cognite_client) + self.routines = SimulatorRoutinesAPI(config, api_version, cognite_client) self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") def list(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorList: diff --git a/cognite/client/_cognite_client.py b/cognite/client/_cognite_client.py index 4b283c5a1..634963e9d 100644 --- a/cognite/client/_cognite_client.py +++ b/cognite/client/_cognite_client.py @@ -23,7 +23,7 @@ from cognite.client._api.raw import RawAPI from cognite.client._api.relationships import RelationshipsAPI from cognite.client._api.sequences import SequencesAPI -from cognite.client._api.simulators import SimulatorsAPI +from cognite.client._api.simulators.simulators import SimulatorsAPI from cognite.client._api.templates import TemplatesAPI from cognite.client._api.three_d import ThreeDAPI from cognite.client._api.time_series import TimeSeriesAPI diff --git a/cognite/client/data_classes/_base.py b/cognite/client/data_classes/_base.py index 98617065f..5fe525ea1 100644 --- a/cognite/client/data_classes/_base.py +++ b/cognite/client/data_classes/_base.py @@ -171,32 +171,6 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = """ return fast_dict_load(cls, resource, cognite_client=cognite_client) - @classmethod - def _load_list_or_dict( - cls, resource: dict[str, Any] | list[dict[str, Any]], cognite_client: CogniteClient | None = None - ) -> Self | list[Self]: - """ - This is the internal load method that is called by the public load method. - It has a default implementation that can be overridden by subclasses. - - The typical use case for overriding this method is to handle nested resources, - or to handle resources that have required fields as the default implementation assumes - all fields are optional. - - Note that the base class takes care of loading from YAML/JSON strings and error handling. - - Args: - resource (dict[str, Any] | list[dict[str, Any]]): The resource to load. - cognite_client (CogniteClient | None): Cognite client to associate with the resource. - - Returns: - Self | list[Self]: The loaded resource. - """ - if isinstance(resource, list): - return [fast_dict_load(cls, res, cognite_client=cognite_client) for res in resource] - - return fast_dict_load(cls, resource, cognite_client=cognite_client) - class UnknownCogniteObject(CogniteObject): def __init__(self, data: dict[str, Any]) -> None: diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 82258e937..dce03b2a5 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -208,6 +208,20 @@ class SimulatorRoutineConfiguration(CogniteObject): @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + inputs = [] + outputs = [] + + if resource.get("inputs", None) is not None: + inputs = [ + SimulatorRoutineInputConstant._load(input_, cognite_client) + if "value" in input_ + else SimulatorRoutineInputTimeseries._load(input_, cognite_client) + for input_ in resource["inputs"] + ] + + if resource.get("outputs", None) is not None: + outputs = [SimulatorRoutineOutput._load(output_, cognite_client) for output_ in resource["outputs"]] + return cls( schedule=SimulatorRoutineSchedule._load(resource["schedule"], cognite_client), data_sampling=SimulatorRoutineDataSampling._load(resource["dataSampling"], cognite_client), @@ -218,13 +232,8 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = SimulatorRoutineSteadyStateDetectionEnabled._load(detection_, cognite_client) for detection_ in resource["steadyStateDetection"] ], - inputs=[ - SimulatorRoutineInputConstant._load(input_, cognite_client) - if "value" in input_ - else SimulatorRoutineInputTimeseries._load(input_, cognite_client) - for input_ in resource["inputs"] - ], - outputs=[SimulatorRoutineOutput._load(output_, cognite_client) for output_ in resource["outputs"]], + inputs=inputs, + outputs=outputs, ) @@ -319,7 +328,7 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = ) @classmethod - def _load_list_or_dict( + def _load_list( cls, resource: dict[str, Any] | list[dict[str, Any]], cognite_client: CogniteClient | None = None ) -> SimulatorModelType | list[SimulatorModelType]: if isinstance(resource, list): @@ -343,7 +352,7 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = ) @classmethod - def _load_list_or_dict( + def _load_list( cls, resource: dict[str, Any] | list[dict[str, Any]], cognite_client: CogniteClient | None = None ) -> SimulatorQuantity | list[SimulatorQuantity]: if isinstance(resource, list): @@ -397,7 +406,7 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = ) @classmethod - def _load_list_or_dict( + def _load_list( cls, resource: dict[str, Any] | list[dict[str, Any]], cognite_client: CogniteClient | None = None ) -> SimulatorStep | list[SimulatorStep]: if isinstance(resource, list): @@ -467,13 +476,13 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = file_extension_types=resource["fileExtensionTypes"], created_time=resource["createdTime"], last_updated_time=resource["lastUpdatedTime"], - model_types=SimulatorModelType._load_list_or_dict(resource["modelTypes"], cognite_client) + model_types=SimulatorModelType._load_list(resource["modelTypes"], cognite_client) if "modelTypes" in resource else None, - step_fields=SimulatorStep._load_list_or_dict(resource["stepFields"], cognite_client) + step_fields=SimulatorStep._load_list(resource["stepFields"], cognite_client) if "stepFields" in resource else None, - unit_quantities=SimulatorQuantity._load_list_or_dict(resource["unitQuantities"], cognite_client) + unit_quantities=SimulatorQuantity._load_list(resource["unitQuantities"], cognite_client) if "unitQuantities" in resource else None, ) @@ -668,6 +677,10 @@ def __init__( @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + script = [] + + if resource.get("script", None) is not None: + script = [SimulatorRoutineStage._load(stage_, cognite_client) for stage_ in resource["script"]] return cls( id=resource["id"], external_id=resource["externalId"], @@ -680,7 +693,7 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = version_number=resource["versionNumber"], created_time=resource["createdTime"], configuration=SimulatorRoutineConfiguration._load(resource["configuration"], cognite_client), - script=[SimulatorRoutineStage._load(stage_, cognite_client) for stage_ in resource["script"]], + script=script, ) def dump(self, camel_case: bool = True) -> dict[str, Any]: diff --git a/cognite/client/testing.py b/cognite/client/testing.py index 06b484054..0e7d29e12 100644 --- a/cognite/client/testing.py +++ b/cognite/client/testing.py @@ -42,7 +42,7 @@ from cognite.client._api.raw import RawAPI, RawDatabasesAPI, RawRowsAPI, RawTablesAPI from cognite.client._api.relationships import RelationshipsAPI from cognite.client._api.sequences import SequencesAPI, SequencesDataAPI -from cognite.client._api.simulators import SimulatorsAPI +from cognite.client._api.simulators.simulators import SimulatorsAPI from cognite.client._api.synthetic_time_series import SyntheticDatapointsAPI from cognite.client._api.templates import ( TemplateGroupsAPI, diff --git a/tests/tests_integration/test_api/test_simulators/seed/ShowerMixer.dwxmz b/tests/tests_integration/test_api/test_simulators/seed/ShowerMixer.dwxmz new file mode 100644 index 0000000000000000000000000000000000000000..b9c93483592f9e6c94ad0189bea9c2be1cba0750 GIT binary patch literal 15807 zcma)j18`=|)^2QbV%xSRp4hfAv2DDuZF^!H6FZZM#+cVXL1@bwd`9VNb(7-^bK|nxQOpHxf*;qIj*todO7}(8N zSQxn3I87NiOiektIGIg2Sb0ntJ$~Ar`<^=Oji&tlj7)dWZ$?FTtA^e2J5D$*k*WYJ zC`U3hRIVXsW-XR{=H{?XfZTa`QNav)845NU)(S-Ub8Y}cqTmUunW z4_~F6s9pEFt@IG}-%nXMzSGT(cinwD;oXnZb_c!)UWtpHE1^SMukyklD^WxXNn#=x zrdnw`OCJ%2;(lzGayt}%a(e~%VxEWBEgrzNHqP=H8o&^bCth^bd(dkxO~sj2l@`fw z{Q;~$wZP11n0)Q|oX&|IQthdNXNBUwrPbwkyJ?@bG*&y?UwmZI4-y~fl}Ahzn18fU zf%CEttmU9@o&}Qa2JOz+9HL*($kPax#J0`3AyN~kpX*VD$Rp&Nq>m>XyRBRb2qBEb z@p+%p*L7n`>o*osQh5J_R@n;v6M_WGD3AwP^OFnYg;HwV;v|Wf`^nU_bD~W$e~0gg z@Y`7Bc=F9^r?W2WO^bJVn{$$S8bBo|N?{g}Z!O1@aWZzy!@*6Pwh}b1Yh$&&?6yd1 zNVR0>$;DpMZ6_TqmRTm+nluA)ykEU{5)#10? z`ZMOv)i_e-HFh+Ngw>YDXxttxnn1`WnveQ9MPPcf8xiL2K6sBHNCypH7iG}{rHW2v z)k9WfeAFo(VHs#u+Xm4CY>$Ke)YSs`970USQ}(jbg!?__VA5f?Zj!jTRh)4UvyLGP z|Z$e%P4N66E@$={?;dSlQFgHw7O&!uTHKj5Xt8-y!jb+(S69bW6sxl z39UMQN}Is~*bJ`TJ!FQ|`ZUG^;-q61r_=GlY+Yz1E2=7(y<=dSFeyitLud(e;`wad z))~2+dk3)vyk`W3b>?78B;B1QKli&VJKS%D6XS;!bgzSawq=yuM4RcNEh(svwrM5@ zT8;6omC;_WZt}dAhX+t=470;PHmzstT2-)UX4(AEjfcg0lh5V2MfyMsjiiwY{5^g7 z))eM>95;q*>cz3TBA9b0a+#dMYwxNlF>Z+UGPL<%T-5&uW5+Y+9#%7`0xqXp#%p;t ztH-3XJ3?pH*{xu?(Hpc4OA)b>%1p0fWw&F8WZmP#5P?i=eUn2A6`J1v2d)Noh49>W z_wdCwy8#CxA9t^gmv7uU{eh$oi0WdRUOGFB-a@IxqjrFXi7|`Jq}#S%`|z0KGWG-z zrryxnjI0-I-&ntKvyX&$K0*wQQ)7}y@D^>+4*-1)Pp&nTj?GikQ{t5=*leeST_hCK zoy$$XcOeou@Mb5nlb-J_>ihM5sHWKj(>J^N|EwA6u?`&Fsu7z{Q@3$0iL?>tQe9=@ zsa)~rt#QnM!moM`d(yGT%pxR7H77y6JaSL6!Bp|dVN^4IHFr^0&fESK6+OWNTrnJd zFU+tFD)nK~L*{jJ7i#VQhTIx}Fmv7q3zZ*YtB88{8)(H4U9X~Q1$sqReoQPZnv!BV zb1OVqhQ~)7tWoQ3(HQ{tpk>9`WN5t(f7N|SL=)9hOqZH}oN0L+R-%I&Z3a3pdN#a8 zOzL>ybNDMJoW|hK*`FAG<_(mRYM2OQshNc74TsG%2CaqS=FMJohKjmz2+APiOy3QZ z=KIyuG&qvx9)gd=I79Rul^cp5NJq71@@2>7;NLkd-YC_L$<_l1d6p=W$W zu9Mmi_b7R!p@NW(sZNwLiwbHBk>fKN-SNnj%@EDfd4z_BLI#1@;G=J(+e zdld`%2)=l6)6J=IPz`%5W7(HD{~+(dH$ShoInRxp<*7qgnXTC67((nx|Hmr#jyUCX zg}Zk63)bE>xp#Go@DC0~t2xkfpgVJl*TjkhbT>yj3v;6Y-x=gp?(`~2m43hvc;U_z z^s4S@qRY4InTt3wK9@08yp&{S$Q2F~7tVComPxlF*+W1E;JarL8*)p|P!Tox9i)cf zOz%-eGq;18F>lV+o^IXkymBVVN;x!@55A{q_ekw1cJh@<&}uS%OC(W}lv;bCSX8d7 zHasQeV`ns!9S{3!C*05Ab|3rzuoO%YEQaABuhwtvO~p+)hPJE>bWOlo5Nc=5SX9oHzwrh_ zR-`=?5so)3Tb;JFn!9dvnpORrHi~vCnpmw336?hbFS?5c3y7;=D7#1bvTn3rt^gDX zFi78(Wwt1<;E0RKf+jj=^z(t}Q|5zaBybCyaGavN;!-?2Jc5t13h9&PmSIbS?DF~|SiZ3Q z?wCNp2yA7gOe#%AA}O6knUz`wL>bqS{dS#IgSmELZ3aM0+EOjhSoF-n^pcFOk*FN( z$Q~B6t+=w%HYW!QL~b8hm@(6khhC2r5rze@k1T$JoIn!v*SDNi+M?Dy57>4l3EB+# zth1b6(^LxxtAB3a5~tUbmwwd^b4OR*_$BOwpcS%14RSJS^{Ep?v-jz;4f3<;+ezhh zLCUH1UgnY-TD^T59d!|`#KVX8?z;UzpebBo@fan=#1aO~W8^v=>4&phM_mStV%WHS z>;n8$2{CSA^|ub1A6Kkl6nQyV#E?)VY%&Mm2_*N+wf$# zCw2pSu0Up2l{tDjPDA`aQON4PV-k+5D9u0HDHK|2a&to&#sF$Nan-=FZfAFF`agms z@ZXnBpnat=FqAlj(;^xe1DR7;N_Y~q&SLQL*A zVUx~_l-t(e#ur|bp6}?rHKWKHmyV=-?rp@c9j+N`$JCymQKmVp&|d#1qZ#5gK2@VY!Ai&ITZQvUZ&D3xt}HQf(4 zCoMT$6_wVGtzW-pYP+Ih;IGZnqi zAwPsv+x=m)rVSVf09|xJkscdLm{9Z2in?}(ejEgIIp`OF0LK|o1s%gQQ&kCz^`^`? zv3Dcbg6;Ci#)9-k8kb0Mf#enE6v=Or5@+A`?=*n=#Q&=v6HKC9RB8Kc*e zhm)7q8?>cNA(Db2iiSBiKv&zli}$p2@I%Q~=VA+|V@ab1^LPtY?L4c4ac88OqWh)g z9?DOUv$p~7DP!XKh~f?CdYgBR_K{?>2AqQFf!7M8&-0=BxGr9yN(QZwW-v}5uQ4qB z-b30x(*~zM!9YR_rfj2bEw$q-rp>+PK@{Gf+-JKQ`XCTE!1yYh=9@q9d`~y?%+dPp zjn+~^wB3rO_Y%nXE}Z6)p_{PV>*75K`oZNt<9I9&4bHDm6aAD#z9O7=VSL@Bbw{ zmXT>?RXUUskiWjm6dx#@0x6!TCaM;&($r=*nanP|C@YHQs=BqlZ1#PEUVK?r?~mB? z5!qlO1pw}wm`bCV%**aE^tkyc8~!PWi&lJr0V0sqbZ=CpyTNeOgK}+NP8{_*p75|@ zv*G7EM;XzqtXwL6Iv9Xrhvdh{9e6`UfTa-0aX=Ul$rPOMXF4w<+&?Nw1c0P}rJuVz zmBQdo{G0~c5fD_V6=r6YSrQ1ASWQK+g9$0xxUJ`+780ARcKZ}3o3D9A-&j0KJwDSO zwSZx0s@mlUf~+C)_f}z*Hposp5yr_Fx3W^`GAp@Yr`|)3MP!*SmBKX=y2IlVFZOYW zar$((>r1dA`y4#-kEJr=ZTF|6{3wVNy2+)Qemc*JE26CxOoR|$q<1(MmO0I=4z8*s z@|IS{mcREqZUR>TXghHcNE1U7hc{42lTM>vM8$R(mchGqOoHqE4Yd31kKOH(0sUVZ z=r7{e6HjAc(fIf%Z78!nuTS zTYGf+2Fb8f@pL!m9boq3_ddZ>V$_zLC$y;&I>*#(K1JrkSr_<5;!B;av_PJ_uo|LB zno)-^9>=7Gqt9lb!J4&?;CX=MSSd-6Zl5qsrK`(opuy#LKa;)=?NlgZ?AlHzLzghzJRCp{c41(w(Vw|3|bys(b@ zYsN?6Ls*yG{}O55{{_zpfiJxN3$$OLEX)=DPyF(ijenzi>lfARm(~@qm5BY%gA+1- zj<;~D?7CG&dWW@jgSF4n7__Zgy}J8pXHR?Leh+)?hh zp%(|!so6tC?O9UM`o&HVr*;gmvr1iJD0Pdf_?JQ93vOM;)&OJcR7z@If$56lziD!U zhUGyem0^|2Uz}r`{00LxWtOeOxl6o)OA0r(vU;8>xe3H8$bcR>(5eh z=|b9_XPfuY;6XruWUZPsJLU!k!|j9x5jC)8#-T-H!4(ymQ&h47P)y|BqQMFYRK@^e z%>7i9y=d$<+k2s#7R;wBtUOI69WO1gxnTi9V=Vb-KY$VtQqvM+qyjDk+&XzNdNRM?Lfa zEfvlRyBNn$zr=mtvhNJK7;a`UUA{I0!a!{IVI-H=>qAjF;52TwenCtWv)?cfo+7Zw z8sAq*8C&*!z8yLjqjBGk4-In=Bn`WBjGf~={q^6VSp?TR3A7vZ|9X*(z-$TOkutKX zQOCbx8SjM;>wOm{7L;50H@;v~tM`>jC-LJTwYYH+Jkb&^AH__sA)1>(*!cwXBJ_;@ zIe@&pt%D-y1=EZ`VU8fdXM2LdkL!SNR!k|FE0tblso3K13w4YBW-=$w>)@H@FsZgu z4aU}$)%+BXeRcL6f_c8e4fJ}->?-K_u&dWVXulHp=a>p;_9HbpR99Fi308gj`#!Fx zn0%J|02(7+I82uw#va8J&?N{+%F|i?Z0oPeTsRe6=!kw{roi&+dpixwb%-vNk^h64 zFZ5JE|7%M7s^q^h^MxL!lm8j-^=0EfGa{ll*gqQl6N4wHPX+Y&Fls+AI>ZCd@5i*1 z#6^!939aZkjx7vqWAA1laIo|4_Qo+)_dw5^z^WSoONtpBtiJVb;3HpAV=_o_7E)?C z3dXxP525VR;(e^d?5*IT^reitfUPUB<3Xu=OXjL=y=KWC{3i3v=hs;$ag#eU#@xZu z!OdCjis+FZL_s6ug4a0&C;~8R?Rja9D~V_mNzxE$he0?QO@96A%;~Q#AapK_UTBib zFkYlh16=9X6%j@ulLha-eo=?fNoX0{bf+wT2=0>l%mIIr)jvciUIZuAS&#W z#}?Tjf%yt43a8vYZO;)gI7!(N2^qQP0d;wrDt)gNI?d1=j&+F6;DSz*t&Ls)G`GI^ z4|R;*%_UFz_67Gy8toYb4lc3#xBx*Z?v{=k&gNBVEsLFi{9%6aVRqAibKEQ zH4FAgM<=zO?`T>E5V4Y8a}KFEqh3~&wue`$+tPA}$vWY3jVpvHSvFG|UFU7Fo9`i! z*kDetk31nAdn&U#joSdqpeuHQgXnu7n29Z*XGetLvnPvGCNrw>y|YefW6b2z2 zvAvAwZPN;7LzN^)&*o&Oln4GO93AF32pniGx6OUphmv=ju{Rvw!$HjUPbJLm)kU5b zl0lv}sD|FsWnerHI5|tUMe?dmuyneGDAZVv!h->}OmE?w<|QhWaxHk0350PcKt&|0 zS#C{LU(<+W&Yr z)w@52phC*aBSf*djDow|fVZze$DW>l3$#oP1M(**+IP2w{u)_h{41#0kQ}_ej*A;D z?nLvm#mPz{mXOLwspJH zq=&hK*IzV^Irb=NnVFn1vijW=Tj+Y%ex-QbbibiADa#~=o5N*!TY@5qdoG@xE^mg* zTRT1aA3pWBRHQTOh%p!w#_?dcQ^ z;D#T#e)Ap}m!Eh91e>=U+_XPsJiY4~1{OAqLKgNzIzkzHtsypHhVb4QemT;s%x?-8 zP&{>UoWsyKIfQ@rT9x}>U9$i&J&Lo{zH+1ih0mb zVv8^TMNqwQjD*&6U993Mh>{Uf7L!O3bwUmtxur+SAF=RKjCJ7edQ}aRfWO7%;U--K z+IZY_B|z1LD&T3mJ~6sR=4e-uk(DQnJ$P+91y)QAlV$F4-_gO7hHm`oO_v}}Ts$FM zG+x`p_S>J(lDOsx_+w>!n^h?RK5-Y>bbo-KoA$7;HFUq^%x?&<T(Lt${%s}m6X zrblh#dXvaVSui^5R&>q3ok59hA!ffzh}@Hv)s5|OOyytAgx*{{3p&+yND z0-X*R;%-VX5Fy_-?4D1XXTJ!x8!Om4U#0yNCWayzA7@M&zZgc~_7u?S4qC;}q5sFo z##=W?&^e<%7|5m3dkFCEXmQF7~3>T@nQmdzhyyL9l~b_;P;0R6|X*LdB`w z(o?Q{Lkk~QBD?UrGA?n~WUcw4wYBE>rAo`eqR5?J4Cs$5&a^=S|Ng79)G^gbIH&Y- zx=RHvOfHZ8%ZsDs^$o`s3c3gZ&F1Cb&QHVh2nxNn3#EN|N_!23VDwyv1?3ND@dNin zE~5nzNM83-L@eSiw-EA3sh^^LhbYcMFol-xDRz)F>(KLcoyf&5=rDKwFK6RX!n@}r zNt>5UZjaMQ?)hgIpNf;Vod)OF?zzFZp^P{UIPDS^WpYbAggS~RAeF>*Pq!7&PT2?r1EBUTh7i3`ReLO);oD@U&9o!Bs^q0rO)N}S& z33@3F;u-}vH_66@Wn5)ztCRBWeB_c#?o#UdgF(0{KP(mw=+u(APA#ts6GY*x|BChM zG%*915r|+siDTi)5oi3&K%hg=I#NHl7<}{d?wnW?na1OX?#s1H!IMA6PuT3Ov|TS{ zp``dopy}NaRWQ44K@E-qRZYm3|6o+j{|q6Hz^ZY@AFXC6Dp zL@el=>7{tQi&}_2`x)l37d2MB@)4cb;sMc#d?)aeZyeu^IUVtNZ+twg8@!w#AK0d34B##In8l?f znq8yZ4%XpC?brI4LJyyVp5{v`A#l&l0imTh3xE1#?6G6{v7OWT)--zFS7tj9CI&g+ zbnQ3SCrbzC#Nl-~vwuQNXZI!r0taG(w8KaAYw~-q#&gwW2k5l*m_>B1L$d{(sPConU_K! z*h7ABp*zI0m)yNPwsrJN7H)lE={;ln93D4fXMtw@>uI)y%7tmvB|~qZd?BA6dy5zd zBs=6~VTh#>elPORnr_Y#08SC7>Q0XS5$OeAr)xO*{i|_-R8WiHVOCxI2czqZDF>W?LB9?qJj_|NIgG#vPSf{=EsC5mv;f7Wou?niRW{ovFjL^ z3~T_UDcQ_^H8k`Be^cZs-^^4%`?6gh2aD{+TlPA z_8FIlA_Z#a@FJ7|BMqyIl$1pynN81ZPw5tTe{GVPUG$!kVpoV+5_yhl8fsePyj&3&Rdg)PAFNl0Vj^+A%Y1uMO_?7a&W> zU`DQYedwg`YAO$Fyc3XD0rSKy&V7=t+=|Jk>k<0l>bW5u1hr&9Jj}{MV!+!?J_}5NFqtQpYgqA zkNOyJ?@IqxEQ#|%L|sRn*$&$BBFUj$Ocs)Ja3E}jL0koFQtPPM{8V?jDE1xLYbhLT zN&B|09t1nov;8-a^_ajR&&$5SS$ZXkQo-9I0i^HSkW&n2N*~=thSRWsN^P6PIOd~l z`)&pei?Vm(*Pl(9nno?K8)W2< ziWg*=_7*e)v4!^Laxb>~uSGfdlRWy^*=(((1>ff?lQnPl1Nc|lE>h(QEKIy5TD16EOP3PL!DYUy7pV`F}n1_9Q+)yXV z2z3<1+7rsPyD|}**%gn)H03UCg`ekE^|q63(YWvP9mM*SttVXGG1M_a7LUX%<}J3y z?LcAE8K_HBp8SQS4QSnI4IwPk5?&C&-ZMW>E&WZWk5Wc{TlVmFQ%Cg%+6rkFc zK+C1PCvmbawHGzc-I&v)^0RkkzwIgT)q4aPKdDGsICHa2(!Sk}*dQe5^i5 z>e+?#DJpWC?n1%3&d#5LRP#M@fx?49gh^0jA-Km$J>24W_Sh^d3uMmN9?RhMT}#5= zYm6X8*GZBhZCz=M!d=zrKWf(>%y=lS`F#oPH-XO*e9a4{<5vG2Onl+5aUuh+!huZ9 z?yE(7l)3rVJp9`DL*6>=&DT5KEdF)#d4c>V$6|ZJf6Vv~5nsn84hhMkeR4}HymX-G zRk|&Pt>d_Jb7l$rghsp=`ySs`drUE-d?tIQTonwvmC#cAtJmT1~%2X5;{;mj0`msJ+I!{ zjlRYPB)287aw+dfRIYzP7HB7DS=Q0*fi80(L3hCd!2r5YK%rTjzZny!P~YB@>~j%1 zXiw#LpqhKxCQ$7Te=JR9iZ8T!&y?5XXV>R$CV$f`170fVu(7#D@;d@(bUD7a0(1}5 zaDPfaD3CU3hxxNXCJd+cW!XpSGss$XZJNOtRCP=cH0tE&C-O>K9#4)FY?3G${p{~cHT{@su{%+5P%IgkP;4cV!9e^)4zDL3yhVv|rY7}l5Z7+OiK&}d6SpA19FM3s}XJZzG2jMe=mQgr!IP3 zT_o-{{o1URR1vS?k>@5N*>|ZsV5`B>*SOlHq~?0Pg6*CM29{d6Lx^8UAF<*e7@NjU zvY3`wIK6gFg11{aDac#^jwsT^uLN&A2I|p$wpC1931j5rga#DsHT+^%ZFtW%!E^SX z$tSyXE<*1;H20e9XPz&>Ki@$ufcKbXORd7&KfNa3ADY{pX7ryQ{PyU9>lwrI z<5`L$J@2S1@Qui^F|CDXq5M=`v}OumB)!+XBN+BF{W9U@+G}g&@C$fPaKo~Ubp)Q5 z)dPr|(uwaBtr|3dD;Ky&Tnv+tWG6@8r_p0Xl%7YNGTg}erH~N~< zL?NEqEM2f5|G%{J(6tzE1`ss-%nUz>q&|&)JwsF0Nmh}kdKQ#sem5slDmP*^V|ld3 ztX(vAQc-TmPmg0|oMM9~(qoOd=ot4)LyxQhcn+wCM%#=L{}!76!C7TR8gbnLqED-l zaC0~B`rzH*m9tTW^~p%OiHUNVK4b;zEz35Qk;+t)eiQtrTk!|QMSJI-XO8IkrnnLM zI@Gg?Ijqzb2R6h#+%W#0mbj=;*GrvuT-vT<-yINv*v zm8KxSC&zs0j(lm4irF}=YXhi6qc19S)S}Gas9D8@$*MGUcMBLJd)+R9pLTaC3n!wc z+zf8J(A%j0eVOh&MYpuAsfi0V%*c|7%k;i1$(5xF&cy~XuF;a~gk@bc(+2WX@#0A9 z25)^PllU*8)PX6&h$Cy(Bc>zGcmw&poH4Dh+VbT~OHD$LJiVjU7AlZgEEVf{9$xjs zg|zWtZn19_P|d=OdZNEaPd53*Fm!AD4%SCJn6(MrJ7hI)9sllT-pH1f13a7ji_MvJ z;#5N2!ti*BuyIoL2XJ>8QTZUJmxiE}nATCCo*@@svsCYY|BPhy=t0%Mdq*SYU{D7w_Mfc779HLF{b?W@>)?Mjb+TC3c{9!vNH}%RN|7szSP*Ugj*LeR~ z@F*~Sk0Pm-Es;*&1<_j;S;1}S9x1P|5t$tY(Aj+g8v_v<-X(+P!FlgmP}gSplsEWr zg$WCO`71pX$&rU}nVFjg^YH3w+lB}f6=L#w4Sa}xIaemk<7lTRh$C3WbFQm`U1P&6 zaknG>*&^t;ZAN}A&{mnkLJgi`XG8~aHZXEE&CqhBM7<*{Jb!;~M8e0}wPMic|D=MM z1;tbo%In^b3RXfjLVOg!um_=$TttXhxH7%s_}0;|zo=kc3D`5Of4E@iwr7l^6*w+U z*$emFyp`%Pq}u~Ur0A(1V6BH&qq^9D60i*N=`N=h`3_wb9fNJ=Mm>u|!CRZq*_|@K%NLZ9$AA0ecd5GSM0gi?cpihY*-X(lxoPVN?LQeNK)+OWN5hM z!UoUXBs{6ZTQ`TkO+*E{!M|KA56cl|&W#j{>bbDlP?L zFW2t2!1$l1Z#nfJG|#49Y&l%>CK2dX0a99_4;%Q&hX}|sv**WS{~ZRH$BhM`U{hMy zHx_Bc5{Bd%VMn$J9UJw#S^59re|tn5ViU4-M1$wX?2gao&?9otW`5g2HP1vVclt3< z=e;m0Yj;xTGAiKFS{qe4OYc=mj#KI5+UIhwF+5#(>;~ovcLF8DkK11NIS?XcNNt3G z!wOwbc$_p`IPKNP`+qgb|5O~Sd@3OqwCZA;Kg4Y zF2y7B?4&_*z|ErYj+`=~Y~6cD&0-)K9HNI6$}&Ht_TbMR@UAKe(g+QA)k3708<&f> z-z>l~3{0z?rdSPP^&sg}M(85Pekdu*9!xhPcp&8@7bD204zVJ)w%u^)4m3UH9FWFx zh>0kvMWfve(|o*{I|_Qo<#F!zu4HO(wK^hx4F6f@W`ycj*3J2-?i=-t)(sUYpuPeC ztbaM-WF7MPvgsn2DBii(KOm~Sma6iZS(ml10;@C}2|iNl+NEvm(m^b^qg-G5m@(R! zGJFw((yQ4;?QHE?$R6Mp{aFpau?~J4r;J}z)tHye^cP8rV=5Fc`r3v?s^@P9uI>bJ z?hs)+N*Y59ePk?CX_^s6Us0KDp(ovc^Kf|#J@dp=8fNPV2~*fUh=vKtD3CV3GHl&N z$r6E8UL@p92PA`m6Kx6%Um}|dz^^e)1F#i(z*;Ae>$wP~(U!Iz(&OyJL#P-)eMv;(MppPM;L$q^o@$eDso6bq_%>>5-G+bsO z9XW&D1QPJgLXNc^nLJ$jc(#xxWgjDnbYF_&ZyGC6xXG?-q=~zzYKHskh5Gwy=@WEl z84zB5R2y*{4B`by#wO)Aq{iH`6b)_PPubw^Ef4`)uiYOAT>$2DB*RSmN+N^~NWq3D znZ?8RhoLWX`Ao2h#pRCg<%&X3UK`AJ#eTZwz2EMPlFc>}lc;ntP;O6m;#B<<{Y@#v zXZNRsIWb6nQZtMR$5l}a0`4(;>v zj;@6NWR~|k4DPW?4}u(AAGys=JG3-}t1Q&X+#GQlnm~irz%ZMeH7kmtaW@DOI|{1A zE3DAF8&>bZhU|HCV_pp|Bkc*Yu3fAM729>LC7vriq5{bfO-vLn@%J=i3s=YY*5hx3{+s z;FXw%zi-}VY%r>+A#708ROHjDGqWey5m#lLo743@D`UN<(cEY5_NHe_Kcuj}^e+Z> z$~#wD1T=++$T5*kFUYj8Z`JyE8(UDnHel0HYt54Dr6#IYr+{DhzeO35Fx*WfvPJZ13P zZv_qvf)RzP12($@XO?)I3MOl}-=-H9l)S^0U=-G&Vl?|*%V8&AQ67^(lDh51kjk|m z16^^dt3t}9v44yz#1umW@(a)hqf1lb;0_ zuYIX+eGQ-I5hE{)_J*IQBJD>7-dk7;ywQLLYVle}JQH$F{qmFjz|83RBInO_XIgJv2K8J)!KEL2;Wwlzk44cvsnGWI6eDSn>`rK0BWu6$K)>2Qw5B+Q! z)60nm3r0)cM?NZpFkWg(DT}&dmea5%H=7_EX+l}8Ak8|1YpFD_8~eW&Ro*oGwiL&} zmreWUV>}iVyZ!ameC5-W#6;QVA}b}>S-;Jx;H6;3xa{$EII?Ys6MS6+&EaEc3gT)E zIJlA}nbFPRN_x%q8)>cxd1z1!NFD-5KExG;`D1d?)1KdAnDN=+8?CHg?PSg2$C>2U`g2#dkSQ`HJp;HeL3 z##0misAqYxc5Z;U@^c-#P(&0}vWs!Yn2#-@?hU~=C^ zPmn)wxq_zZJ1x<7fl!sQ39_*670bff9)0`^h$7Wy4x1wZ(@a;!CA>&QoJdNxg*0KN zi`U;;uLHh8bQzAZ?`i3SR~{tRYO8ih7(FCgE7_cAbC}t!iZwf$P484!jQ3z$Yy~7D ze>)DTtDKP66ALH85<=)37UG-oOGRn**cO>4ZVhFaK7OncztO_g&`}jxVAowO|J~F8 z8f810N@-cDKXcfXGXs;>t*WN3)|fj}o-^Z-57%HdvSTYynSzQKaYA=`)HuVf9?AbH zQl=W2=XNJWUwHx-5_3w@k*`%c{Q$akBTa|J9-FWEt=>ua85j$d38_>)*6-#5p~L=! ztH-euaMM^KPXG-FCtFfTwEVRhTF{XdqtsG%w>^*3Wo09B0x8a!-EW#_?WVbKJ&Q#RPNu!D?G-66?o2RfLP ztZMQ#K8L=^YZHs^(iSeDFL*a1la5|S4Pn9t68_-ll^eN~T?3);8@Z?$h_bSlo;1F1 z8~$uv2Ihg*w%ylqrl>n0vXElXqm-gODJOI=t0)WTx9L3Yg-$)s(@x2P>e6~k<-@uT3 z*xNN)o@SBb4VinqeW3izqDvm?+keEA9XrcmB1HKy;6r1F+Ea!@km2OvGt8G${~Pm2 zf2Yahh!k|`axmvy5K3N~gQ5*D8oy3D}Fpm4>&CUZ^$aqeU-mGLpsdb37$t_$6<%Jc#Ygev4B`dd&! zgrB)1DMMb8!j9o3U*|9P29ny-9O3lzrC->%zQlBY0U1pjN;us>>bUaa5~n=q!?N$H zqTv}%89ZwqeD_niXIFnRNDGBCsgIvD%##QQ5jUR$v&MX_cPV>Xqki-YrdTIQtA7(} zAqGYwj*v}8fnNR6X!2H0xjsQ_?M41@bP~w!;(5Nm_LqN*5I~j zd6=Q{H?_oP%>CZ`Xtj|5~YhN zcRFW47V$rSCh8YCuFHNZrVp*|isOTW+nsuJg#KOkd<)CH8Akct$0kEbg$xtQmG7#- z5>%fLGpVLqZ?Se6qLk?(GUkPF;x+Kr9j#YI)w*-qcQM*K^Kmc+K-6$k)2L12TpD*( zuLV8aOZeiR+Y44O2H-p>q$ouNKqG%duOavpsf#N>k4(;tr=f?vcFUN@fx?W#Inv(kN~7d$l6<){2BE$zjFIR* zP9+I_uK7M)e!eh8eCYKGJ){y9`l!lywd|vu6P(u&q``FWfR;9X>Rk#r{xMzdL#@hZSgM39FUM)A*)8pR$*uP5GfK--CG_NcZEn{D=X2k*lS{RfU>oBF? zO3wo})hz%&S2*v?gwV~PLSoerjcs6+T6xsrIv;hx4SojNO=zp{0z_hv_mjAsJ>Ah6 z@}vS!9|_ls2w$2%!OsuhByh;w)q&bUcyqw79?Z@=6E$;ayL^VUU{%e2g&_X1^53ZI-wS?%j(El_R=g4u1s zuUz9vKK_n(laO(dSF+F?_FKgU-zW9=iEEskZ`;@YvhKB;M)pBVkJq4ySFK!oPJW`9 zE?uA1PQxdmnZcT{aLHUCJU<+r6E{h@I&nnJr$qTPJo`V%=9yGiU} znxZ=OZV4o%3Sav%UiILzDNUN;${J0cVe1-Ais6$QO^#vQ8cl}b%ovvUTc z$))N`Op~|pdP&^|d)_h}WZB;K2asDjRvwq8=01_wOfwU0%g*+-H(l+T4GCQ_)H8KF ze_f_IL|(h(6m9NRYB5-63Nw4bLlKYce6p=dPS+{PsizPhSK*}Dl{qsHlK0X}46lFlc*g*dO{?Gr(`d{IH p*Bko(w)%fJ#Q(A?_vLH--)t5|8Azyq3W9x|RbS!9S5Xj<{{g7Ey>|cr literal 0 HcmV?d00001 diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py new file mode 100644 index 000000000..2de2f000b --- /dev/null +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -0,0 +1,740 @@ +simulator = { + "name": "DWSIM", + "externalId": "integration_tests_workflow", + "fileExtensionTypes": ["dwxmz"], + "modelTypes": [{"name": "Steady State", "key": "SteadyState"}], + "stepFields": [ + { + "stepType": "get/set", + "fields": [ + { + "name": "objectName", + "label": "Simulation Object Name", + "info": "Enter the name of the DWSIM object, i.e. Feed", + }, + { + "name": "objectProperty", + "label": "Simulation Object Property", + "info": "Enter the property of the DWSIM object, i.e. Temperature", + }, + ], + }, + { + "stepType": "command", + "fields": [ + { + "name": "command", + "label": "Command", + "info": "Select a command", + "options": [{"label": "Solve Flowsheet", "value": "Solve"}], + } + ], + }, + ], + "unitQuantities": [ + { + "name": "area", + "label": "Area", + "units": [{"label": "m2", "name": "m2"}, {"label": "cm2", "name": "cm2"}, {"label": "ft2", "name": "ft2"}], + }, + { + "name": "head", + "label": "Head", + "units": [{"label": "m", "name": "m"}, {"label": "ft", "name": "ft"}, {"label": "cm", "name": "cm"}], + }, + { + "name": "mass", + "label": "Mass", + "units": [{"label": "kg", "name": "kg"}, {"label": "g", "name": "g"}, {"label": "lb", "name": "lb"}], + }, + { + "name": "time", + "label": "Time", + "units": [{"label": "s", "name": "s"}, {"label": "min.", "name": "min."}, {"label": "h", "name": "h"}], + }, + { + "name": "accel", + "label": "Acceleration", + "units": [ + {"label": "m/s2", "name": "m/s2"}, + {"label": "cm/s2", "name": "cm/s2"}, + {"label": "ft/s2", "name": "ft/s2"}, + ], + }, + { + "name": "force", + "label": "Force", + "units": [ + {"label": "N", "name": "N"}, + {"label": "dyn", "name": "dyn"}, + {"label": "kgf", "name": "kgf"}, + {"label": "lbf", "name": "lbf"}, + ], + }, + { + "name": "deltaP", + "label": "Delta P", + "units": [ + {"label": "Pa", "name": "Pa"}, + {"label": "atm", "name": "atm"}, + {"label": "lbf/ft2", "name": "lbf/ft2"}, + {"label": "kgf/cm2", "name": "kgf/cm2"}, + {"label": "kgf/cm2_g", "name": "kgf/cm2_g"}, + {"label": "kPa", "name": "kPa"}, + {"label": "bar", "name": "bar"}, + {"label": "barg", "name": "barg"}, + {"label": "ftH2O", "name": "ftH2O"}, + {"label": "inH2O", "name": "inH2O"}, + {"label": "inHg", "name": "inHg"}, + {"label": "mbar", "name": "mbar"}, + {"label": "mH2O", "name": "mH2O"}, + {"label": "mmH2O", "name": "mmH2O"}, + {"label": "mmHg", "name": "mmHg"}, + {"label": "MPa", "name": "MPa"}, + {"label": "psi", "name": "psi"}, + {"label": "psig", "name": "psig"}, + ], + }, + { + "name": "deltaT", + "label": "Delta T", + "units": [ + {"label": "C.", "name": "C."}, + {"label": "K.", "name": "K."}, + {"label": "F.", "name": "F."}, + {"label": "R.", "name": "R."}, + ], + }, + { + "name": "volume", + "label": "Volume", + "units": [ + {"label": "m3", "name": "m3"}, + {"label": "cm3", "name": "cm3"}, + {"label": "L", "name": "L"}, + {"label": "ft3", "name": "ft3"}, + {"label": "bbl", "name": "bbl"}, + {"label": "gal[US]", "name": "gal[US]"}, + {"label": "gal[UK]", "name": "gal[UK]"}, + ], + }, + { + "name": "density", + "label": "Density", + "units": [ + {"label": "kg/m3", "name": "kg/m3"}, + {"label": "g/cm3", "name": "g/cm3"}, + {"label": "lbm/ft3", "name": "lbm/ft3"}, + ], + }, + { + "name": "entropy", + "label": "Entropy", + "units": [ + {"label": "kJ/[kg.K]", "name": "kJ/[kg.K]"}, + {"label": "cal/[g.C]", "name": "cal/[g.C]"}, + {"label": "BTU/[lbm.R]", "name": "BTU/[lbm.R]"}, + ], + }, + { + "name": "diameter", + "label": "Diameter", + "units": [{"label": "mm", "name": "mm"}, {"label": "in", "name": "in"}], + }, + { + "name": "distance", + "label": "Distance", + "units": [{"label": "m", "name": "m"}, {"label": "ft", "name": "ft"}, {"label": "cm", "name": "cm"}], + }, + { + "name": "enthalpy", + "label": "Enthalpy", + "units": [ + {"label": "kJ/kg", "name": "kJ/kg"}, + {"label": "cal/g", "name": "cal/g"}, + {"label": "BTU/lbm", "name": "BTU/lbm"}, + {"label": "kcal/kg", "name": "kcal/kg"}, + ], + }, + { + "name": "heatflow", + "label": "Heat Flow", + "units": [ + {"label": "kW", "name": "kW"}, + {"label": "kcal/h", "name": "kcal/h"}, + {"label": "BTU/h", "name": "BTU/h"}, + {"label": "BTU/s", "name": "BTU/s"}, + {"label": "cal/s", "name": "cal/s"}, + {"label": "HP", "name": "HP"}, + {"label": "kJ/h", "name": "kJ/h"}, + {"label": "kJ/d", "name": "kJ/d"}, + {"label": "MW", "name": "MW"}, + {"label": "W", "name": "W"}, + {"label": "BTU/d", "name": "BTU/d"}, + {"label": "MMBTU/d", "name": "MMBTU/d"}, + {"label": "MMBTU/h", "name": "MMBTU/h"}, + {"label": "kcal/s", "name": "kcal/s"}, + {"label": "kcal/h", "name": "kcal/h"}, + {"label": "kcal/d", "name": "kcal/d"}, + ], + }, + { + "name": "massflow", + "label": "Mass Flow", + "units": [ + {"label": "g/s", "name": "g/s"}, + {"label": "lbm/h", "name": "lbm/h"}, + {"label": "kg/s", "name": "kg/s"}, + {"label": "kg/h", "name": "kg/h"}, + {"label": "kg/d", "name": "kg/d"}, + {"label": "kg/min", "name": "kg/min"}, + {"label": "lb/min", "name": "lb/min"}, + {"label": "lb/s", "name": "lb/s"}, + {"label": "lb/h", "name": "lb/h"}, + {"label": "lb/d", "name": "lb/d"}, + {"label": "Mg/s", "name": "Mg/s"}, + {"label": "Mg/h", "name": "Mg/h"}, + {"label": "Mg/d", "name": "Mg/d"}, + ], + }, + { + "name": "pressure", + "label": "Pressure", + "units": [ + {"label": "Pa", "name": "Pa"}, + {"label": "atm", "name": "atm"}, + {"label": "kgf/cm2", "name": "kgf/cm2"}, + {"label": "kgf/cm2g", "name": "kgf/cm2g"}, + {"label": "lbf/ft2", "name": "lbf/ft2"}, + {"label": "kPa", "name": "kPa"}, + {"label": "kPag", "name": "kPag"}, + {"label": "bar", "name": "bar"}, + {"label": "barg", "name": "barg"}, + {"label": "ftH2O", "name": "ftH2O"}, + {"label": "inH2O", "name": "inH2O"}, + {"label": "inHg", "name": "inHg"}, + {"label": "mbar", "name": "mbar"}, + {"label": "mH2O", "name": "mH2O"}, + {"label": "mmH2O", "name": "mmH2O"}, + {"label": "mmHg", "name": "mmHg"}, + {"label": "MPa", "name": "MPa"}, + {"label": "psi", "name": "psi"}, + {"label": "psig", "name": "psig"}, + ], + }, + { + "name": "spec_vol", + "label": "Specific Volume", + "units": [ + {"label": "m3/kg", "name": "m3/kg"}, + {"label": "cm3/g", "name": "cm3/g"}, + {"label": "ft3/lbm", "name": "ft3/lbm"}, + ], + }, + { + "name": "velocity", + "label": "Velocity", + "units": [ + {"label": "m/s", "name": "m/s"}, + {"label": "cm/s", "name": "cm/s"}, + {"label": "mm/s", "name": "mm/s"}, + {"label": "km/h", "name": "km/h"}, + {"label": "ft/h", "name": "ft/h"}, + {"label": "ft/min", "name": "ft/min"}, + {"label": "ft/s", "name": "ft/s"}, + {"label": "in/s", "name": "in/s"}, + ], + }, + { + "name": "mass_conc", + "label": "Mass Concentration", + "units": [ + {"label": "kg/m3", "name": "kg/m3"}, + {"label": "g/L", "name": "g/L"}, + {"label": "g/cm3", "name": "g/cm3"}, + {"label": "g/mL", "name": "g/mL"}, + {"label": "lbm/ft3", "name": "lbm/ft3"}, + ], + }, + { + "name": "molarflow", + "label": "Molar Flow", + "units": [ + {"label": "mol/s", "name": "mol/s"}, + {"label": "lbmol/h", "name": "lbmol/h"}, + {"label": "mol/h", "name": "mol/h"}, + {"label": "mol/d", "name": "mol/d"}, + {"label": "kmol/s", "name": "kmol/s"}, + {"label": "kmol/h", "name": "kmol/h"}, + {"label": "kmol/d", "name": "kmol/d"}, + {"label": "m3/d @ BR", "name": "m3/d @ BR"}, + {"label": "m3/d @ NC", "name": "m3/d @ NC"}, + {"label": "m3/d @ CNTP", "name": "m3/d @ CNTP"}, + {"label": "m3/d @ SC", "name": "m3/d @ SC"}, + {"label": "m3/d @ 0 C, 1 atm", "name": "m3/d @ 0 C, 1 atm"}, + {"label": "m3/d @ 15.56 C, 1 atm", "name": "m3/d @ 15.56 C, 1 atm"}, + {"label": "m3/d @ 20 C, 1 atm", "name": "m3/d @ 20 C, 1 atm"}, + {"label": "ft3/d @ 60 f, 14.7 psia", "name": "ft3/d @ 60 f, 14.7 psia"}, + {"label": "ft3/d @ 0 C, 1 atm", "name": "ft3/d @ 0 C, 1 atm"}, + {"label": "MMSCFD", "name": "MMSCFD"}, + {"label": "SCFD", "name": "SCFD"}, + {"label": "SCFM", "name": "SCFM"}, + {"label": "Mm3/d @ BR", "name": "Mm3/d @ BR"}, + {"label": "Mm3/d @ SC", "name": "Mm3/d @ SC"}, + {"label": "Mm3/d @ NC", "name": "Mm3/d @ NC"}, + ], + }, + { + "name": "reac_rate", + "label": "Reaction Rate", + "units": [ + {"label": "kmol/[m3.s]", "name": "kmol/[m3.s]"}, + {"label": "kmol/[m3.min.]", "name": "kmol/[m3.min.]"}, + {"label": "kmol/[m3.h]", "name": "kmol/[m3.h]"}, + {"label": "mol/[m3.s]", "name": "mol/[m3.s]"}, + {"label": "mol/[m3.min.]", "name": "mol/[m3.min.]"}, + {"label": "mol/[m3.h]", "name": "mol/[m3.h]"}, + {"label": "mol/[L.s]", "name": "mol/[L.s]"}, + {"label": "mol/[L.min.]", "name": "mol/[L.min.]"}, + {"label": "mol/[L.h]", "name": "mol/[L.h]"}, + {"label": "mol/[cm3.s]", "name": "mol/[cm3.s]"}, + {"label": "mol/[cm3.min.]", "name": "mol/[cm3.min.]"}, + {"label": "mol/[cm3.h]", "name": "mol/[cm3.h]"}, + {"label": "lbmol/[ft3.h]", "name": "lbmol/[ft3.h]"}, + ], + }, + { + "name": "viscosity", + "label": "Viscosity", + "units": [ + {"label": "kg/[m.s]", "name": "kg/[m.s]"}, + {"label": "Pa.s", "name": "Pa.s"}, + {"label": "cP", "name": "cP"}, + {"label": "lbm/[ft.h]", "name": "lbm/[ft.h]"}, + ], + }, + { + "name": "molar_conc", + "label": "Molar Concentration", + "units": [ + {"label": "kmol/m3", "name": "kmol/m3"}, + {"label": "mol/m3", "name": "mol/m3"}, + {"label": "mol/L", "name": "mol/L"}, + {"label": "mol/cm3", "name": "mol/cm3"}, + {"label": "mol/mL", "name": "mol/mL"}, + {"label": "lbmol/ft3", "name": "lbmol/ft3"}, + ], + }, + { + "name": "conductance", + "label": "Conductance", + "units": [ + {"label": "[kg/s]/[Pa^0.5]", "name": "[kg/s]/[Pa^0.5]"}, + {"label": "[lbm/h]/[psi^0.5]", "name": "[lbm/h]/[psi^0.5]"}, + {"label": "[kg/h]/[atm^0.5]", "name": "[kg/h]/[atm^0.5]"}, + {"label": "[kg/h]/[bar^0.5]", "name": "[kg/h]/[bar^0.5]"}, + {"label": "[kg/h]/[[kgf/cm2]^0.5]", "name": "[kg/h]/[[kgf/cm2]^0.5]"}, + ], + }, + { + "name": "diffusivity", + "label": "Diffusivity", + "units": [ + {"label": "m2/s", "name": "m2/s"}, + {"label": "cSt", "name": "cSt"}, + {"label": "ft2/s", "name": "ft2/s"}, + {"label": "mm2/s", "name": "mm2/s"}, + {"label": "cm2/s", "name": "cm2/s"}, + ], + }, + { + "name": "temperature", + "label": "Temperature", + "units": [ + {"label": "K", "name": "K"}, + {"label": "R", "name": "R"}, + {"label": "C", "name": "C"}, + {"label": "F", "name": "F"}, + ], + }, + { + "name": "molar_volume", + "label": "Molar Volume", + "units": [ + {"label": "m3/kmol", "name": "m3/kmol"}, + {"label": "cm3/mmol", "name": "cm3/mmol"}, + {"label": "ft3/lbmol", "name": "ft3/lbmol"}, + ], + }, + { + "name": "speedOfSound", + "label": "Speed of Sound", + "units": [ + {"label": "m/s", "name": "m/s"}, + {"label": "cm/s", "name": "cm/s"}, + {"label": "mm/s", "name": "mm/s"}, + {"label": "km/h", "name": "km/h"}, + {"label": "ft/h", "name": "ft/h"}, + {"label": "ft/min", "name": "ft/min"}, + {"label": "ft/s", "name": "ft/s"}, + {"label": "in/s", "name": "in/s"}, + ], + }, + { + "name": "foulingfactor", + "label": "Fouling Factor", + "units": [ + {"label": "K.m2/W", "name": "K.m2/W"}, + {"label": "C.cm2.s/cal", "name": "C.cm2.s/cal"}, + {"label": "ft2.h.F/BTU", "name": "ft2.h.F/BTU"}, + ], + }, + { + "name": "molar_entropy", + "label": "Molar Entropy", + "units": [ + {"label": "kJ/[kmol.K]", "name": "kJ/[kmol.K]"}, + {"label": "cal/[mol.C]", "name": "cal/[mol.C]"}, + {"label": "BTU/[lbmol.R]", "name": "BTU/[lbmol.R]"}, + ], + }, + { + "name": "cakeresistance", + "label": "Cake Resistance", + "units": [ + {"label": "m/kg", "name": "m/kg"}, + {"label": "ft/lbm", "name": "ft/lbm"}, + {"label": "cm/g", "name": "cm/g"}, + ], + }, + { + "name": "heatCapacityCp", + "label": "Cp", + "units": [ + {"label": "kJ/[kg.K]", "name": "kJ/[kg.K]"}, + {"label": "cal/[g.C]", "name": "cal/[g.C]"}, + {"label": "BTU/[lbm.R]", "name": "BTU/[lbm.R]"}, + ], + }, + { + "name": "molar_enthalpy", + "label": "Molar Enthalpy", + "units": [ + {"label": "kJ/kmol", "name": "kJ/kmol"}, + {"label": "cal/mol", "name": "cal/mol"}, + {"label": "BTU/lbmol", "name": "BTU/lbmol"}, + {"label": "J/mol", "name": "J/mol"}, + ], + }, + { + "name": "surfaceTension", + "label": "Surface Tension", + "units": [ + {"label": "N/m", "name": "N/m"}, + {"label": "dyn/cm", "name": "dyn/cm"}, + {"label": "lbf/in", "name": "lbf/in"}, + ], + }, + { + "name": "volumetricFlow", + "label": "Volumetric Flow", + "units": [ + {"label": "m3/s", "name": "m3/s"}, + {"label": "ft3/s", "name": "ft3/s"}, + {"label": "cm3/s", "name": "cm3/s"}, + {"label": "m3/h", "name": "m3/h"}, + {"label": "m3/d", "name": "m3/d"}, + {"label": "bbl/h", "name": "bbl/h"}, + {"label": "bbl/d", "name": "bbl/d"}, + {"label": "ft3/min", "name": "ft3/min"}, + {"label": "ft3/d", "name": "ft3/d"}, + {"label": "gal[UK]/h", "name": "gal[UK]/h"}, + {"label": "gal[UK]/min", "name": "gal[UK]/min"}, + {"label": "gal[UK]/s", "name": "gal[UK]/s"}, + {"label": "gal[US]/h", "name": "gal[US]/h"}, + {"label": "gal[US]/min", "name": "gal[US]/min"}, + {"label": "gal[US]/s", "name": "gal[US]/s"}, + {"label": "L/h", "name": "L/h"}, + {"label": "L/min", "name": "L/min"}, + {"label": "L/s", "name": "L/s"}, + ], + }, + { + "name": "compressibility", + "label": "Compressibility", + "units": [ + {"label": "1/Pa", "name": "1/Pa"}, + {"label": "1/atm", "name": "1/atm"}, + {"label": "1/kPa", "name": "1/kPa"}, + {"label": "1/bar", "name": "1/bar"}, + {"label": "1/MPa", "name": "1/MPa"}, + {"label": "1/psi", "name": "1/psi"}, + ], + }, + { + "name": "molecularWeight", + "label": "Molecular Weight", + "units": [ + {"label": "kg/kmol", "name": "kg/kmol"}, + {"label": "g/mol", "name": "g/mol"}, + {"label": "lbm/lbmol", "name": "lbm/lbmol"}, + ], + }, + { + "name": "mediumresistance", + "label": "Medium Resistance", + "units": [ + {"label": "m-1", "name": "m-1"}, + {"label": "cm-1", "name": "cm-1"}, + {"label": "ft-1", "name": "ft-1"}, + ], + }, + { + "name": "heat_transf_coeff", + "label": "Heat Transfer Coefficient", + "units": [ + {"label": "W/[m2.K]", "name": "W/[m2.K]"}, + {"label": "cal/[cm2.s.C]", "name": "cal/[cm2.s.C]"}, + {"label": "BTU/[ft2.h.R]", "name": "BTU/[ft2.h.R]"}, + ], + }, + { + "name": "reac_rate_heterog", + "label": "Reaction Rate Heterogeneous", + "units": [ + {"label": "kmol/[kg.s]", "name": "kmol/[kg.s]"}, + {"label": "kmol/[kg.min.]", "name": "kmol/[kg.min.]"}, + {"label": "kmol/[kg.h]", "name": "kmol/[kg.h]"}, + {"label": "mol/[kg.s]", "name": "mol/[kg.s]"}, + {"label": "mol/[kg.min.]", "name": "mol/[kg.min.]"}, + {"label": "mol/[kg.h]", "name": "mol/[kg.h]"}, + {"label": "lbmol/[lbm.h]", "name": "lbmol/[lbm.h]"}, + ], + }, + { + "name": "cinematic_viscosity", + "label": "Kinematic Viscosity", + "units": [ + {"label": "m2/s", "name": "m2/s"}, + {"label": "cSt", "name": "cSt"}, + {"label": "ft2/s", "name": "ft2/s"}, + {"label": "mm2/s", "name": "mm2/s"}, + {"label": "cm2/s", "name": "cm2/s"}, + ], + }, + { + "name": "thermalConductivity", + "label": "Thermal Conductivity", + "units": [ + {"label": "W/[m.K]", "name": "W/[m.K]"}, + {"label": "cal/[cm.s.C]", "name": "cal/[cm.s.C]"}, + {"label": "BTU/[ft.h.R]", "name": "BTU/[ft.h.R]"}, + ], + }, + { + "name": "jouleThomsonCoefficient", + "label": "Joule Thomson Coefficient", + "units": [ + {"label": "K/Pa", "name": "K/Pa"}, + {"label": "F/psi", "name": "F/psi"}, + {"label": "C/atm", "name": "C/atm"}, + ], + }, + ], +} + + +simulator_integration = { + "externalId": "integration_tests_workflow_connector", + "simulatorExternalId": "integration_tests_workflow", + "heartbeat": 1706396950969, + "dataSetId": 97552494921583, + "connectorVersion": "1.0.0", + "simulatorVersion": "1.0.0", + "licenseStatus": "AVAILABLE", + "licenseLastCheckedTime": 0, + "connectorStatus": "IDLE", + "connectorStatusUpdatedTime": 0, +} + + +simulator_model = { + "externalId": "integration_tests_workflow_model", + "simulatorExternalId": "integration_tests_workflow", + "name": "Test Simulator Model", + "description": "Test Simulator Model Desc", + "dataSetId": 97552494921583, + "labels": [{"externalId": "simconfig-labels-PROSPER"}], + "type": "SteadyState", +} + +simulator_model_revision = { + "externalId": "integration_tests_workflow_model_revision", + "modelExternalId": "integration_tests_workflow_model", + "description": "test sim model revision description", + "fileId": 00000000000000, +} + +simulator_routine = { + "externalId": "integration_tests_workflow_routine", + "modelExternalId": "integration_tests_workflow_model", + "simulatorIntegrationExternalId": "integration_tests_workflow_connector", + "name": "Routine test", + "description": "test", +} + +simulator_routine_revision = { + "externalId": "integration_tests_workflow_routine_revision", + "routineExternalId": "integration_tests_workflow_routine", + "configuration": { + "schedule": {"enabled": True, "cronExpression": "*/10 * * * *"}, + "dataSampling": {"enabled": True, "validationWindow": None, "samplingWindow": 15, "granularity": 1}, + "logicalCheck": [], + "steadyStateDetection": [], + "inputs": [ + { + "name": "Cold Water Temperature - Constant", + "referenceId": "CWTC", + "value": 10, + "valueType": "DOUBLE", + "unit": {"name": "C", "quantity": "temperature"}, + "saveTimeseriesExternalId": "DWSIM-INPUT-constinput-CWTC-ShowerMixer-AI", + }, + { + "name": "Cold Water Pressure - Constant", + "referenceId": "CWPC", + "value": 3.6, + "valueType": "DOUBLE", + "unit": {"name": "bar", "quantity": "pressure"}, + "saveTimeseriesExternalId": "DWSIM-INPUT-constinput-CWPC-ShowerMixer", + }, + { + "name": "Cold Water Volumetric Flow - Constant", + "referenceId": "CWVFC", + "value": 0.37, + "valueType": "DOUBLE", + "unit": {"name": "m3/h", "quantity": "volumetricFlow"}, + "saveTimeseriesExternalId": "DWSIM-INPUT-constinput-CWVFC-ShowerMixer-AI", + }, + { + "name": "Hot Water Temperature - Constant", + "referenceId": "HWTC", + "value": 69, + "valueType": "DOUBLE", + "unit": {"name": "C", "quantity": "temperature"}, + "saveTimeseriesExternalId": "DWSIM-INPUT-constinput-HWTC-ShowerMixer-AI", + }, + { + "name": "Hot Water Pressure - Constant", + "referenceId": "HWPC", + "value": 2.8, + "valueType": "DOUBLE", + "unit": {"name": "bar", "quantity": "pressure"}, + "saveTimeseriesExternalId": "DWSIM-INPUT-constinput-HWPC-ShowerMixer-AI", + }, + { + "name": "Hot Water Volumetric Flow - Constant", + "referenceId": "HWVFC", + "value": 0.19, + "valueType": "DOUBLE", + "unit": {"name": "m3/h", "quantity": "volumetricFlow"}, + "saveTimeseriesExternalId": "DWSIM-INPUT-constinput-HWVFC-ShowerMixer-AI", + }, + ], + "outputs": [ + { + "name": "Shower Temperature", + "referenceId": "ST", + "unit": {"name": "C", "quantity": "temperature"}, + "valueType": "DOUBLE", + "saveTimeseriesExternalId": "DWSIM-OUTPUT-const_input-ST-ShowerMixer-AI", + }, + { + "name": "Shower Pressure", + "referenceId": "SP", + "unit": {"name": "bar", "quantity": "pressure"}, + "valueType": "DOUBLE", + "saveTimeseriesExternalId": "DWSIM-OUTPUT-const_input-SP-ShowerMixer-AI", + }, + { + "name": "Shower Volumetric Flow", + "referenceId": "SVF", + "unit": {"name": "m3/h", "quantity": "volumetricFlow"}, + "valueType": "DOUBLE", + "saveTimeseriesExternalId": "DWSIM-OUTPUT-const_input-SVF-ShowerMixer-AI", + }, + ], + }, + "script": [ + { + "order": 1, + "description": "Set Inputs", + "steps": [ + { + "order": 1, + "stepType": "Set", + "arguments": {"referenceId": "CWTC", "objectName": "Cold water", "objectProperty": "Temperature"}, + }, + { + "order": 2, + "stepType": "Set", + "arguments": {"referenceId": "CWPC", "objectName": "Cold water", "objectProperty": "Pressure"}, + }, + { + "order": 3, + "stepType": "Set", + "arguments": { + "referenceId": "CWVFC", + "objectName": "Cold water", + "objectProperty": "Volumetric Flow", + }, + }, + { + "order": 4, + "stepType": "Set", + "arguments": {"referenceId": "HWTC", "objectName": "Hot water", "objectProperty": "Temperature"}, + }, + { + "order": 5, + "stepType": "Set", + "arguments": {"referenceId": "HWPC", "objectName": "Hot water", "objectProperty": "Pressure"}, + }, + { + "order": 6, + "stepType": "Set", + "arguments": { + "referenceId": "HWVFC", + "objectName": "Hot water", + "objectProperty": "Volumetric Flow", + }, + }, + ], + }, + { + "order": 2, + "description": "Solve the flowsheet", + "steps": [{"order": 1, "stepType": "Command", "arguments": {"command": "Solve"}}], + }, + { + "order": 3, + "description": "Set simulation outputs", + "steps": [ + { + "order": 1, + "stepType": "Get", + "arguments": {"referenceId": "ST", "objectName": "Shower", "objectProperty": "Temperature"}, + }, + { + "order": 2, + "stepType": "Get", + "arguments": {"referenceId": "SP", "objectName": "Shower", "objectProperty": "Pressure"}, + }, + { + "order": 3, + "stepType": "Get", + "arguments": {"referenceId": "SVF", "objectName": "Shower", "objectProperty": "Volumetric Flow"}, + }, + ], + }, + ], +} diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 48ff2edcd..87d789cfd 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -1,5 +1,63 @@ +import pytest + from cognite.client import CogniteClient from cognite.client.data_classes.simulators.filters import SimulatorIntegrationFilter +from tests.tests_integration.test_api.test_simulators.seed.data import ( + simulator, + simulator_integration, + simulator_model, + simulator_model_revision, + simulator_routine, + simulator_routine_revision, +) + + +@pytest.fixture +def add_simulator_resoures(cognite_client: CogniteClient) -> None: + simulator_external_id = "integration_tests_workflow" + simulator_model_file_external_id = "ShowerMixer_simulator_model_file" + + file = cognite_client.files.upload( + path="tests/tests_integration/test_api/test_simulators/seed/data/ShowerMixer.dwxmz", + external_id=simulator_model_file_external_id, + name="ShowerMixer.dwxmz", + data_set_id=97552494921583, + ) + + resources = [ + {"url": f"/api/v1/projects/{cognite_client.config.project}/simulators", "seed": simulator}, + { + "url": f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations", + "seed": simulator_integration, + }, + {"url": f"/api/v1/projects/{cognite_client.config.project}/simulators/models", "seed": simulator_model}, + { + "url": f"/api/v1/projects/{cognite_client.config.project}/simulators/models/revisions", + "seed": {**simulator_model_revision, "fileId": file.id}, + }, + {"url": f"/api/v1/projects/{cognite_client.config.project}/simulators/routines", "seed": simulator_routine}, + { + "url": f"/api/v1/projects/{cognite_client.config.project}/simulators/routines/revisions", + "seed": simulator_routine_revision, + }, + ] + + for resource in resources: + cognite_client.post( + resource["url"], + json={"items": [resource["seed"]]}, + headers={"cdf-version": "alpha"}, + ) + + yield None + + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", + json={"items": [{"externalId": simulator_external_id}]}, + headers={"cdf-version": "alpha"}, + ) + + cognite_client.files.delete(external_id=simulator_model_file_external_id) class TestSimulators: @@ -14,16 +72,16 @@ class TestSimulatorIntegrations: # test filter # test retrieve def test_list_integrations(self, cognite_client: CogniteClient) -> None: - integrations = cognite_client.simulators.list_integrations(limit=5) + integrations = cognite_client.simulators.integrations.list(limit=5) assert len(integrations) > 0 def test_filter_integrations(self, cognite_client: CogniteClient) -> None: - all_integrations = cognite_client.simulators.list_integrations() - active_integrations = cognite_client.simulators.list_integrations( + all_integrations = cognite_client.simulators.integrations.list() + active_integrations = cognite_client.simulators.integrations.list( filter=SimulatorIntegrationFilter(active=True) ) - dwsim_integrations = cognite_client.simulators.list_integrations( + dwsim_integrations = cognite_client.simulators.integrations.list( filter=SimulatorIntegrationFilter(simulator_external_ids=["DWSIM"]) ) @@ -35,42 +93,42 @@ def test_filter_integrations(self, cognite_client: CogniteClient) -> None: class TestSimulatorModels: def test_list_models(self, cognite_client: CogniteClient) -> None: - models = cognite_client.simulators.list_models(limit=5) + models = cognite_client.simulators.models.list(limit=5) assert len(models) > 0 def test_retrieve_model(self, cognite_client: CogniteClient) -> None: - model = cognite_client.simulators.retrieve_model(external_id="TEST_WORKFLOWS_SIMINT_INTEGRATION_MODEL") + model = cognite_client.simulators.models.retrieve(external_id="TEST_WORKFLOWS_SIMINT_INTEGRATION_MODEL") assert model is not None assert model.external_id == "TEST_WORKFLOWS_SIMINT_INTEGRATION_MODEL" def test_list_model_revisions(self, cognite_client: CogniteClient) -> None: - revisions = cognite_client.simulators.list_model_revisions(limit=5) + revisions = cognite_client.simulators.models.list_revisions(limit=5) assert len(revisions) > 0 def test_retrieve_model_revision(self, cognite_client: CogniteClient) -> None: - model = cognite_client.simulators.retrieve_model_revision(external_id="Shower_mixer-1") + model = cognite_client.simulators.models.retrieve_revision(external_id="Shower_mixer-1") assert model is not None assert model.external_id == "Shower_mixer-1" class TestSimulatorRoutines: def test_list_routines(self, cognite_client: CogniteClient) -> None: - routines = cognite_client.simulators.list_routines(limit=5) + routines = cognite_client.simulators.routines.list(limit=5) assert len(routines) > 0 def test_list_routine_revisions(self, cognite_client: CogniteClient) -> None: - revisions = cognite_client.simulators.list_routine_revisions(limit=5) + revisions = cognite_client.simulators.routines.list_revisions(limit=5) assert revisions[0].configuration is not None assert revisions[0].script is not None assert len(revisions) > 0 def test_retrieve_routine_revision(self, cognite_client: CogniteClient) -> None: - revision = cognite_client.simulators.retrieve_routine_revision(external_id="ShowerMixerForTests-1") + revision = cognite_client.simulators.routines.retrieve_revision(external_id="ShowerMixerForTests-1") assert revision is not None assert revision.external_id == "ShowerMixerForTests-1" class TestSimulationRuns: def test_list_runs(self, cognite_client: CogniteClient) -> None: - routines = cognite_client.simulators.list_runs(limit=5) + routines = cognite_client.simulators.runs.list(limit=5) assert len(routines) > 0 From 4061ed29311b898ca005353427f9e230f4140a33 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Thu, 7 Nov 2024 00:15:26 +0100 Subject: [PATCH 015/122] retrieve byids --- cognite/client/_api/simulators/__init__.py | 23 ---------------------- 1 file changed, 23 deletions(-) diff --git a/cognite/client/_api/simulators/__init__.py b/cognite/client/_api/simulators/__init__.py index 02c835809..e69de29bb 100644 --- a/cognite/client/_api/simulators/__init__.py +++ b/cognite/client/_api/simulators/__init__.py @@ -1,23 +0,0 @@ -<<<<<<< HEAD -from __future__ import annotations - -from typing import TYPE_CHECKING - -from cognite.client._api.simulators.simulation_runs import SimulatorRunsAPI -from cognite.client._api.simulators.simulator_integrations import SimulatorIntegrationsAPI -from cognite.client._api.simulators.simulator_models import SimulatorModelsAPI -from cognite.client._api.simulators.simulator_routines import SimulatorRoutinesAPI -from cognite.client._api.simulators.simulators import SimulatorsResourceAPI - -if TYPE_CHECKING: - from cognite.client import CogniteClient - from cognite.client.config import ClientConfig - - -class SimulatorsAPI( - SimulatorsResourceAPI, SimulatorIntegrationsAPI, SimulatorModelsAPI, SimulatorRoutinesAPI, SimulatorRunsAPI -): - def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: - super().__init__(config, api_version, cognite_client) -======= ->>>>>>> a7c607cf (retrieve byids) From 7de05818b7ff37aca1a8ae0ca9c9c31387a8164d Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Thu, 21 Nov 2024 10:57:42 +0100 Subject: [PATCH 016/122] fix ci --- cognite/client/_cognite_client.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cognite/client/_cognite_client.py b/cognite/client/_cognite_client.py index 634963e9d..f9eb2e2da 100644 --- a/cognite/client/_cognite_client.py +++ b/cognite/client/_cognite_client.py @@ -24,6 +24,10 @@ from cognite.client._api.relationships import RelationshipsAPI from cognite.client._api.sequences import SequencesAPI from cognite.client._api.simulators.simulators import SimulatorsAPI +from cognite.client._api.simulators.simulation_runs import SimulatorRunsAPI +from cognite.client._api.simulators.simulator_integrations import SimulatorIntegrationsAPI +from cognite.client._api.simulators.simulator_models import SimulatorModelsAPI +from cognite.client._api.simulators.simulator_routines import SimulatorRoutinesAPI from cognite.client._api.templates import TemplatesAPI from cognite.client._api.three_d import ThreeDAPI from cognite.client._api.time_series import TimeSeriesAPI @@ -85,6 +89,10 @@ def __init__(self, config: ClientConfig | None = None) -> None: self.workflows = WorkflowAPI(self._config, self._API_VERSION, self) self.units = UnitAPI(self._config, self._API_VERSION, self) self.simulators = SimulatorsAPI(self._config, self._API_VERSION, self) + self.simulators.models = SimulatorModelsAPI(self._config, self._API_VERSION, self) + self.simulators.runs = SimulatorRunsAPI(self._config, self._API_VERSION, self) + self.simulators.integrations = SimulatorIntegrationsAPI(self._config, self._API_VERSION, self) + self.simulators.routines = SimulatorRoutinesAPI(self._config, self._API_VERSION, self) # APIs just using base_url: self._api_client = APIClient(self._config, api_version=None, cognite_client=self) From bd058e476ec4ae13942dfe8b567fa7db1b6018cb Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Thu, 21 Nov 2024 10:59:58 +0100 Subject: [PATCH 017/122] lint --- cognite/client/_cognite_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_cognite_client.py b/cognite/client/_cognite_client.py index f9eb2e2da..aa0f3e81e 100644 --- a/cognite/client/_cognite_client.py +++ b/cognite/client/_cognite_client.py @@ -23,11 +23,11 @@ from cognite.client._api.raw import RawAPI from cognite.client._api.relationships import RelationshipsAPI from cognite.client._api.sequences import SequencesAPI -from cognite.client._api.simulators.simulators import SimulatorsAPI from cognite.client._api.simulators.simulation_runs import SimulatorRunsAPI from cognite.client._api.simulators.simulator_integrations import SimulatorIntegrationsAPI from cognite.client._api.simulators.simulator_models import SimulatorModelsAPI from cognite.client._api.simulators.simulator_routines import SimulatorRoutinesAPI +from cognite.client._api.simulators.simulators import SimulatorsAPI from cognite.client._api.templates import TemplatesAPI from cognite.client._api.three_d import ThreeDAPI from cognite.client._api.time_series import TimeSeriesAPI From 0fd679d41ba2090ace3f2f69595f68e3904d7052 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Sun, 24 Nov 2024 19:34:48 +0100 Subject: [PATCH 018/122] simulator resource - writable --- .../data_classes/simulators/simulators.py | 99 ++++++++++++++++--- 1 file changed, 85 insertions(+), 14 deletions(-) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index dce03b2a5..13014f60d 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -1,5 +1,6 @@ from __future__ import annotations +from abc import ABC from collections.abc import Sequence from dataclasses import dataclass from typing import TYPE_CHECKING, Any @@ -10,6 +11,10 @@ CogniteObject, CogniteResource, CogniteResourceList, + ExternalIDTransformerMixin, + IdTransformerMixin, + WriteableCogniteResource, + WriteableCogniteResourceList, ) from cognite.client.utils.useful_types import SequenceNotStr @@ -421,7 +426,7 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return output -class Simulator(CogniteResource): +class SimulatorCore(WriteableCogniteResource["SimulatorWrite"], ABC): """The simulator resource contains the definitions necessary for Cognite Data Fusion (CDF) to interact with a given simulator. It serves as a central contract that allows APIs, UIs, and integrations (connectors) to utilize the same definitions @@ -433,12 +438,9 @@ class Simulator(CogniteResource): This is the read/response format of the simulator. Args: - id (int): A unique id of a simulator external_id (str): External id of the simulator name (str): Name of the simulator file_extension_types (str | SequenceNotStr[str]): File extension types supported by the simulator - created_time (int): None - last_updated_time (int): None model_types (SimulatorModelType | Sequence[SimulatorModelType] | None): Model types supported by the simulator step_fields (SimulatorStep | Sequence[SimulatorStep] | None): Step types supported by the simulator when creating routines unit_quantities (SimulatorQuantity | Sequence[SimulatorQuantity] | None): Quantities and their units supported by the simulator @@ -447,12 +449,9 @@ class Simulator(CogniteResource): def __init__( self, - id: int, external_id: str, name: str, file_extension_types: str | SequenceNotStr[str], - created_time: int, - last_updated_time: int, model_types: SimulatorModelType | Sequence[SimulatorModelType] | None = None, step_fields: SimulatorStep | Sequence[SimulatorStep] | None = None, unit_quantities: SimulatorQuantity | Sequence[SimulatorQuantity] | None = None, @@ -463,19 +462,13 @@ def __init__( self.model_types = model_types self.step_fields = step_fields self.unit_quantities = unit_quantities - self.id = id - self.created_time = created_time - self.last_updated_time = last_updated_time @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: return cls( - id=resource["id"], external_id=resource["externalId"], name=resource["name"], file_extension_types=resource["fileExtensionTypes"], - created_time=resource["createdTime"], - last_updated_time=resource["lastUpdatedTime"], model_types=SimulatorModelType._load_list(resource["modelTypes"], cognite_client) if "modelTypes" in resource else None, @@ -501,6 +494,77 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return output +class SimulatorWrite(SimulatorCore): + def __init__( + self, + external_id: str, + name: str, + file_extension_types: str | SequenceNotStr[str], + model_types: SimulatorModelType | Sequence[SimulatorModelType] | None = None, + step_fields: SimulatorStep | Sequence[SimulatorStep] | None = None, + unit_quantities: SimulatorQuantity | Sequence[SimulatorQuantity] | None = None, + ) -> None: + super().__init__( + external_id=external_id, + name=name, + file_extension_types=file_extension_types, + model_types=model_types, + step_fields=step_fields, + unit_quantities=unit_quantities, + ) + + def as_write(self) -> SimulatorWrite: + """Returns a writeable version of this resource""" + return self + + +class Simulator(SimulatorCore): + def __init__( + self, + external_id: str, + name: str, + file_extension_types: str | SequenceNotStr[str], + created_time: int | None = None, + last_updated_time: int | None = None, + id: int | None = None, + model_types: SimulatorModelType | Sequence[SimulatorModelType] | None = None, + step_fields: SimulatorStep | Sequence[SimulatorStep] | None = None, + unit_quantities: SimulatorQuantity | Sequence[SimulatorQuantity] | None = None, + ) -> None: + self.external_id = external_id + self.name = name + self.file_extension_types = file_extension_types + self.model_types = model_types + self.step_fields = step_fields + self.unit_quantities = unit_quantities + # id/created_time/last_updated_time are required when using the class to read, + # but don't make sense passing in when creating a new object. So in order to make the typing + # correct here (i.e. int and not Optional[int]), we force the type to be int rather than + # Optional[int]. + self.id: int | None = id + self.created_time: int | None = created_time + self.last_updated_time: int | None = last_updated_time + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + instance = super()._load(resource, cognite_client) + return instance + + def as_write(self) -> SimulatorWrite: + """Returns a writeable version of this resource""" + return SimulatorWrite( + external_id=self.external_id, + name=self.name, + file_extension_types=self.file_extension_types, + model_types=self.model_types, + step_fields=self.step_fields, + unit_quantities=self.unit_quantities, + ) + + def __hash__(self) -> int: + return hash(self.external_id) + + class SimulatorIntegration(CogniteResource): """ The simulator integration resource represents a simulator connector in Cognite Data Fusion (CDF). @@ -959,9 +1023,16 @@ class SimulatorRoutineRevisionsList(CogniteResourceList[SimulatorRoutineRevision _RESOURCE = SimulatorRoutineRevision -class SimulatorList(CogniteResourceList[Simulator]): +class SimulatorWriteList(CogniteResourceList[SimulatorWrite], ExternalIDTransformerMixin): + _RESOURCE = SimulatorWrite + + +class SimulatorList(WriteableCogniteResourceList[SimulatorWrite, Simulator], IdTransformerMixin): _RESOURCE = Simulator + def as_write(self) -> SimulatorWriteList: + return SimulatorWriteList([a.as_write() for a in self.data], cognite_client=self._get_cognite_client()) + class SimulatorIntegrationList(CogniteResourceList[SimulatorIntegration]): _RESOURCE = SimulatorIntegration From 76d3c5164d9f6168087dcc6ffc9fc514070a3538 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Sun, 24 Nov 2024 19:57:06 +0100 Subject: [PATCH 019/122] simulator integration resource - writeable --- .../data_classes/simulators/simulators.py | 130 +++++++++++++++--- 1 file changed, 108 insertions(+), 22 deletions(-) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 13014f60d..c70c51a08 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -565,7 +565,7 @@ def __hash__(self) -> int: return hash(self.external_id) -class SimulatorIntegration(CogniteResource): +class SimulatorIntegrationCore(WriteableCogniteResource["SimulatorIntegrationWrite"], ABC): """ The simulator integration resource represents a simulator connector in Cognite Data Fusion (CDF). It provides information about the configured connectors for a given simulator, including their status and additional @@ -578,16 +578,11 @@ class SimulatorIntegration(CogniteResource): Args: - id (int): A unique id of a simulator integration external_id (str): External id of the simulator integration simulator_external_id (str): External id of the associated simulator heartbeat (int): The interval in seconds between the last heartbeat and the current time - active (bool): Whether the simulator integration is active data_set_id (int): The id of the dataset associated with the simulator integration connector_version (str): The version of the connector - log_id (int): The id of the log associated with the simulator integration - created_time (int): The time when the simulator integration was created - last_updated_time (int): The time when the simulator integration was last updated license_status (str | None): The status of the license simulator_version (str | None): The version of the simulator license_last_checked_time (int | None): The time when the license was last checked @@ -598,32 +593,22 @@ class SimulatorIntegration(CogniteResource): def __init__( self, - id: int, external_id: str, simulator_external_id: str, heartbeat: int, - active: bool, data_set_id: int, connector_version: str, - log_id: int, - created_time: int, - last_updated_time: int, license_status: str | None = None, simulator_version: str | None = None, license_last_checked_time: int | None = None, connector_status: str | None = None, connector_status_updated_time: int | None = None, ) -> None: - self.id = id self.external_id = external_id self.simulator_external_id = simulator_external_id self.heartbeat = heartbeat - self.active = active self.data_set_id = data_set_id self.connector_version = connector_version - self.log_id = log_id - self.created_time = created_time - self.last_updated_time = last_updated_time self.license_status = license_status self.simulator_version = simulator_version self.license_last_checked_time = license_last_checked_time @@ -633,16 +618,11 @@ def __init__( @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: return cls( - id=resource["id"], external_id=resource["externalId"], simulator_external_id=resource["simulatorExternalId"], heartbeat=resource["heartbeat"], - active=resource["active"], data_set_id=resource["dataSetId"], connector_version=resource["connectorVersion"], - log_id=resource["logId"], - created_time=resource["createdTime"], - last_updated_time=resource["lastUpdatedTime"], license_status=resource.get("licenseStatus"), simulator_version=resource.get("simulatorVersion"), license_last_checked_time=resource.get("licenseLastCheckedTime"), @@ -654,6 +634,101 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) +class SimulatorIntegrationWrite(SimulatorIntegrationCore): + def __init__( + self, + external_id: str, + simulator_external_id: str, + heartbeat: int, + data_set_id: int, + connector_version: str, + license_status: str | None = None, + simulator_version: str | None = None, + license_last_checked_time: int | None = None, + connector_status: str | None = None, + connector_status_updated_time: int | None = None, + ) -> None: + super().__init__( + external_id=external_id, + simulator_external_id=simulator_external_id, + heartbeat=heartbeat, + data_set_id=data_set_id, + connector_version=connector_version, + license_status=license_status, + simulator_version=simulator_version, + license_last_checked_time=license_last_checked_time, + connector_status=connector_status, + connector_status_updated_time=connector_status_updated_time, + ) + + def as_write(self) -> SimulatorIntegrationWrite: + """Returns a writeable version of this resource""" + return self + + +class SimulatorIntegration(SimulatorIntegrationCore): + def __init__( + self, + external_id: str, + simulator_external_id: str, + heartbeat: int, + data_set_id: int, + connector_version: str, + license_status: str | None = None, + simulator_version: str | None = None, + license_last_checked_time: int | None = None, + connector_status: str | None = None, + connector_status_updated_time: int | None = None, + created_time: int | None = None, + last_updated_time: int | None = None, + id: int | None = None, + active: bool | None = None, + log_id: int | None = None, + ) -> None: + self.external_id = external_id + self.simulator_external_id = simulator_external_id + self.heartbeat = heartbeat + self.data_set_id = data_set_id + self.connector_version = connector_version + self.license_status = license_status + self.simulator_version = simulator_version + self.license_last_checked_time = license_last_checked_time + self.connector_status = connector_status + self.connector_status_updated_time = connector_status_updated_time + # id/created_time/last_updated_time are required when using the class to read, + # but don't make sense passing in when creating a new object. So in order to make the typing + # correct here (i.e. int and not Optional[int]), we force the type to be int rather than + # Optional[int]. + self.id: int | None = id + self.created_time: int | None = created_time + self.last_updated_time: int | None = last_updated_time + self.active = active + self.log_id = log_id + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + instance = super()._load(resource, cognite_client) + return instance + + def as_write(self) -> SimulatorIntegrationWrite: + """Returns a writeable version of this resource""" + return SimulatorIntegrationWrite( + external_id=self.external_id, + simulator_external_id=self.simulator_external_id, + heartbeat=self.heartbeat, + data_set_id=self.data_set_id, + connector_version=self.connector_version, + license_status=self.license_status, + simulator_version=self.simulator_version, + license_last_checked_time=self.license_last_checked_time, + connector_status=self.connector_status, + connector_status_updated_time=self.connector_status_updated_time, + ) + + def __hash__(self) -> int: + return hash(self.external_id) + + class SimulatorModelRevision(CogniteResource): def __init__( self, @@ -1034,9 +1109,20 @@ def as_write(self) -> SimulatorWriteList: return SimulatorWriteList([a.as_write() for a in self.data], cognite_client=self._get_cognite_client()) -class SimulatorIntegrationList(CogniteResourceList[SimulatorIntegration]): +class SimulatorIntegrationWriteList(CogniteResourceList[SimulatorIntegrationWrite], ExternalIDTransformerMixin): + _RESOURCE = SimulatorIntegrationWrite + + +class SimulatorIntegrationList( + WriteableCogniteResourceList[SimulatorIntegrationWrite, SimulatorIntegration], IdTransformerMixin +): _RESOURCE = SimulatorIntegration + def as_write(self) -> SimulatorIntegrationWriteList: + return SimulatorIntegrationWriteList( + [a.as_write() for a in self.data], cognite_client=self._get_cognite_client() + ) + class SimulatorModelList(CogniteResourceList[SimulatorModel]): _RESOURCE = SimulatorModel From a70bab1f38194240d901b2382f9b81c32d6b7336 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Wed, 27 Nov 2024 14:35:06 +0100 Subject: [PATCH 020/122] fix API maturity level --- .../client/_api/simulators/simulation_runs.py | 4 +- .../_api/simulators/simulator_integrations.py | 4 +- .../_api/simulators/simulator_models.py | 4 +- .../_api/simulators/simulator_routines.py | 4 +- cognite/client/_api/simulators/simulators.py | 4 +- .../data_classes/simulators/simulators.py | 221 +++++++++++++++--- 6 files changed, 208 insertions(+), 33 deletions(-) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py index df6b0e0cd..2340b378c 100644 --- a/cognite/client/_api/simulators/simulation_runs.py +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -17,7 +17,9 @@ class SimulatorRunsAPI(APIClient): def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: super().__init__(config, api_version, cognite_client) - self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") + self._warning = FeaturePreviewWarning( + api_maturity="General Availability", sdk_maturity="alpha", feature_name="Simulators" + ) def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulationRunsFilter | dict[str, Any] | None = None diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index e329791d4..136a236ba 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -20,7 +20,9 @@ class SimulatorIntegrationsAPI(APIClient): def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: super().__init__(config, api_version, cognite_client) - self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") + self._warning = FeaturePreviewWarning( + api_maturity="General Availability", sdk_maturity="alpha", feature_name="Simulators" + ) def list( self, diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 7d14adb3f..203242cb2 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -23,7 +23,9 @@ class SimulatorModelsAPI(APIClient): def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: super().__init__(config, api_version, cognite_client) - self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") + self._warning = FeaturePreviewWarning( + api_maturity="General Availability", sdk_maturity="alpha", feature_name="Simulators" + ) def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelsFilter | dict[str, Any] | None = None diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 148a21853..c13559572 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -23,7 +23,9 @@ class SimulatorRoutinesAPI(APIClient): def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: super().__init__(config, api_version, cognite_client) - self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") + self._warning = FeaturePreviewWarning( + api_maturity="General Availability", sdk_maturity="alpha", feature_name="Simulators" + ) def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutinesFilter | dict[str, Any] | None = None diff --git a/cognite/client/_api/simulators/simulators.py b/cognite/client/_api/simulators/simulators.py index 3b77a57d0..ba93e1b3d 100644 --- a/cognite/client/_api/simulators/simulators.py +++ b/cognite/client/_api/simulators/simulators.py @@ -28,7 +28,9 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client self.runs = SimulatorRunsAPI(config, api_version, cognite_client) self.integrations = SimulatorIntegrationsAPI(config, api_version, cognite_client) self.routines = SimulatorRoutinesAPI(config, api_version, cognite_client) - self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators") + self._warning = FeaturePreviewWarning( + api_maturity="General Availability", sdk_maturity="alpha", feature_name="Simulators" + ) def list(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorList: """`Filter Simulators `_ diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index c70c51a08..82a9399ae 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -785,32 +785,24 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) -class SimulatorRoutineRevision(CogniteResource): +class SimulatorRoutineRevisionCore(WriteableCogniteResource["SimulatorRoutineRevisionWrite"], ABC): def __init__( self, - id: int, external_id: str, simulator_external_id: str, routine_external_id: str, simulator_integration_external_id: str, model_external_id: str, data_set_id: int, - created_by_user_id: str, - version_number: int, - created_time: int, configuration: SimulatorRoutineConfiguration, script: list[SimulatorRoutineStage], ) -> None: - self.id = id self.external_id = external_id self.simulator_external_id = simulator_external_id self.routine_external_id = routine_external_id self.simulator_integration_external_id = simulator_integration_external_id self.model_external_id = model_external_id self.data_set_id = data_set_id - self.created_by_user_id = created_by_user_id - self.version_number = version_number - self.created_time = created_time self.configuration = configuration self.script = script @@ -821,16 +813,12 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = if resource.get("script", None) is not None: script = [SimulatorRoutineStage._load(stage_, cognite_client) for stage_ in resource["script"]] return cls( - id=resource["id"], external_id=resource["externalId"], simulator_external_id=resource["simulatorExternalId"], routine_external_id=resource["routineExternalId"], simulator_integration_external_id=resource["simulatorIntegrationExternalId"], model_external_id=resource["modelExternalId"], data_set_id=resource["dataSetId"], - created_by_user_id=resource["createdByUserId"], - version_number=resource["versionNumber"], - created_time=resource["createdTime"], configuration=SimulatorRoutineConfiguration._load(resource["configuration"], cognite_client), script=script, ) @@ -843,6 +831,91 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return output +class SimulatorRoutineRevisionWrite(SimulatorRoutineRevisionCore): + def __init__( + self, + external_id: str, + simulator_external_id: str, + routine_external_id: str, + simulator_integration_external_id: str, + model_external_id: str, + data_set_id: int, + configuration: SimulatorRoutineConfiguration, + script: list[SimulatorRoutineStage], + ) -> None: + super().__init__( + external_id=external_id, + simulator_external_id=simulator_external_id, + routine_external_id=routine_external_id, + simulator_integration_external_id=simulator_integration_external_id, + model_external_id=model_external_id, + data_set_id=data_set_id, + configuration=configuration, + script=script, + ) + + def as_write(self) -> SimulatorRoutineRevisionWrite: + """Returns a writeable version of this resource""" + return self + + +class SimulatorRoutineRevision(SimulatorRoutineRevisionCore): + def __init__( + self, + external_id: str, + simulator_external_id: str, + routine_external_id: str, + simulator_integration_external_id: str, + model_external_id: str, + data_set_id: int, + configuration: SimulatorRoutineConfiguration, + script: list[SimulatorRoutineStage], + id: int | None = None, + created_by_user_id: str | None = None, + last_updated_time: int | None = None, + version_number: int | None = None, + created_time: int | None = None, + log_id: int | None = None, + ) -> None: + self.external_id = external_id + self.simulator_external_id = simulator_external_id + self.routine_external_id = routine_external_id + self.simulator_integration_external_id = simulator_integration_external_id + self.model_external_id = model_external_id + self.data_set_id = data_set_id + self.created_by_user_id = created_by_user_id + self.configuration = configuration + self.script = script + + # id/created_time/last_updated_time are required when using the class to read, + # but don't make sense passing in when creating a new object. So in order to make the typing + # correct here (i.e. int and not Optional[int]), we force the type to be int rather than + # Optional[int]. + self.id: int | None = id + self.created_time: int | None = created_time + self.last_updated_time: int | None = last_updated_time + self.version_number = version_number + self.log_id = log_id + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + instance = super()._load(resource, cognite_client) + return instance + + def as_write(self) -> SimulatorRoutineRevisionWrite: + """Returns a writeable version of this resource""" + return SimulatorRoutineRevisionWrite( + external_id=self.external_id, + simulator_external_id=self.simulator_external_id, + routine_external_id=self.routine_external_id, + simulator_integration_external_id=self.simulator_integration_external_id, + model_external_id=self.model_external_id, + data_set_id=self.data_set_id, + configuration=self.configuration, + script=self.script, + ) + + class SimulatorModel(CogniteResource): """ The simulator model resource represents an asset modeled in a simulator. @@ -1015,7 +1088,7 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) -class SimulatorRoutine(CogniteResource): +class SimulatorRoutineCore(WriteableCogniteResource["SimulatorRoutineWrite"], ABC): """ The simulator routine resource defines instructions on interacting with a simulator model. A simulator routine includes: @@ -1035,54 +1108,42 @@ class SimulatorRoutine(CogniteResource): This is the read/response format of a simulator routine. Args: - id (int): A unique id of a simulator routine external_id (str): External id of the simulator routine simulator_external_id (str): External id of the associated simulator model_external_id (str): External id of the associated simulator model simulator_integration_external_id (str): External id of the associated simulator integration name (str): The name of the simulator routine data_set_id (int): The id of the dataset associated with the simulator routine - created_time (int): The time when the simulator routine was created - last_updated_time (int): The time when the simulator routine was last updated description (str | None): The description of the simulator routine """ def __init__( self, - id: int, external_id: str, simulator_external_id: str, model_external_id: str, simulator_integration_external_id: str, name: str, data_set_id: int, - created_time: int, - last_updated_time: int, description: str | None = None, ) -> None: - self.id = id self.external_id = external_id self.simulator_external_id = simulator_external_id self.model_external_id = model_external_id self.simulator_integration_external_id = simulator_integration_external_id self.name = name self.data_set_id = data_set_id - self.created_time = created_time - self.last_updated_time = last_updated_time self.description = description @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: return cls( - id=resource["id"], external_id=resource["externalId"], simulator_external_id=resource["simulatorExternalId"], model_external_id=resource["modelExternalId"], simulator_integration_external_id=resource["simulatorIntegrationExternalId"], name=resource["name"], data_set_id=resource["dataSetId"], - created_time=resource["createdTime"], - last_updated_time=resource["lastUpdatedTime"], description=resource.get("description"), ) @@ -1090,13 +1151,117 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) -class SimulatorRoutineList(CogniteResourceList[SimulatorRoutine]): +class SimulatorRoutineWrite(SimulatorRoutineCore): + def __init__( + self, + external_id: str, + simulator_external_id: str, + model_external_id: str, + simulator_integration_external_id: str, + name: str, + data_set_id: int, + description: str | None = None, + ) -> None: + super().__init__( + external_id=external_id, + simulator_external_id=simulator_external_id, + model_external_id=model_external_id, + simulator_integration_external_id=simulator_integration_external_id, + name=name, + data_set_id=data_set_id, + description=description, + ) + + def as_write(self) -> SimulatorRoutineWrite: + """Returns a writeable version of this resource""" + return self + + +class SimulatorRoutine(SimulatorRoutineCore): + def __init__( + self, + external_id: str, + simulator_external_id: str, + model_external_id: str, + simulator_integration_external_id: str, + name: str, + data_set_id: int, + created_time: int | None = None, + last_updated_time: int | None = None, + id: int | None = None, + description: str | None = None, + ) -> None: + self.external_id = external_id + self.simulator_external_id = simulator_external_id + self.model_external_id = model_external_id + self.simulator_integration_external_id = simulator_integration_external_id + self.name = name + self.data_set_id = data_set_id + # id/created_time/last_updated_time are required when using the class to read, + # but don't make sense passing in when creating a new object. So in order to make the typing + # correct here (i.e. int and not Optional[int]), we force the type to be int rather than + # Optional[int]. + self.id: int | None = id + self.created_time: int | None = created_time + self.last_updated_time: int | None = last_updated_time + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + instance = super()._load(resource, cognite_client) + return instance + + def as_write(self) -> SimulatorRoutineWrite: + """Returns a writeable version of this resource""" + return SimulatorRoutineWrite( + external_id=self.external_id, + simulator_external_id=self.simulator_external_id, + model_external_id=self.model_external_id, + simulator_integration_external_id=self.simulator_integration_external_id, + name=self.name, + data_set_id=self.data_set_id, + description=self.description, + ) + + def __hash__(self) -> int: + return hash(self.external_id) + + +class SimulatorRoutineRevisionWriteList(CogniteResourceList[SimulatorRoutineRevisionWrite], ExternalIDTransformerMixin): + _RESOURCE = SimulatorRoutineRevisionWrite + + +class SimulatorRoutineRevisionList( + WriteableCogniteResourceList[SimulatorRoutineRevisionWrite, SimulatorRoutineRevision], IdTransformerMixin +): + _RESOURCE = SimulatorRoutineRevision + + def as_write(self) -> SimulatorRoutineRevisionWriteList: + return SimulatorRoutineRevisionWriteList( + [a.as_write() for a in self.data], cognite_client=self._get_cognite_client() + ) + + +class SimulatorRoutineWriteList(CogniteResourceList[SimulatorRoutineWrite], ExternalIDTransformerMixin): + _RESOURCE = SimulatorRoutineWrite + + +class SimulatorRoutineList(WriteableCogniteResourceList[SimulatorRoutineWrite, SimulatorRoutine], IdTransformerMixin): _RESOURCE = SimulatorRoutine + def as_write(self) -> SimulatorRoutineWriteList: + return SimulatorRoutineWriteList([a.as_write() for a in self.data], cognite_client=self._get_cognite_client()) -class SimulatorRoutineRevisionsList(CogniteResourceList[SimulatorRoutineRevision]): + +class SimulatorRoutineRevisionsList( + WriteableCogniteResourceList[SimulatorRoutineRevisionWrite, SimulatorRoutineRevision], IdTransformerMixin +): _RESOURCE = SimulatorRoutineRevision + def as_write(self) -> SimulatorRoutineRevisionWriteList: + return SimulatorRoutineRevisionWriteList( + [a.as_write() for a in self.data], cognite_client=self._get_cognite_client() + ) + class SimulatorWriteList(CogniteResourceList[SimulatorWrite], ExternalIDTransformerMixin): _RESOURCE = SimulatorWrite From 74ae117259dd31fd13170a3408eb8f16c09c6d9a Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Wed, 27 Nov 2024 16:26:26 +0100 Subject: [PATCH 021/122] remove beta header --- cognite/client/_api/simulators/simulation_runs.py | 7 +++---- cognite/client/_api/simulators/simulator_integrations.py | 1 - cognite/client/_api/simulators/simulator_models.py | 4 ---- cognite/client/_api/simulators/simulator_routines.py | 3 --- cognite/client/_api/simulators/simulators.py | 4 +--- cognite/client/_cognite_client.py | 8 -------- 6 files changed, 4 insertions(+), 23 deletions(-) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py index 2340b378c..f528e36e4 100644 --- a/cognite/client/_api/simulators/simulation_runs.py +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -26,14 +26,14 @@ def list( ) -> SimulationRunsList: """`Filter simulation runs `_ - List all simulation runs + List simulation runs Args: limit (int): The maximum number of simulation runs to return. Defaults to 100. - filter (SimulationRunsFilter | dict[str, Any] | None): The filter to narrow down simulator models. + filter (SimulationRunsFilter | dict[str, Any] | None): The filter to narrow down simulation run. Returns: - SimulationRunsList: List of simulator models + SimulationRunsList: List of simulation runs Examples: @@ -51,7 +51,6 @@ def list( url_path="/simulators/runs/list", resource_cls=SimulationRun, list_cls=SimulationRunsList, - headers={"cdf-version": "beta"}, filter=filter.dump() if isinstance(filter, SimulationRunsFilter) else filter diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index 136a236ba..c4ecc6fe6 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -57,7 +57,6 @@ def list( url_path="/simulators/integrations/list", resource_cls=SimulatorIntegration, list_cls=SimulatorIntegrationList, - headers={"cdf-version": "beta"}, filter=filter.dump() if isinstance(filter, SimulatorIntegrationFilter) else filter diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 203242cb2..800ff4d2e 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -57,7 +57,6 @@ def list( url_path="/simulators/models/list", resource_cls=SimulatorModel, list_cls=SimulatorModelList, - headers={"cdf-version": "beta"}, filter=filter.dump() if isinstance(filter, SimulatorModelsFilter) else filter @@ -92,7 +91,6 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim resource_cls=SimulatorModel, identifiers=identifiers, resource_path="/simulators/models", - headers={"cdf-version": "beta"}, ) def list_revisions( @@ -125,7 +123,6 @@ def list_revisions( url_path="/simulators/models/revisions/list", resource_cls=SimulatorModelRevision, list_cls=SimulatorModelRevisionList, - headers={"cdf-version": "beta"}, filter=filter.dump() if isinstance(filter, SimulatorModelRevisionsFilter) else filter @@ -160,5 +157,4 @@ def retrieve_revision(self, id: int | None = None, external_id: str | None = Non resource_cls=SimulatorModelRevision, identifiers=identifiers, resource_path="/simulators/models/revisions", - headers={"cdf-version": "beta"}, ) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index c13559572..6721a2eaf 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -57,7 +57,6 @@ def list( url_path="/simulators/routines/list", resource_cls=SimulatorRoutine, list_cls=SimulatorRoutineList, - headers={"cdf-version": "beta"}, filter=filter.dump() if isinstance(filter, SimulatorRoutinesFilter) else filter @@ -95,7 +94,6 @@ def list_revisions( url_path="/simulators/routines/revisions/list", resource_cls=SimulatorRoutineRevision, list_cls=SimulatorRoutineRevisionsList, - headers={"cdf-version": "beta"}, filter=filter.dump() if isinstance(filter, SimulatorRoutineRevisionsFilter) else filter @@ -132,5 +130,4 @@ def retrieve_revision( list_cls=SimulatorRoutineRevisionsList, identifiers=identifiers, resource_path="/simulators/routines/revisions", - headers={"cdf-version": "beta"}, ) diff --git a/cognite/client/_api/simulators/simulators.py b/cognite/client/_api/simulators/simulators.py index ba93e1b3d..ee1f499bd 100644 --- a/cognite/client/_api/simulators/simulators.py +++ b/cognite/client/_api/simulators/simulators.py @@ -53,6 +53,4 @@ def list(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorList: """ self._warning.warn() - return self._list( - method="POST", limit=limit, resource_cls=Simulator, list_cls=SimulatorList, headers={"cdf-version": "beta"} - ) + return self._list(method="POST", limit=limit, resource_cls=Simulator, list_cls=SimulatorList) diff --git a/cognite/client/_cognite_client.py b/cognite/client/_cognite_client.py index aa0f3e81e..634963e9d 100644 --- a/cognite/client/_cognite_client.py +++ b/cognite/client/_cognite_client.py @@ -23,10 +23,6 @@ from cognite.client._api.raw import RawAPI from cognite.client._api.relationships import RelationshipsAPI from cognite.client._api.sequences import SequencesAPI -from cognite.client._api.simulators.simulation_runs import SimulatorRunsAPI -from cognite.client._api.simulators.simulator_integrations import SimulatorIntegrationsAPI -from cognite.client._api.simulators.simulator_models import SimulatorModelsAPI -from cognite.client._api.simulators.simulator_routines import SimulatorRoutinesAPI from cognite.client._api.simulators.simulators import SimulatorsAPI from cognite.client._api.templates import TemplatesAPI from cognite.client._api.three_d import ThreeDAPI @@ -89,10 +85,6 @@ def __init__(self, config: ClientConfig | None = None) -> None: self.workflows = WorkflowAPI(self._config, self._API_VERSION, self) self.units = UnitAPI(self._config, self._API_VERSION, self) self.simulators = SimulatorsAPI(self._config, self._API_VERSION, self) - self.simulators.models = SimulatorModelsAPI(self._config, self._API_VERSION, self) - self.simulators.runs = SimulatorRunsAPI(self._config, self._API_VERSION, self) - self.simulators.integrations = SimulatorIntegrationsAPI(self._config, self._API_VERSION, self) - self.simulators.routines = SimulatorRoutinesAPI(self._config, self._API_VERSION, self) # APIs just using base_url: self._api_client = APIClient(self._config, api_version=None, cognite_client=self) From e041dad3aae79f1dba9f185555a9f79a8048a24e Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:37:01 +0100 Subject: [PATCH 022/122] Update cognite/client/_api/simulators/simulator_integrations.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_integrations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index c4ecc6fe6..63d3dbcba 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -29,7 +29,7 @@ def list( limit: int = DEFAULT_LIMIT_READ, filter: SimulatorIntegrationFilter | dict[str, Any] | None = None, ) -> SimulatorIntegrationList: - """`Filter Simulators `_ + """`Filter simulator integrations `_ List simulators From c940dbc30c70f692ee5e1dd25286582a9a394ef7 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:50:23 +0100 Subject: [PATCH 023/122] Update cognite/client/_api/simulators/simulator_routines.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_routines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 6721a2eaf..3638c1afb 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -72,7 +72,7 @@ def list_revisions( List simulators Args: - limit (int): The maximum number of simulators to return. Defaults to 25. Set to -1, float("inf") or None + limit (int): The maximum number of simulator routine revisions to return. Defaults to 10. filter (SimulatorRoutineRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator routine revisions. Returns: From 5a9f01ec4a8a4a5cfb9457e60d8ba53dad37fe79 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:50:40 +0100 Subject: [PATCH 024/122] Update cognite/client/_api/simulators/simulator_routines.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_routines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 3638c1afb..923c9a89e 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -106,7 +106,7 @@ def retrieve_revision( ) -> SimulatorRoutineRevision | None: """`Retrieve Simulator Routine Revisions `_ - Retrieve Simulator Routine Revisions + Retrieve multiple simulator routine revisions by IDs or external IDs Args: id (int | None): The id of the simulator routine revision. From 079075bd2834b8ec39b318241292f99ce7bfff83 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:53:26 +0100 Subject: [PATCH 025/122] Update cognite/client/_api/simulators/simulator_routines.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_routines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 923c9a89e..6f7366122 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -69,7 +69,7 @@ def list_revisions( ) -> SimulatorRoutineRevisionsList: """`Filter Simulators `_ - List simulators + List simulator routine revisions Args: limit (int): The maximum number of simulator routine revisions to return. Defaults to 10. From 27fe6bd35cf8e3e1e9a7a569547cae5392b209a8 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:53:36 +0100 Subject: [PATCH 026/122] Update cognite/client/_api/simulators/simulator_routines.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_routines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 6f7366122..97ed45c65 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -76,7 +76,7 @@ def list_revisions( filter (SimulatorRoutineRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator routine revisions. Returns: - SimulatorRoutineRevisionsList: List of simulator routines + SimulatorRoutineRevisionsList: List of simulator routine revisions Examples: From 8e7ae96341901f4713feba28e78f62fae5a312c2 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:54:19 +0100 Subject: [PATCH 027/122] Update cognite/client/_api/simulators/simulator_integrations.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_integrations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index 63d3dbcba..a88392183 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -34,7 +34,7 @@ def list( List simulators Args: - limit (int): The maximum number of simulators to return. Defaults to 100. + limit (int): The maximum number of simulator integrations to return. Defaults to 100. filter (SimulatorIntegrationFilter | dict[str, Any] | None): The filter to narrow down simulator integrations. Returns: From 2001b372e2a30c7de39aa3e925ef4804097d78df Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:55:55 +0100 Subject: [PATCH 028/122] Update cognite/client/_api/simulators/simulator_routines.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_routines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 97ed45c65..ed9c02bd2 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -104,7 +104,7 @@ def list_revisions( def retrieve_revision( self, id: int | None = None, external_id: str | None = None ) -> SimulatorRoutineRevision | None: - """`Retrieve Simulator Routine Revisions `_ + """`Retrieve simulator routine revisions `_ Retrieve multiple simulator routine revisions by IDs or external IDs From 3a5a13930797650728298dfb513be88e911a8f8d Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:56:07 +0100 Subject: [PATCH 029/122] Update cognite/client/_api/simulators/simulators.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulators.py b/cognite/client/_api/simulators/simulators.py index ee1f499bd..8854da47a 100644 --- a/cognite/client/_api/simulators/simulators.py +++ b/cognite/client/_api/simulators/simulators.py @@ -33,7 +33,7 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client ) def list(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorList: - """`Filter Simulators `_ + """`Filter simulators `_ List simulators From 75c61893b8bf8f17d02f805de3c826348b22853c Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:56:49 +0100 Subject: [PATCH 030/122] Update cognite/client/_api/simulators/simulator_integrations.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_integrations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index a88392183..57eeb08c8 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -31,7 +31,7 @@ def list( ) -> SimulatorIntegrationList: """`Filter simulator integrations `_ - List simulators + List simulator integrations Args: limit (int): The maximum number of simulator integrations to return. Defaults to 100. From 334bfadc637234c095506a6478d1322a91b57f0a Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Thu, 28 Nov 2024 13:05:48 +0100 Subject: [PATCH 031/122] fix docstrings --- .../client/_api/simulators/simulation_runs.py | 6 +++--- .../_api/simulators/simulator_integrations.py | 6 +++--- .../_api/simulators/simulator_models.py | 20 ++++++++++++++----- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py index f528e36e4..d80af8ab2 100644 --- a/cognite/client/_api/simulators/simulation_runs.py +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -37,11 +37,11 @@ def list( Examples: - List simulators: + List simulation runs: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.list() + >>> res = client.simulators.runs.list() """ self._warning.warn() @@ -55,5 +55,5 @@ def list( if isinstance(filter, SimulationRunsFilter) else filter if isinstance(filter, dict) - else None, # fix this + else None, ) diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index 57eeb08c8..f96fcc80b 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -38,15 +38,15 @@ def list( filter (SimulatorIntegrationFilter | dict[str, Any] | None): The filter to narrow down simulator integrations. Returns: - SimulatorIntegrationList: List of simulators + SimulatorIntegrationList: List of simulator integrations Examples: - List simulators: + List simulator integrations: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.list_integrations() + >>> res = client.simulators.integrations.list() """ diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 800ff4d2e..c1fe6d3fb 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -32,7 +32,7 @@ def list( ) -> SimulatorModelList: """`Filter Simulator Models `_ - List all simulation models + List simulator models Args: limit (int): The maximum number of simulator models to return. Defaults to 100. @@ -43,11 +43,11 @@ def list( Examples: - List simulators: + List simulator models: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.list_models() + >>> res = client.simulators.models.list() """ self._warning.warn() @@ -78,11 +78,21 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim Examples: - List simulators: + List simulator models: + + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.list() + + Get simulator model by id: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.retrieve(id=1) + Get simulator model by external id: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.retrieve_model() + >>> res = client.simulators.models.retrieve(external_id="1") """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() From 281a6696b47998ca7fa91db53a4a5e2039a0b3ca Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Thu, 28 Nov 2024 13:16:15 +0100 Subject: [PATCH 032/122] chane structure for revisions --- .../_api/simulators/simulator_models.py | 135 ++++++++++-------- .../_api/simulators/simulator_routines.py | 95 ++++++------ .../test_simulators/test_simulators.py | 8 +- 3 files changed, 131 insertions(+), 107 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index c1fe6d3fb..6a08f5aa7 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -18,8 +18,9 @@ from cognite.client import ClientConfig, CogniteClient -class SimulatorModelsAPI(APIClient): - _RESOURCE_PATH = "/simulators/models" + +class SimulatorModelRevisionsAPI(APIClient): + _RESOURCE_PATH = "/simulators/models/revisions" def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: super().__init__(config, api_version, cognite_client) @@ -28,22 +29,22 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client ) def list( - self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelsFilter | dict[str, Any] | None = None - ) -> SimulatorModelList: - """`Filter Simulator Models `_ + self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelRevisionsFilter | dict[str, Any] | None = None + ) -> SimulatorModelRevisionList: + """`Filter simulator model revisions `_ - List simulator models + List all simulation model revisions Args: - limit (int): The maximum number of simulator models to return. Defaults to 100. - filter (SimulatorModelsFilter | dict[str, Any] | None): The filter to narrow down simulator models. + limit (int): The maximum number of model revisions to return. Defaults to 100. + filter (SimulatorModelRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator model revisions. Returns: - SimulatorModelList: List of simulator models + SimulatorModelRevisionList: List all simulation model revisions Examples: - List simulator models: + List simulators: >>> from cognite.client import CogniteClient >>> client = CogniteClient() @@ -54,117 +55,129 @@ def list( return self._list( method="POST", limit=limit, - url_path="/simulators/models/list", - resource_cls=SimulatorModel, - list_cls=SimulatorModelList, + url_path="/simulators/models/revisions/list", + resource_cls=SimulatorModelRevision, + list_cls=SimulatorModelRevisionList, filter=filter.dump() - if isinstance(filter, SimulatorModelsFilter) + if isinstance(filter, SimulatorModelRevisionsFilter) else filter if isinstance(filter, dict) else None, # fix this ) - def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModel | None: - """`Retrieve Simulator Model `_ + def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModelRevision | None: + """`Retrieve Simulator Model Revisions `_ - Get a simulator model by id/externalId + Retrieve simulator model revisions by IDs or external IDs Args: - id (int | None): The id of the simulator model. - external_id (str | None): The external id of the simulator model. + id (int | None): The id of the simulator model revision. + external_id (str | None): The external id of the simulator model revision. Returns: - SimulatorModel | None: Requested simulator model + SimulatorModelRevision | None: Requested simulator model revision Examples: - List simulator models: - - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> res = client.simulators.models.list() - - Get simulator model by id: - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> res = client.simulators.models.retrieve(id=1) + List simulators: - Get simulator model by external id: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.models.retrieve(external_id="1") + >>> res = client.simulators.models.revisions.retrieve(external_id="1") """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() return self._retrieve_multiple( - list_cls=SimulatorModelList, - resource_cls=SimulatorModel, + list_cls=SimulatorModelRevisionList, + resource_cls=SimulatorModelRevision, identifiers=identifiers, - resource_path="/simulators/models", + resource_path="/simulators/models/revisions", ) - def list_revisions( - self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelRevisionsFilter | dict[str, Any] | None = None - ) -> SimulatorModelRevisionList: - """`Filter simulator model revisions `_ - List all simulation model revisions + +class SimulatorModelsAPI(APIClient): + _RESOURCE_PATH = "/simulators/models" + + def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: + super().__init__(config, api_version, cognite_client) + self.revisions = SimulatorModelRevisionsAPI(config, api_version, cognite_client) + self._warning = FeaturePreviewWarning( + api_maturity="General Availability", sdk_maturity="alpha", feature_name="Simulators" + ) + + def list( + self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelsFilter | dict[str, Any] | None = None + ) -> SimulatorModelList: + """`Filter Simulator Models `_ + + List simulator models Args: - limit (int): The maximum number of model revisions to return. Defaults to 100. - filter (SimulatorModelRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator model revisions. + limit (int): The maximum number of simulator models to return. Defaults to 100. + filter (SimulatorModelsFilter | dict[str, Any] | None): The filter to narrow down simulator models. Returns: - SimulatorModelRevisionList: List all simulation model revisions + SimulatorModelList: List of simulator models Examples: - List simulators: + List simulator models: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.list_revisions() + >>> res = client.simulators.models.list() """ self._warning.warn() return self._list( method="POST", limit=limit, - url_path="/simulators/models/revisions/list", - resource_cls=SimulatorModelRevision, - list_cls=SimulatorModelRevisionList, + url_path="/simulators/models/list", + resource_cls=SimulatorModel, + list_cls=SimulatorModelList, filter=filter.dump() - if isinstance(filter, SimulatorModelRevisionsFilter) + if isinstance(filter, SimulatorModelsFilter) else filter if isinstance(filter, dict) else None, # fix this ) - def retrieve_revision(self, id: int | None = None, external_id: str | None = None) -> SimulatorModelRevision | None: - """`Retrieve Simulator Model Revisions `_ + def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModel | None: + """`Retrieve Simulator Model `_ - Retrieve simulator model revisions by IDs or external IDs + Get a simulator model by id/externalId Args: - id (int | None): The id of the simulator model revision. - external_id (str | None): The external id of the simulator model revision. + id (int | None): The id of the simulator model. + external_id (str | None): The external id of the simulator model. Returns: - SimulatorModelRevision | None: Requested simulator model revision + SimulatorModel | None: Requested simulator model Examples: - List simulators: + List simulator models: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.retrieve_revision() + >>> res = client.simulators.models.list() + + Get simulator model by id: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.retrieve(id=1) + + Get simulator model by external id: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.retrieve(external_id="1") """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() return self._retrieve_multiple( - list_cls=SimulatorModelRevisionList, - resource_cls=SimulatorModelRevision, + list_cls=SimulatorModelList, + resource_cls=SimulatorModel, identifiers=identifiers, - resource_path="/simulators/models/revisions", - ) + resource_path="/simulators/models", + ) \ No newline at end of file diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index ed9c02bd2..0c8c551da 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -18,8 +18,8 @@ from cognite.client import ClientConfig, CogniteClient -class SimulatorRoutinesAPI(APIClient): - _RESOURCE_PATH = "/simulators/routines" +class SimulatorRoutineRevisionsAPI(APIClient): + _RESOURCE_PATH = "/simulators/routines/revisions" def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: super().__init__(config, api_version, cognite_client) @@ -28,43 +28,6 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client ) def list( - self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutinesFilter | dict[str, Any] | None = None - ) -> SimulatorRoutineList: - """`Filter Simulators `_ - - List simulators - - Args: - limit (int): The maximum number of simulators to return. Defaults to 100. - filter (SimulatorRoutinesFilter | dict[str, Any] | None): The filter to narrow down simulator routines. - - Returns: - SimulatorRoutineList: List of simulator routines - - Examples: - - List simulators: - - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> res = client.simulators.list_routines() - - """ - self._warning.warn() - return self._list( - method="POST", - limit=limit, - url_path="/simulators/routines/list", - resource_cls=SimulatorRoutine, - list_cls=SimulatorRoutineList, - filter=filter.dump() - if isinstance(filter, SimulatorRoutinesFilter) - else filter - if isinstance(filter, dict) - else None, # fix this - ) - - def list_revisions( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutineRevisionsFilter | dict[str, Any] | None = None ) -> SimulatorRoutineRevisionsList: """`Filter Simulators `_ @@ -84,7 +47,7 @@ def list_revisions( >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.list_revisions() + >>> res = client.simulators.routines.list() """ self._warning.warn() @@ -101,7 +64,7 @@ def list_revisions( else None, # fix this ) - def retrieve_revision( + def retrieve( self, id: int | None = None, external_id: str | None = None ) -> SimulatorRoutineRevision | None: """`Retrieve simulator routine revisions `_ @@ -121,7 +84,7 @@ def retrieve_revision( >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.retrieve_revision() + >>> res = client.simulators.routine.retrieve(external_id="1") """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() @@ -131,3 +94,51 @@ def retrieve_revision( identifiers=identifiers, resource_path="/simulators/routines/revisions", ) + +class SimulatorRoutinesAPI(APIClient): + _RESOURCE_PATH = "/simulators/routines" + + def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: + super().__init__(config, api_version, cognite_client) + self.revisions = SimulatorRoutineRevisionsAPI(config, api_version, cognite_client) + self._warning = FeaturePreviewWarning( + api_maturity="General Availability", sdk_maturity="alpha", feature_name="Simulators" + ) + + def list( + self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutinesFilter | dict[str, Any] | None = None + ) -> SimulatorRoutineList: + """`Filter Simulators `_ + + List simulators + + Args: + limit (int): The maximum number of simulators to return. Defaults to 100. + filter (SimulatorRoutinesFilter | dict[str, Any] | None): The filter to narrow down simulator routines. + + Returns: + SimulatorRoutineList: List of simulator routines + + Examples: + + List simulators: + + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.list_routines() + + """ + self._warning.warn() + return self._list( + method="POST", + limit=limit, + url_path="/simulators/routines/list", + resource_cls=SimulatorRoutine, + list_cls=SimulatorRoutineList, + filter=filter.dump() + if isinstance(filter, SimulatorRoutinesFilter) + else filter + if isinstance(filter, dict) + else None, # fix this + ) + diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 87d789cfd..50bd289dd 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -102,11 +102,11 @@ def test_retrieve_model(self, cognite_client: CogniteClient) -> None: assert model.external_id == "TEST_WORKFLOWS_SIMINT_INTEGRATION_MODEL" def test_list_model_revisions(self, cognite_client: CogniteClient) -> None: - revisions = cognite_client.simulators.models.list_revisions(limit=5) + revisions = cognite_client.simulators.models.revisions.list(limit=5) assert len(revisions) > 0 def test_retrieve_model_revision(self, cognite_client: CogniteClient) -> None: - model = cognite_client.simulators.models.retrieve_revision(external_id="Shower_mixer-1") + model = cognite_client.simulators.models.revisions.retrieve(external_id="Shower_mixer-1") assert model is not None assert model.external_id == "Shower_mixer-1" @@ -117,13 +117,13 @@ def test_list_routines(self, cognite_client: CogniteClient) -> None: assert len(routines) > 0 def test_list_routine_revisions(self, cognite_client: CogniteClient) -> None: - revisions = cognite_client.simulators.routines.list_revisions(limit=5) + revisions = cognite_client.simulators.routines.revisions.list(limit=5) assert revisions[0].configuration is not None assert revisions[0].script is not None assert len(revisions) > 0 def test_retrieve_routine_revision(self, cognite_client: CogniteClient) -> None: - revision = cognite_client.simulators.routines.retrieve_revision(external_id="ShowerMixerForTests-1") + revision = cognite_client.simulators.routines.revisions.retrieve(external_id="ShowerMixerForTests-1") assert revision is not None assert revision.external_id == "ShowerMixerForTests-1" From 5947ad7b9f9f8d1218f6ed42658e3060c1bc9a86 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Thu, 28 Nov 2024 13:17:08 +0100 Subject: [PATCH 033/122] fmt --- cognite/client/_api/simulators/simulator_models.py | 4 +--- cognite/client/_api/simulators/simulator_routines.py | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 6a08f5aa7..ee93c7301 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -18,7 +18,6 @@ from cognite.client import ClientConfig, CogniteClient - class SimulatorModelRevisionsAPI(APIClient): _RESOURCE_PATH = "/simulators/models/revisions" @@ -95,7 +94,6 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim ) - class SimulatorModelsAPI(APIClient): _RESOURCE_PATH = "/simulators/models" @@ -180,4 +178,4 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim resource_cls=SimulatorModel, identifiers=identifiers, resource_path="/simulators/models", - ) \ No newline at end of file + ) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 0c8c551da..ad276bf24 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -64,9 +64,7 @@ def list( else None, # fix this ) - def retrieve( - self, id: int | None = None, external_id: str | None = None - ) -> SimulatorRoutineRevision | None: + def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorRoutineRevision | None: """`Retrieve simulator routine revisions `_ Retrieve multiple simulator routine revisions by IDs or external IDs @@ -95,6 +93,7 @@ def retrieve( resource_path="/simulators/routines/revisions", ) + class SimulatorRoutinesAPI(APIClient): _RESOURCE_PATH = "/simulators/routines" @@ -141,4 +140,3 @@ def list( if isinstance(filter, dict) else None, # fix this ) - From b6672ff5e6b7402bbeb192328c76c7c591268947 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:17:42 +0100 Subject: [PATCH 034/122] Update cognite/client/_api/simulators/simulation_runs.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulation_runs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py index d80af8ab2..13e67ea7a 100644 --- a/cognite/client/_api/simulators/simulation_runs.py +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -24,7 +24,7 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulationRunsFilter | dict[str, Any] | None = None ) -> SimulationRunsList: - """`Filter simulation runs `_ + """`Filter simulation runs `_ List simulation runs From 5d09fb00be11beb908bc523616f32ebf529d1052 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 2 Dec 2024 12:12:12 +0100 Subject: [PATCH 035/122] update docstrings --- .../client/_api/simulators/simulation_runs.py | 2 +- .../_api/simulators/simulator_models.py | 22 ++++++++-------- .../_api/simulators/simulator_routines.py | 26 +++++++++++-------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py index 13e67ea7a..d787d33fc 100644 --- a/cognite/client/_api/simulators/simulation_runs.py +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -30,7 +30,7 @@ def list( Args: limit (int): The maximum number of simulation runs to return. Defaults to 100. - filter (SimulationRunsFilter | dict[str, Any] | None): The filter to narrow down simulation run. + filter (SimulationRunsFilter | dict[str, Any] | None): The filter that helps narrow down the list of simulation runs. Returns: SimulationRunsList: List of simulation runs diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index ee93c7301..785fbf913 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -30,24 +30,24 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelRevisionsFilter | dict[str, Any] | None = None ) -> SimulatorModelRevisionList: - """`Filter simulator model revisions `_ + """`Filter simulator model revisions `_ - List all simulation model revisions + List simulator model revisions Args: limit (int): The maximum number of model revisions to return. Defaults to 100. filter (SimulatorModelRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator model revisions. Returns: - SimulatorModelRevisionList: List all simulation model revisions + SimulatorModelRevisionList: List all simulator model revisions Examples: - List simulators: + List simulators model revisions: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.models.list() + >>> res = client.simulators.models.routines.list() """ self._warning.warn() @@ -65,9 +65,9 @@ def list( ) def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModelRevision | None: - """`Retrieve Simulator Model Revisions `_ + """`Retrieve simulator model revisions `_ - Retrieve simulator model revisions by IDs or external IDs + Retrieve multiple simulator model revisions by IDs or external IDs Args: id (int | None): The id of the simulator model revision. @@ -78,7 +78,7 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim Examples: - List simulators: + Retrieve simulator model revisions: >>> from cognite.client import CogniteClient >>> client = CogniteClient() @@ -107,7 +107,7 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelsFilter | dict[str, Any] | None = None ) -> SimulatorModelList: - """`Filter Simulator Models `_ + """`Filter simulator models `_ List simulator models @@ -142,9 +142,9 @@ def list( ) def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModel | None: - """`Retrieve Simulator Model `_ + """`Retrieve simulator model `_ - Get a simulator model by id/externalId + Retrieve a single simulator model by id/externalId Args: id (int | None): The id of the simulator model. diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index ad276bf24..a9a84848f 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -30,7 +30,7 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutineRevisionsFilter | dict[str, Any] | None = None ) -> SimulatorRoutineRevisionsList: - """`Filter Simulators `_ + """`Filter simulator routine revisions `_ List simulator routine revisions @@ -47,7 +47,7 @@ def list( >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.routines.list() + >>> res = client.simulators.routines.revisions.list() """ self._warning.warn() @@ -78,11 +78,15 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim Examples: - List simulators: + Get simulator routine revisions by id: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.routines.revisions.retrieve(ids=[1, 2, 3]) - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> res = client.simulators.routine.retrieve(external_id="1") + Get simulator routine revisions by external id: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.routines.revisions.retrieve(external_ids=["abc", "def"]) """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() @@ -107,12 +111,12 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutinesFilter | dict[str, Any] | None = None ) -> SimulatorRoutineList: - """`Filter Simulators `_ + """`Filter simulator routines `_ - List simulators + List simulator routines Args: - limit (int): The maximum number of simulators to return. Defaults to 100. + limit (int): The maximum number of simulator routines to return. Defaults to 100. filter (SimulatorRoutinesFilter | dict[str, Any] | None): The filter to narrow down simulator routines. Returns: @@ -120,11 +124,11 @@ def list( Examples: - List simulators: + List simulator routines: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.list_routines() + >>> res = client.simulators.routines.list() """ self._warning.warn() From 016227c80cc1744d87654d3e108c6a60fe1d0758 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 2 Dec 2024 12:20:56 +0100 Subject: [PATCH 036/122] update docstrings --- .../_api/simulators/simulator_models.py | 25 +++++++++++-------- .../_api/simulators/simulator_routines.py | 11 ++++---- cognite/client/_api/simulators/simulators.py | 2 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 785fbf913..39e5602ed 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -35,19 +35,18 @@ def list( List simulator model revisions Args: - limit (int): The maximum number of model revisions to return. Defaults to 100. + limit (int): The maximum number of simulator model revisions to return. Defaults to 100. filter (SimulatorModelRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator model revisions. Returns: - SimulatorModelRevisionList: List all simulator model revisions + SimulatorModelRevisionList: List of simulator model revisions Examples: - List simulators model revisions: - - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> res = client.simulators.models.routines.list() + List simulator model revisions: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.revisions.list() """ self._warning.warn() @@ -78,11 +77,15 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim Examples: - Retrieve simulator model revisions: + Get simulator model revisions by id: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.revisions.retrieve(ids=[1, 2, 3]) - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> res = client.simulators.models.revisions.retrieve(external_id="1") + Get simulator model revisions by external id: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.revisions.retrieve(external_ids=["abc", "def"]) """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index a9a84848f..44b6a2e74 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -43,11 +43,10 @@ def list( Examples: - List simulators: - - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> res = client.simulators.routines.revisions.list() + List simulator routine revisions: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.routines.revisions.list() """ self._warning.warn() @@ -111,7 +110,7 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client def list( self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutinesFilter | dict[str, Any] | None = None ) -> SimulatorRoutineList: - """`Filter simulator routines `_ + """`Filter simulator routines `_ List simulator routines diff --git a/cognite/client/_api/simulators/simulators.py b/cognite/client/_api/simulators/simulators.py index 8854da47a..7599951d0 100644 --- a/cognite/client/_api/simulators/simulators.py +++ b/cognite/client/_api/simulators/simulators.py @@ -38,7 +38,7 @@ def list(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorList: List simulators Args: - limit (int): The maximum number of simulators to return. Defaults to 25. Set to -1, float("inf") or None + limit (int): The maximum number of simulators to return. Defaults to 10. Returns: SimulatorList: List of simulators From 7bd168414189e8f45aab01d521e4f4aa28a4b960 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 2 Dec 2024 13:42:57 +0100 Subject: [PATCH 037/122] add retrieve_multiple method and clean up seed data --- .../_api/simulators/simulator_integrations.py | 2 +- .../_api/simulators/simulator_models.py | 52 ++- .../_api/simulators/simulator_routines.py | 50 ++- .../data_classes/simulators/simulators.py | 48 +-- .../test_api/test_simulators/seed/data.py | 376 ------------------ 5 files changed, 104 insertions(+), 424 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index f96fcc80b..6c9cc0137 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -61,5 +61,5 @@ def list( if isinstance(filter, SimulatorIntegrationFilter) else filter if isinstance(filter, dict) - else None, # fix this + else None, ) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 39e5602ed..2fed01cab 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -1,5 +1,6 @@ from __future__ import annotations +from collections.abc import Sequence from typing import TYPE_CHECKING, Any from cognite.client._api_client import APIClient @@ -13,6 +14,7 @@ ) from cognite.client.utils._experimental import FeaturePreviewWarning from cognite.client.utils._identifier import IdentifierSequence +from cognite.client.utils.useful_types import SequenceNotStr if TYPE_CHECKING: from cognite.client import ClientConfig, CogniteClient @@ -60,11 +62,11 @@ def list( if isinstance(filter, SimulatorModelRevisionsFilter) else filter if isinstance(filter, dict) - else None, # fix this + else None, ) def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModelRevision | None: - """`Retrieve simulator model revisions `_ + """`Retrieve simulator model revision `_ Retrieve multiple simulator model revisions by IDs or external IDs @@ -77,15 +79,15 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim Examples: - Get simulator model revisions by id: + Get simulator model revision by id: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.models.revisions.retrieve(ids=[1, 2, 3]) + >>> res = client.simulators.models.revisions.retrieve(id=123) - Get simulator model revisions by external id: + Get simulator model revision by external id: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.models.revisions.retrieve(external_ids=["abc", "def"]) + >>> res = client.simulators.models.revisions.retrieve(external_id="abcdef") """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() @@ -96,6 +98,42 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim resource_path="/simulators/models/revisions", ) + def retrieve_multiple( + self, + ids: Sequence[int] | None = None, + external_ids: SequenceNotStr[str] | None = None, + ignore_unknown_ids: bool = False, + ) -> SimulatorModelRevisionList: + """`Retrieve simulator model revisions `_ + + Args: + ids (Sequence[int] | None): IDs + external_ids (SequenceNotStr[str] | None): External IDs + ignore_unknown_ids (bool): Ignore IDs and external IDs that are not found rather than throw an exception. + + Returns: + SimulatorModelRevisionList: Requested simulator model revisions + + Examples: + + Get simulator model revisions by ids: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.revisions.retrieve_multiple(ids=[1, 2, 3]) + + Get simulator model revisions by external ids: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.revisions.retrieve_multiple(external_ids=["abc", "def"]) + """ + identifiers = IdentifierSequence.load(ids=ids, external_ids=external_ids) + return self._retrieve_multiple( + list_cls=SimulatorModelRevisionList, + resource_cls=SimulatorModelRevision, + identifiers=identifiers, + ignore_unknown_ids=ignore_unknown_ids, + ) + class SimulatorModelsAPI(APIClient): _RESOURCE_PATH = "/simulators/models" @@ -141,7 +179,7 @@ def list( if isinstance(filter, SimulatorModelsFilter) else filter if isinstance(filter, dict) - else None, # fix this + else None, ) def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModel | None: diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 44b6a2e74..6fe4ea2d9 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -1,5 +1,6 @@ from __future__ import annotations +from collections.abc import Sequence from typing import TYPE_CHECKING, Any from cognite.client._api_client import APIClient @@ -13,6 +14,7 @@ ) from cognite.client.utils._experimental import FeaturePreviewWarning from cognite.client.utils._identifier import IdentifierSequence +from cognite.client.utils.useful_types import SequenceNotStr if TYPE_CHECKING: from cognite.client import ClientConfig, CogniteClient @@ -60,7 +62,7 @@ def list( if isinstance(filter, SimulatorRoutineRevisionsFilter) else filter if isinstance(filter, dict) - else None, # fix this + else None, ) def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorRoutineRevision | None: @@ -77,15 +79,15 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim Examples: - Get simulator routine revisions by id: + Get simulator routine revision by id: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.routines.revisions.retrieve(ids=[1, 2, 3]) + >>> res = client.simulators.routines.revisions.retrieve(ids=123) - Get simulator routine revisions by external id: + Get simulator routine revision by external id: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.routines.revisions.retrieve(external_ids=["abc", "def"]) + >>> res = client.simulators.routines.revisions.retrieve(external_ids="abcdef") """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() @@ -96,6 +98,42 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim resource_path="/simulators/routines/revisions", ) + def retrieve_multiple( + self, + ids: Sequence[int] | None = None, + external_ids: SequenceNotStr[str] | None = None, + ignore_unknown_ids: bool = False, + ) -> SimulatorRoutineRevisionsList: + """`Retrieve simulator routine revisions `_ + + Args: + ids (Sequence[int] | None): IDs + external_ids (SequenceNotStr[str] | None): External IDs + ignore_unknown_ids (bool): Ignore IDs and external IDs that are not found rather than throw an exception. + + Returns: + SimulatorRoutineRevisionsList: Requested simulator routine revisions + + Examples: + + Get simulator routine revisions by id: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.routines.revisions.retrieve_multiple(ids=[1, 2, 3]) + + Get simulator routine revisions by external id: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.routines.revisions.retrieve_multiple(external_ids=["abc", "def"]) + """ + identifiers = IdentifierSequence.load(ids=ids, external_ids=external_ids) + return self._retrieve_multiple( + list_cls=SimulatorRoutineRevisionsList, + resource_cls=SimulatorRoutineRevision, + identifiers=identifiers, + ignore_unknown_ids=ignore_unknown_ids, + ) + class SimulatorRoutinesAPI(APIClient): _RESOURCE_PATH = "/simulators/routines" @@ -141,5 +179,5 @@ def list( if isinstance(filter, SimulatorRoutinesFilter) else filter if isinstance(filter, dict) - else None, # fix this + else None, ) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 82a9399ae..83f636f33 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -122,15 +122,13 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: @dataclass class SimulatorRoutineSchedule(CogniteObject): - enabled: bool + enabled: bool = False cron_expression: str | None = None @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - return cls( - enabled=resource["enabled"], - cron_expression=resource.get("cronExpression"), - ) + instance = super()._load(resource, cognite_client) + return instance def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) @@ -138,19 +136,15 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: @dataclass class SimulatorRoutineDataSampling(CogniteObject): - enabled: bool + enabled: bool = False validation_window: int | None = None sampling_window: int | None = None granularity: str | None = None @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - return cls( - enabled=resource["enabled"], - validation_window=resource.get("validationWindow"), - sampling_window=resource.get("samplingWindow"), - granularity=resource.get("granularity"), - ) + instance = super()._load(resource, cognite_client) + return instance def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) @@ -158,7 +152,7 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: @dataclass class SimulatorRoutineLogicalCheckEnabled(CogniteObject): - enabled: bool + enabled: bool = False timeseries_external_id: str | None = None aggregate: str | None = None operator: str | None = None @@ -166,13 +160,8 @@ class SimulatorRoutineLogicalCheckEnabled(CogniteObject): @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - return cls( - enabled=resource["enabled"], - timeseries_external_id=resource.get("timeseriesExternalId"), - aggregate=resource.get("aggregate"), - operator=resource.get("operator"), - value=resource.get("value"), - ) + instance = super()._load(resource, cognite_client) + return instance def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) @@ -180,7 +169,7 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: @dataclass class SimulatorRoutineSteadyStateDetectionEnabled(CogniteObject): - enabled: bool + enabled: bool = False timeseries_external_id: str | None = None aggregate: str | None = None min_section_size: int | None = None @@ -189,14 +178,8 @@ class SimulatorRoutineSteadyStateDetectionEnabled(CogniteObject): @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - return cls( - enabled=resource["enabled"], - timeseries_external_id=resource.get("timeseriesExternalId"), - aggregate=resource.get("aggregate"), - min_section_size=resource.get("minSectionSize"), - var_threshold=resource.get("varThreshold"), - slope_threshold=resource.get("slopeThreshold"), - ) + instance = super()._load(resource, cognite_client) + return instance def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) @@ -250,11 +233,8 @@ class SimulatorRoutineStepArguments(CogniteObject): @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - return cls( - reference_id=resource.get("referenceId"), - object_name=resource.get("objectName"), - object_property=resource.get("objectProperty"), - ) + instance = super()._load(resource, cognite_client) + return instance def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index 2de2f000b..b3db2c021 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -32,16 +32,6 @@ }, ], "unitQuantities": [ - { - "name": "area", - "label": "Area", - "units": [{"label": "m2", "name": "m2"}, {"label": "cm2", "name": "cm2"}, {"label": "ft2", "name": "ft2"}], - }, - { - "name": "head", - "label": "Head", - "units": [{"label": "m", "name": "m"}, {"label": "ft", "name": "ft"}, {"label": "cm", "name": "cm"}], - }, { "name": "mass", "label": "Mass", @@ -71,40 +61,6 @@ {"label": "lbf", "name": "lbf"}, ], }, - { - "name": "deltaP", - "label": "Delta P", - "units": [ - {"label": "Pa", "name": "Pa"}, - {"label": "atm", "name": "atm"}, - {"label": "lbf/ft2", "name": "lbf/ft2"}, - {"label": "kgf/cm2", "name": "kgf/cm2"}, - {"label": "kgf/cm2_g", "name": "kgf/cm2_g"}, - {"label": "kPa", "name": "kPa"}, - {"label": "bar", "name": "bar"}, - {"label": "barg", "name": "barg"}, - {"label": "ftH2O", "name": "ftH2O"}, - {"label": "inH2O", "name": "inH2O"}, - {"label": "inHg", "name": "inHg"}, - {"label": "mbar", "name": "mbar"}, - {"label": "mH2O", "name": "mH2O"}, - {"label": "mmH2O", "name": "mmH2O"}, - {"label": "mmHg", "name": "mmHg"}, - {"label": "MPa", "name": "MPa"}, - {"label": "psi", "name": "psi"}, - {"label": "psig", "name": "psig"}, - ], - }, - { - "name": "deltaT", - "label": "Delta T", - "units": [ - {"label": "C.", "name": "C."}, - {"label": "K.", "name": "K."}, - {"label": "F.", "name": "F."}, - {"label": "R.", "name": "R."}, - ], - }, { "name": "volume", "label": "Volume", @@ -127,15 +83,6 @@ {"label": "lbm/ft3", "name": "lbm/ft3"}, ], }, - { - "name": "entropy", - "label": "Entropy", - "units": [ - {"label": "kJ/[kg.K]", "name": "kJ/[kg.K]"}, - {"label": "cal/[g.C]", "name": "cal/[g.C]"}, - {"label": "BTU/[lbm.R]", "name": "BTU/[lbm.R]"}, - ], - }, { "name": "diameter", "label": "Diameter", @@ -146,16 +93,6 @@ "label": "Distance", "units": [{"label": "m", "name": "m"}, {"label": "ft", "name": "ft"}, {"label": "cm", "name": "cm"}], }, - { - "name": "enthalpy", - "label": "Enthalpy", - "units": [ - {"label": "kJ/kg", "name": "kJ/kg"}, - {"label": "cal/g", "name": "cal/g"}, - {"label": "BTU/lbm", "name": "BTU/lbm"}, - {"label": "kcal/kg", "name": "kcal/kg"}, - ], - }, { "name": "heatflow", "label": "Heat Flow", @@ -178,25 +115,6 @@ {"label": "kcal/d", "name": "kcal/d"}, ], }, - { - "name": "massflow", - "label": "Mass Flow", - "units": [ - {"label": "g/s", "name": "g/s"}, - {"label": "lbm/h", "name": "lbm/h"}, - {"label": "kg/s", "name": "kg/s"}, - {"label": "kg/h", "name": "kg/h"}, - {"label": "kg/d", "name": "kg/d"}, - {"label": "kg/min", "name": "kg/min"}, - {"label": "lb/min", "name": "lb/min"}, - {"label": "lb/s", "name": "lb/s"}, - {"label": "lb/h", "name": "lb/h"}, - {"label": "lb/d", "name": "lb/d"}, - {"label": "Mg/s", "name": "Mg/s"}, - {"label": "Mg/h", "name": "Mg/h"}, - {"label": "Mg/d", "name": "Mg/d"}, - ], - }, { "name": "pressure", "label": "Pressure", @@ -222,15 +140,6 @@ {"label": "psig", "name": "psig"}, ], }, - { - "name": "spec_vol", - "label": "Specific Volume", - "units": [ - {"label": "m3/kg", "name": "m3/kg"}, - {"label": "cm3/g", "name": "cm3/g"}, - {"label": "ft3/lbm", "name": "ft3/lbm"}, - ], - }, { "name": "velocity", "label": "Velocity", @@ -245,108 +154,6 @@ {"label": "in/s", "name": "in/s"}, ], }, - { - "name": "mass_conc", - "label": "Mass Concentration", - "units": [ - {"label": "kg/m3", "name": "kg/m3"}, - {"label": "g/L", "name": "g/L"}, - {"label": "g/cm3", "name": "g/cm3"}, - {"label": "g/mL", "name": "g/mL"}, - {"label": "lbm/ft3", "name": "lbm/ft3"}, - ], - }, - { - "name": "molarflow", - "label": "Molar Flow", - "units": [ - {"label": "mol/s", "name": "mol/s"}, - {"label": "lbmol/h", "name": "lbmol/h"}, - {"label": "mol/h", "name": "mol/h"}, - {"label": "mol/d", "name": "mol/d"}, - {"label": "kmol/s", "name": "kmol/s"}, - {"label": "kmol/h", "name": "kmol/h"}, - {"label": "kmol/d", "name": "kmol/d"}, - {"label": "m3/d @ BR", "name": "m3/d @ BR"}, - {"label": "m3/d @ NC", "name": "m3/d @ NC"}, - {"label": "m3/d @ CNTP", "name": "m3/d @ CNTP"}, - {"label": "m3/d @ SC", "name": "m3/d @ SC"}, - {"label": "m3/d @ 0 C, 1 atm", "name": "m3/d @ 0 C, 1 atm"}, - {"label": "m3/d @ 15.56 C, 1 atm", "name": "m3/d @ 15.56 C, 1 atm"}, - {"label": "m3/d @ 20 C, 1 atm", "name": "m3/d @ 20 C, 1 atm"}, - {"label": "ft3/d @ 60 f, 14.7 psia", "name": "ft3/d @ 60 f, 14.7 psia"}, - {"label": "ft3/d @ 0 C, 1 atm", "name": "ft3/d @ 0 C, 1 atm"}, - {"label": "MMSCFD", "name": "MMSCFD"}, - {"label": "SCFD", "name": "SCFD"}, - {"label": "SCFM", "name": "SCFM"}, - {"label": "Mm3/d @ BR", "name": "Mm3/d @ BR"}, - {"label": "Mm3/d @ SC", "name": "Mm3/d @ SC"}, - {"label": "Mm3/d @ NC", "name": "Mm3/d @ NC"}, - ], - }, - { - "name": "reac_rate", - "label": "Reaction Rate", - "units": [ - {"label": "kmol/[m3.s]", "name": "kmol/[m3.s]"}, - {"label": "kmol/[m3.min.]", "name": "kmol/[m3.min.]"}, - {"label": "kmol/[m3.h]", "name": "kmol/[m3.h]"}, - {"label": "mol/[m3.s]", "name": "mol/[m3.s]"}, - {"label": "mol/[m3.min.]", "name": "mol/[m3.min.]"}, - {"label": "mol/[m3.h]", "name": "mol/[m3.h]"}, - {"label": "mol/[L.s]", "name": "mol/[L.s]"}, - {"label": "mol/[L.min.]", "name": "mol/[L.min.]"}, - {"label": "mol/[L.h]", "name": "mol/[L.h]"}, - {"label": "mol/[cm3.s]", "name": "mol/[cm3.s]"}, - {"label": "mol/[cm3.min.]", "name": "mol/[cm3.min.]"}, - {"label": "mol/[cm3.h]", "name": "mol/[cm3.h]"}, - {"label": "lbmol/[ft3.h]", "name": "lbmol/[ft3.h]"}, - ], - }, - { - "name": "viscosity", - "label": "Viscosity", - "units": [ - {"label": "kg/[m.s]", "name": "kg/[m.s]"}, - {"label": "Pa.s", "name": "Pa.s"}, - {"label": "cP", "name": "cP"}, - {"label": "lbm/[ft.h]", "name": "lbm/[ft.h]"}, - ], - }, - { - "name": "molar_conc", - "label": "Molar Concentration", - "units": [ - {"label": "kmol/m3", "name": "kmol/m3"}, - {"label": "mol/m3", "name": "mol/m3"}, - {"label": "mol/L", "name": "mol/L"}, - {"label": "mol/cm3", "name": "mol/cm3"}, - {"label": "mol/mL", "name": "mol/mL"}, - {"label": "lbmol/ft3", "name": "lbmol/ft3"}, - ], - }, - { - "name": "conductance", - "label": "Conductance", - "units": [ - {"label": "[kg/s]/[Pa^0.5]", "name": "[kg/s]/[Pa^0.5]"}, - {"label": "[lbm/h]/[psi^0.5]", "name": "[lbm/h]/[psi^0.5]"}, - {"label": "[kg/h]/[atm^0.5]", "name": "[kg/h]/[atm^0.5]"}, - {"label": "[kg/h]/[bar^0.5]", "name": "[kg/h]/[bar^0.5]"}, - {"label": "[kg/h]/[[kgf/cm2]^0.5]", "name": "[kg/h]/[[kgf/cm2]^0.5]"}, - ], - }, - { - "name": "diffusivity", - "label": "Diffusivity", - "units": [ - {"label": "m2/s", "name": "m2/s"}, - {"label": "cSt", "name": "cSt"}, - {"label": "ft2/s", "name": "ft2/s"}, - {"label": "mm2/s", "name": "mm2/s"}, - {"label": "cm2/s", "name": "cm2/s"}, - ], - }, { "name": "temperature", "label": "Temperature", @@ -357,189 +164,6 @@ {"label": "F", "name": "F"}, ], }, - { - "name": "molar_volume", - "label": "Molar Volume", - "units": [ - {"label": "m3/kmol", "name": "m3/kmol"}, - {"label": "cm3/mmol", "name": "cm3/mmol"}, - {"label": "ft3/lbmol", "name": "ft3/lbmol"}, - ], - }, - { - "name": "speedOfSound", - "label": "Speed of Sound", - "units": [ - {"label": "m/s", "name": "m/s"}, - {"label": "cm/s", "name": "cm/s"}, - {"label": "mm/s", "name": "mm/s"}, - {"label": "km/h", "name": "km/h"}, - {"label": "ft/h", "name": "ft/h"}, - {"label": "ft/min", "name": "ft/min"}, - {"label": "ft/s", "name": "ft/s"}, - {"label": "in/s", "name": "in/s"}, - ], - }, - { - "name": "foulingfactor", - "label": "Fouling Factor", - "units": [ - {"label": "K.m2/W", "name": "K.m2/W"}, - {"label": "C.cm2.s/cal", "name": "C.cm2.s/cal"}, - {"label": "ft2.h.F/BTU", "name": "ft2.h.F/BTU"}, - ], - }, - { - "name": "molar_entropy", - "label": "Molar Entropy", - "units": [ - {"label": "kJ/[kmol.K]", "name": "kJ/[kmol.K]"}, - {"label": "cal/[mol.C]", "name": "cal/[mol.C]"}, - {"label": "BTU/[lbmol.R]", "name": "BTU/[lbmol.R]"}, - ], - }, - { - "name": "cakeresistance", - "label": "Cake Resistance", - "units": [ - {"label": "m/kg", "name": "m/kg"}, - {"label": "ft/lbm", "name": "ft/lbm"}, - {"label": "cm/g", "name": "cm/g"}, - ], - }, - { - "name": "heatCapacityCp", - "label": "Cp", - "units": [ - {"label": "kJ/[kg.K]", "name": "kJ/[kg.K]"}, - {"label": "cal/[g.C]", "name": "cal/[g.C]"}, - {"label": "BTU/[lbm.R]", "name": "BTU/[lbm.R]"}, - ], - }, - { - "name": "molar_enthalpy", - "label": "Molar Enthalpy", - "units": [ - {"label": "kJ/kmol", "name": "kJ/kmol"}, - {"label": "cal/mol", "name": "cal/mol"}, - {"label": "BTU/lbmol", "name": "BTU/lbmol"}, - {"label": "J/mol", "name": "J/mol"}, - ], - }, - { - "name": "surfaceTension", - "label": "Surface Tension", - "units": [ - {"label": "N/m", "name": "N/m"}, - {"label": "dyn/cm", "name": "dyn/cm"}, - {"label": "lbf/in", "name": "lbf/in"}, - ], - }, - { - "name": "volumetricFlow", - "label": "Volumetric Flow", - "units": [ - {"label": "m3/s", "name": "m3/s"}, - {"label": "ft3/s", "name": "ft3/s"}, - {"label": "cm3/s", "name": "cm3/s"}, - {"label": "m3/h", "name": "m3/h"}, - {"label": "m3/d", "name": "m3/d"}, - {"label": "bbl/h", "name": "bbl/h"}, - {"label": "bbl/d", "name": "bbl/d"}, - {"label": "ft3/min", "name": "ft3/min"}, - {"label": "ft3/d", "name": "ft3/d"}, - {"label": "gal[UK]/h", "name": "gal[UK]/h"}, - {"label": "gal[UK]/min", "name": "gal[UK]/min"}, - {"label": "gal[UK]/s", "name": "gal[UK]/s"}, - {"label": "gal[US]/h", "name": "gal[US]/h"}, - {"label": "gal[US]/min", "name": "gal[US]/min"}, - {"label": "gal[US]/s", "name": "gal[US]/s"}, - {"label": "L/h", "name": "L/h"}, - {"label": "L/min", "name": "L/min"}, - {"label": "L/s", "name": "L/s"}, - ], - }, - { - "name": "compressibility", - "label": "Compressibility", - "units": [ - {"label": "1/Pa", "name": "1/Pa"}, - {"label": "1/atm", "name": "1/atm"}, - {"label": "1/kPa", "name": "1/kPa"}, - {"label": "1/bar", "name": "1/bar"}, - {"label": "1/MPa", "name": "1/MPa"}, - {"label": "1/psi", "name": "1/psi"}, - ], - }, - { - "name": "molecularWeight", - "label": "Molecular Weight", - "units": [ - {"label": "kg/kmol", "name": "kg/kmol"}, - {"label": "g/mol", "name": "g/mol"}, - {"label": "lbm/lbmol", "name": "lbm/lbmol"}, - ], - }, - { - "name": "mediumresistance", - "label": "Medium Resistance", - "units": [ - {"label": "m-1", "name": "m-1"}, - {"label": "cm-1", "name": "cm-1"}, - {"label": "ft-1", "name": "ft-1"}, - ], - }, - { - "name": "heat_transf_coeff", - "label": "Heat Transfer Coefficient", - "units": [ - {"label": "W/[m2.K]", "name": "W/[m2.K]"}, - {"label": "cal/[cm2.s.C]", "name": "cal/[cm2.s.C]"}, - {"label": "BTU/[ft2.h.R]", "name": "BTU/[ft2.h.R]"}, - ], - }, - { - "name": "reac_rate_heterog", - "label": "Reaction Rate Heterogeneous", - "units": [ - {"label": "kmol/[kg.s]", "name": "kmol/[kg.s]"}, - {"label": "kmol/[kg.min.]", "name": "kmol/[kg.min.]"}, - {"label": "kmol/[kg.h]", "name": "kmol/[kg.h]"}, - {"label": "mol/[kg.s]", "name": "mol/[kg.s]"}, - {"label": "mol/[kg.min.]", "name": "mol/[kg.min.]"}, - {"label": "mol/[kg.h]", "name": "mol/[kg.h]"}, - {"label": "lbmol/[lbm.h]", "name": "lbmol/[lbm.h]"}, - ], - }, - { - "name": "cinematic_viscosity", - "label": "Kinematic Viscosity", - "units": [ - {"label": "m2/s", "name": "m2/s"}, - {"label": "cSt", "name": "cSt"}, - {"label": "ft2/s", "name": "ft2/s"}, - {"label": "mm2/s", "name": "mm2/s"}, - {"label": "cm2/s", "name": "cm2/s"}, - ], - }, - { - "name": "thermalConductivity", - "label": "Thermal Conductivity", - "units": [ - {"label": "W/[m.K]", "name": "W/[m.K]"}, - {"label": "cal/[cm.s.C]", "name": "cal/[cm.s.C]"}, - {"label": "BTU/[ft.h.R]", "name": "BTU/[ft.h.R]"}, - ], - }, - { - "name": "jouleThomsonCoefficient", - "label": "Joule Thomson Coefficient", - "units": [ - {"label": "K/Pa", "name": "K/Pa"}, - {"label": "F/psi", "name": "F/psi"}, - {"label": "C/atm", "name": "C/atm"}, - ], - }, ], } From e01cec358d46fcb75c0462b20995f2184e3907ad Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 2 Dec 2024 13:52:35 +0100 Subject: [PATCH 038/122] fix docstrings --- cognite/client/_api/simulators/simulator_models.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 2fed01cab..dfb0481e4 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -79,12 +79,12 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim Examples: - Get simulator model revision by id: + Get simulator model revision by id:: >>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> res = client.simulators.models.revisions.retrieve(id=123) - Get simulator model revision by external id: + Get simulator model revision by external id:: >>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> res = client.simulators.models.revisions.retrieve(external_id="abcdef") @@ -196,18 +196,17 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim Examples: - List simulator models: - + List simulator models:: >>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> res = client.simulators.models.list() - Get simulator model by id: + Get simulator model by id:: >>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> res = client.simulators.models.retrieve(id=1) - Get simulator model by external id: + Get simulator model by external id:: >>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> res = client.simulators.models.retrieve(external_id="1") From e9bde707fb82ad187d11812a0c0445387c4c27d1 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 2 Dec 2024 13:56:45 +0100 Subject: [PATCH 039/122] fix docstrings --- .../_api/simulators/simulator_models.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index dfb0481e4..efcfbd95e 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -196,20 +196,20 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim Examples: - List simulator models:: - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> res = client.simulators.models.list() + List simulator models: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.list() - Get simulator model by id:: - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> res = client.simulators.models.retrieve(id=1) + Get simulator model by id: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.retrieve(id=1) - Get simulator model by external id:: - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> res = client.simulators.models.retrieve(external_id="1") + Get simulator model by external id: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.retrieve(external_id="1") """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() From 47d33a762b8cc9e58ce2b9b5fdd13b9a9f10115d Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 2 Dec 2024 14:00:37 +0100 Subject: [PATCH 040/122] fix docstrings --- cognite/client/_api/simulators/simulator_models.py | 4 ++-- cognite/client/_api/simulators/simulator_routines.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index efcfbd95e..10eb485d2 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -79,12 +79,12 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim Examples: - Get simulator model revision by id:: + Get simulator model revision by id: >>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> res = client.simulators.models.revisions.retrieve(id=123) - Get simulator model revision by external id:: + Get simulator model revision by external id: >>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> res = client.simulators.models.revisions.retrieve(external_id="abcdef") diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 6fe4ea2d9..ba7ec561c 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -88,7 +88,6 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim >>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> res = client.simulators.routines.revisions.retrieve(external_ids="abcdef") - """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() return self._retrieve_multiple( From 985e1ffa33c004b72d56e435bc25c27effc20005 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 2 Dec 2024 14:05:54 +0100 Subject: [PATCH 041/122] fix docstrings --- cognite/client/_api/simulators/simulator_models.py | 8 -------- cognite/client/_api/simulators/simulator_routines.py | 4 ---- 2 files changed, 12 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 10eb485d2..b02c5449a 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -85,8 +85,6 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim >>> res = client.simulators.models.revisions.retrieve(id=123) Get simulator model revision by external id: - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() >>> res = client.simulators.models.revisions.retrieve(external_id="abcdef") """ @@ -122,8 +120,6 @@ def retrieve_multiple( >>> res = client.simulators.models.revisions.retrieve_multiple(ids=[1, 2, 3]) Get simulator model revisions by external ids: - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() >>> res = client.simulators.models.revisions.retrieve_multiple(external_ids=["abc", "def"]) """ identifiers = IdentifierSequence.load(ids=ids, external_ids=external_ids) @@ -202,13 +198,9 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim >>> res = client.simulators.models.list() Get simulator model by id: - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() >>> res = client.simulators.models.retrieve(id=1) Get simulator model by external id: - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() >>> res = client.simulators.models.retrieve(external_id="1") """ diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index ba7ec561c..27451fcf3 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -85,8 +85,6 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim >>> res = client.simulators.routines.revisions.retrieve(ids=123) Get simulator routine revision by external id: - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() >>> res = client.simulators.routines.revisions.retrieve(external_ids="abcdef") """ identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton() @@ -121,8 +119,6 @@ def retrieve_multiple( >>> res = client.simulators.routines.revisions.retrieve_multiple(ids=[1, 2, 3]) Get simulator routine revisions by external id: - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() >>> res = client.simulators.routines.revisions.retrieve_multiple(external_ids=["abc", "def"]) """ identifiers = IdentifierSequence.load(ids=ids, external_ids=external_ids) From ce5c8f1400baea634479922c61318935cda3a37a Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 2 Dec 2024 14:43:22 +0100 Subject: [PATCH 042/122] fix test --- cognite/client/_api/simulators/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cognite/client/_api/simulators/__init__.py b/cognite/client/_api/simulators/__init__.py index e69de29bb..6c43ea250 100644 --- a/cognite/client/_api/simulators/__init__.py +++ b/cognite/client/_api/simulators/__init__.py @@ -0,0 +1 @@ +from __future__ import annotations \ No newline at end of file From 0a37df1293c41bb1178e3e62f9d22832f569c3dc Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 2 Dec 2024 15:20:50 +0100 Subject: [PATCH 043/122] fix model revisions to writable class --- .../data_classes/simulators/simulators.py | 323 ++++++++++++++---- 1 file changed, 264 insertions(+), 59 deletions(-) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 83f636f33..92f859f01 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -709,25 +709,23 @@ def __hash__(self) -> int: return hash(self.external_id) -class SimulatorModelRevision(CogniteResource): +class SimulatorModelRevisionCore(WriteableCogniteResource["SimulatorModelRevisionWrite"], ABC): def __init__( self, - id: int, - external_id: str, - simulator_external_id: str, - model_external_id: str, - data_set_id: int, - file_id: int, - created_by_user_id: str, - status: str, - created_time: int, - last_updated_time: int, - version_number: int, - log_id: int, + external_id: str | None = None, + simulator_external_id: str | None = None, + model_external_id: str | None = None, + data_set_id: int | None = None, + file_id: int | None = None, + created_by_user_id: str | None = None, + status: str | None = None, + created_time: int | None = None, + last_updated_time: int | None = None, + version_number: int | None = None, + log_id: int | None = None, description: str | None = None, status_message: str | None = None, ) -> None: - self.id = id self.external_id = external_id self.simulator_external_id = simulator_external_id self.model_external_id = model_external_id @@ -744,25 +742,125 @@ def __init__( @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + instance = super()._load(resource, cognite_client) + return instance + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +class SimulatorModelRevisionWrite(SimulatorModelRevisionCore): + def __init__( + self, + external_id: str | None = None, + model_external_id: str | None = None, + file_id: int | None = None, + description: str | None = None, + ) -> None: + super().__init__( + external_id=external_id, + model_external_id=model_external_id, + file_id=file_id, + description=description, + ) + + def as_write(self) -> SimulatorModelRevisionWrite: + """Returns a writeable version of this resource""" + return self + + @classmethod + def _load( + cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None + ) -> SimulatorModelRevisionWrite: return cls( - id=resource["id"], external_id=resource["externalId"], - simulator_external_id=resource["simulatorExternalId"], model_external_id=resource["modelExternalId"], - data_set_id=resource["dataSetId"], file_id=resource["fileId"], - created_by_user_id=resource["createdByUserId"], - status=resource["status"], - created_time=resource["createdTime"], - last_updated_time=resource["lastUpdatedTime"], - version_number=resource["versionNumber"], - log_id=resource["logId"], description=resource.get("description"), - status_message=resource.get("statusMessage"), ) + +class SimulatorModelRevision(SimulatorModelRevisionCore): + """ + + Simulator model revisions track changes and updates to a simulator model over time. + Each revision ensures that modifications to models are traceable and allows users to understand the evolution of a given model. + + Args: + external_id (str | None): External id of the simulator model revision + simulator_external_id (str | None): No description. + model_external_id (str | None): External id of the associated simulator model + data_set_id (int | None): The id of the dataset associated with the simulator model revision + file_id (int | None): The id of the file associated with the simulator model revision + created_by_user_id (str | None): The id of the user who created the simulator model revision + status (str | None): The status of the simulator model revision + created_time (int | None): The time when the simulator model revision was created + last_updated_time (int | None): The time when the simulator model revision was last updated + version_number (int | None): The version number of the simulator model revision + log_id (int | None): The id of the log associated with the simulator model revision + description (str | None): The description of the simulator model revision + status_message (str | None): The current status of the model revision + + """ + + def __init__( + self, + external_id: str | None = None, + simulator_external_id: str | None = None, + model_external_id: str | None = None, + data_set_id: int | None = None, + file_id: int | None = None, + created_by_user_id: str | None = None, + status: str | None = None, + created_time: int | None = None, + last_updated_time: int | None = None, + version_number: int | None = None, + log_id: int | None = None, + description: str | None = None, + status_message: str | None = None, + ) -> None: + super().__init__( + external_id=external_id, + simulator_external_id=simulator_external_id, + model_external_id=model_external_id, + data_set_id=data_set_id, + file_id=file_id, + created_by_user_id=created_by_user_id, + status=status, + created_time=created_time, + last_updated_time=last_updated_time, + version_number=version_number, + log_id=log_id, + description=description, + status_message=status_message, + ) + # id/created_time/last_updated_time are required when using the class to read, + # but don't make sense passing in when creating a new object. So in order to make the typing + # correct here (i.e. int and not Optional[int]), we force the type to be int rather than + # Optional[int]. + self.id: int = id # type: ignore + self.created_time: int = created_time # type: ignore + self.last_updated_time: int = last_updated_time # type: ignore + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + instance = super()._load(resource, cognite_client) + return instance + + def as_write(self) -> SimulatorModelRevisionWrite: + """Returns this SimulatorModelRevision in its writing version.""" + return SimulatorModelRevisionWrite( + external_id=self.external_id, + model_external_id=self.model_external_id, + file_id=self.file_id, + description=self.description, + ) + + def __hash__(self) -> int: + return hash(self.external_id) + def dump(self, camel_case: bool = True) -> dict[str, Any]: - return super().dump(camel_case=camel_case) + return super().dump(camel_case) class SimulatorRoutineRevisionCore(WriteableCogniteResource["SimulatorRoutineRevisionWrite"], ABC): @@ -896,7 +994,7 @@ def as_write(self) -> SimulatorRoutineRevisionWrite: ) -class SimulatorModel(CogniteResource): +class SimulatorModelCore(WriteableCogniteResource["SimulatorModelWrite"], ABC): """ The simulator model resource represents an asset modeled in a simulator. This asset could range from a pump or well to a complete processing facility or refinery. @@ -907,63 +1005,152 @@ class SimulatorModel(CogniteResource): Simulator model revisions track changes and updates to a simulator model over time. Each revision ensures that modifications to models are traceable and allows users to understand the evolution of a given model. - Limitations: - - A project can have a maximum of 1000 simulator models - - Each simulator model can have a maximum of 200 revisions - - This is the read/response format of a simulator model. Args: - id (int): A unique id of a simulator model - external_id (str): External id of the simulator model - simulator_external_id (str): External id of the associated simulator - data_set_id (int): The id of the dataset associated with the simulator model - created_time (int): The time when the simulator model was created - last_updated_time (int): The time when the simulator model was last updated - name (str): The name of the simulator model - type_key (str | None): The type key of the simulator model + external_id (str | None): External id of the simulator model + simulator_external_id (str | None): External id of the associated simulator + data_set_id (int | None): The id of the dataset associated with the simulator model + name (str | None): The name of the simulator model + type (str | None): The type key of the simulator model description (str | None): The description of the simulator model """ def __init__( self, - id: int, - external_id: str, - simulator_external_id: str, - data_set_id: int, - created_time: int, - last_updated_time: int, - name: str, - type_key: str | None = None, + external_id: str | None = None, + simulator_external_id: str | None = None, + data_set_id: int | None = None, + name: str | None = None, + type: str | None = None, description: str | None = None, ) -> None: - self.id = id self.external_id = external_id self.simulator_external_id = simulator_external_id self.data_set_id = data_set_id - self.created_time = created_time - self.last_updated_time = last_updated_time self.name = name - self.type_key = type_key + self.type = type self.description = description @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + instance = super()._load(resource, cognite_client) + return instance + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case=camel_case) + + +class SimulatorModelWrite(SimulatorModelCore): + def __init__( + self, + external_id: str | None = None, + simulator_external_id: str | None = None, + data_set_id: int | None = None, + name: str | None = None, + type: str | None = None, + description: str | None = None, + ) -> None: + super().__init__( + external_id=external_id, + simulator_external_id=simulator_external_id, + data_set_id=data_set_id, + name=name, + type=type, + description=description, + ) + + @classmethod + def _load(cls, resource: dict, cognite_client: CogniteClient | None = None) -> SimulatorModelWrite: return cls( - id=resource["id"], external_id=resource["externalId"], simulator_external_id=resource["simulatorExternalId"], - name=resource["name"], data_set_id=resource["dataSetId"], - created_time=resource["createdTime"], - last_updated_time=resource["lastUpdatedTime"], - type_key=resource.get("typeKey"), + name=resource["name"], + type=resource.get("typeKey"), description=resource.get("description"), ) + def as_write(self) -> SimulatorModelWrite: + """Returns self.""" + return self + + +class SimulatorModel(SimulatorModelCore): + """ + The simulator model resource represents an asset modeled in a simulator. + This asset could range from a pump or well to a complete processing facility or refinery. + The simulator model is the root of its associated revisions, routines, runs, and results. + The dataset assigned to a model is inherited by its children. Deleting a model also deletes all its children, thereby + maintaining the integrity and hierarchy of the simulation data. + + Simulator model revisions track changes and updates to a simulator model over time. + Each revision ensures that modifications to models are traceable and allows users to understand the evolution of a given model. + + + This is the read/response format of a simulator model. + + Args: + external_id (str | None): External id of the simulator model + simulator_external_id (str | None): External id of the associated simulator + data_set_id (int | None): The id of the dataset associated with the simulator model + name (str | None): The name of the simulator model + id (int | None): A unique id of a simulator model + type (str | None): The type key of the simulator model + description (str | None): The description of the simulator model + created_time (int | None): The time when the simulator model was created + last_updated_time (int | None): The time when the simulator model was last updated + """ + + def __init__( + self, + external_id: str | None = None, + simulator_external_id: str | None = None, + data_set_id: int | None = None, + name: str | None = None, + id: int | None = None, + type: str | None = None, + description: str | None = None, + created_time: int | None = None, + last_updated_time: int | None = None, + ) -> None: + super().__init__( + external_id=external_id, + simulator_external_id=simulator_external_id, + data_set_id=data_set_id, + name=name, + type=type, + description=description, + ) + # id/created_time/last_updated_time are required when using the class to read, + # but don't make sense passing in when creating a new object. So in order to make the typing + # correct here (i.e. int and not Optional[int]), we force the type to be int rather than + # Optional[int]. + self.id: int = id # type: ignore + self.created_time: int = created_time # type: ignore + self.last_updated_time: int = last_updated_time # type: ignore + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + instance = super()._load(resource, cognite_client) + return instance + + def as_write(self) -> SimulatorModelWrite: + """Returns this SimulatorModel in its writing version.""" + return SimulatorModelWrite( + external_id=self.external_id, + simulator_external_id=self.simulator_external_id, + data_set_id=self.data_set_id, + name=self.name, + type=self.type, + description=self.description, + ) + + def __hash__(self) -> int: + return hash(self.external_id) + def dump(self, camel_case: bool = True) -> dict[str, Any]: - return super().dump(camel_case=camel_case) + return super().dump(camel_case) class SimulationRun(CogniteResource): @@ -1269,13 +1456,31 @@ def as_write(self) -> SimulatorIntegrationWriteList: ) -class SimulatorModelList(CogniteResourceList[SimulatorModel]): +class SimulatorModelWriteList(CogniteResourceList[SimulatorModelWrite], ExternalIDTransformerMixin): + _RESOURCE = SimulatorModelWrite + + +class SimulatorModelList(WriteableCogniteResourceList[SimulatorModelWrite, SimulatorModel], IdTransformerMixin): _RESOURCE = SimulatorModel + def as_write(self) -> SimulatorModelWriteList: + return SimulatorModelWriteList([a.as_write() for a in self.data], cognite_client=self._get_cognite_client()) + -class SimulatorModelRevisionList(CogniteResourceList[SimulatorModelRevision]): +class SimulatorModelRevisionWriteList(CogniteResourceList[SimulatorModelRevisionWrite], ExternalIDTransformerMixin): + _RESOURCE = SimulatorModelRevisionWrite + + +class SimulatorModelRevisionList( + WriteableCogniteResourceList[SimulatorModelRevisionWrite, SimulatorModelRevision], IdTransformerMixin +): _RESOURCE = SimulatorModelRevision + def as_write(self) -> SimulatorModelRevisionWriteList: + return SimulatorModelRevisionWriteList( + [a.as_write() for a in self.data], cognite_client=self._get_cognite_client() + ) + class SimulationRunsList(CogniteResourceList[SimulationRun]): _RESOURCE = SimulationRun From 5fff3a419dd574ce19cd080c875443a601cabe19 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 2 Dec 2024 15:57:05 +0100 Subject: [PATCH 044/122] fix mock --- cognite/client/testing.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cognite/client/testing.py b/cognite/client/testing.py index d33c10db0..ee869db97 100644 --- a/cognite/client/testing.py +++ b/cognite/client/testing.py @@ -43,6 +43,10 @@ from cognite.client._api.raw import RawAPI, RawDatabasesAPI, RawRowsAPI, RawTablesAPI from cognite.client._api.relationships import RelationshipsAPI from cognite.client._api.sequences import SequencesAPI, SequencesDataAPI +from cognite.client._api.simulators.simulation_runs import SimulatorRunsAPI +from cognite.client._api.simulators.simulator_integrations import SimulatorIntegrationsAPI +from cognite.client._api.simulators.simulator_models import SimulatorModelRevisionsAPI, SimulatorModelsAPI +from cognite.client._api.simulators.simulator_routines import SimulatorRoutineRevisionsAPI, SimulatorRoutinesAPI from cognite.client._api.simulators.simulators import SimulatorsAPI from cognite.client._api.synthetic_time_series import SyntheticDatapointsAPI from cognite.client._api.templates import ( @@ -144,6 +148,12 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.relationships = MagicMock(spec_set=RelationshipsAPI) self.simulators = MagicMock(spec=SimulatorsAPI) + self.models = MagicMock(spec=SimulatorModelsAPI) + self.models.revisions = MagicMock(spec_set=SimulatorModelRevisionsAPI) + self.runs = MagicMock(spec=SimulatorRunsAPI) + self.integrations = MagicMock(spec=SimulatorIntegrationsAPI) + self.routines = MagicMock(spec=SimulatorRoutinesAPI) + self.routines.revisions = MagicMock(spec_set=SimulatorRoutineRevisionsAPI) self.sequences = MagicMock(spec=SequencesAPI) self.sequences.data = MagicMock(spec_set=SequencesDataAPI) From 6b8275114cc72dd7f8013d147c1d4f44af7a641f Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 2 Dec 2024 16:00:40 +0100 Subject: [PATCH 045/122] fix mock --- cognite/client/testing.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cognite/client/testing.py b/cognite/client/testing.py index ee869db97..1e50932c5 100644 --- a/cognite/client/testing.py +++ b/cognite/client/testing.py @@ -148,12 +148,12 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.relationships = MagicMock(spec_set=RelationshipsAPI) self.simulators = MagicMock(spec=SimulatorsAPI) - self.models = MagicMock(spec=SimulatorModelsAPI) - self.models.revisions = MagicMock(spec_set=SimulatorModelRevisionsAPI) - self.runs = MagicMock(spec=SimulatorRunsAPI) - self.integrations = MagicMock(spec=SimulatorIntegrationsAPI) - self.routines = MagicMock(spec=SimulatorRoutinesAPI) - self.routines.revisions = MagicMock(spec_set=SimulatorRoutineRevisionsAPI) + self.simulators.models = MagicMock(spec=SimulatorModelsAPI) + self.simulators.models.revisions = MagicMock(spec_set=SimulatorModelRevisionsAPI) + self.simulators.runs = MagicMock(spec=SimulatorRunsAPI) + self.simulators.integrations = MagicMock(spec=SimulatorIntegrationsAPI) + self.simulators.routines = MagicMock(spec=SimulatorRoutinesAPI) + self.simulators.routines.revisions = MagicMock(spec_set=SimulatorRoutineRevisionsAPI) self.sequences = MagicMock(spec=SequencesAPI) self.sequences.data = MagicMock(spec_set=SequencesDataAPI) From 774252b49cc000ebbd7743531106f75e737a80fc Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 3 Dec 2024 14:03:22 +0100 Subject: [PATCH 046/122] fix spec definition for mock client --- cognite/client/_api/simulators/simulator_integrations.py | 3 ++- cognite/client/testing.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index 6c9cc0137..5cef2845b 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -12,7 +12,8 @@ from cognite.client.utils._experimental import FeaturePreviewWarning if TYPE_CHECKING: - from cognite.client import ClientConfig, CogniteClient + from cognite.client import CogniteClient + from cognite.client.config import ClientConfig class SimulatorIntegrationsAPI(APIClient): diff --git a/cognite/client/testing.py b/cognite/client/testing.py index 1e50932c5..74cabb499 100644 --- a/cognite/client/testing.py +++ b/cognite/client/testing.py @@ -148,11 +148,11 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.relationships = MagicMock(spec_set=RelationshipsAPI) self.simulators = MagicMock(spec=SimulatorsAPI) + self.simulators.runs = MagicMock(spec_set=SimulatorRunsAPI) + self.simulators.integrations = MagicMock(spec_set=SimulatorIntegrationsAPI) self.simulators.models = MagicMock(spec=SimulatorModelsAPI) - self.simulators.models.revisions = MagicMock(spec_set=SimulatorModelRevisionsAPI) - self.simulators.runs = MagicMock(spec=SimulatorRunsAPI) - self.simulators.integrations = MagicMock(spec=SimulatorIntegrationsAPI) self.simulators.routines = MagicMock(spec=SimulatorRoutinesAPI) + self.simulators.models.revisions = MagicMock(spec_set=SimulatorModelRevisionsAPI) self.simulators.routines.revisions = MagicMock(spec_set=SimulatorRoutineRevisionsAPI) self.sequences = MagicMock(spec=SequencesAPI) From 8991a383a4093356f0760aaf4c73253921225bc2 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 3 Dec 2024 15:22:47 +0100 Subject: [PATCH 047/122] fix meta tests for simulators --- cognite/client/_api/simulators/__init__.py | 2 +- cognite/client/_api_client.py | 1 + cognite/client/data_classes/simulators/__init__.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/__init__.py b/cognite/client/_api/simulators/__init__.py index 6c43ea250..9d48db4f9 100644 --- a/cognite/client/_api/simulators/__init__.py +++ b/cognite/client/_api/simulators/__init__.py @@ -1 +1 @@ -from __future__ import annotations \ No newline at end of file +from __future__ import annotations diff --git a/cognite/client/_api_client.py b/cognite/client/_api_client.py index 135c2bf7f..910e32fac 100644 --- a/cognite/client/_api_client.py +++ b/cognite/client/_api_client.py @@ -99,6 +99,7 @@ class APIClient: "geospatial/(compute|crs/byids|featuretypes/(byids|list))", "geospatial/featuretypes/[A-Za-z][A-Za-z0-9_]{0,31}/features/(aggregate|list|byids|search|search-streaming|[A-Za-z][A-Za-z0-9_]{0,255}/rasters/[A-Za-z][A-Za-z0-9_]{0,31})", "transformations/(filter|byids|jobs/byids|schedules/byids|query/run)", + "simulators/.*", "extpipes/(list|byids|runs/list)", "workflows/.*", "hostedextractors/.*", diff --git a/cognite/client/data_classes/simulators/__init__.py b/cognite/client/data_classes/simulators/__init__.py index e69de29bb..9d48db4f9 100644 --- a/cognite/client/data_classes/simulators/__init__.py +++ b/cognite/client/data_classes/simulators/__init__.py @@ -0,0 +1 @@ +from __future__ import annotations From e4d437e0c0c8c0e118f95e86a50ac0acb5adb2e4 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 3 Dec 2024 15:28:46 +0100 Subject: [PATCH 048/122] fix sim runs --- .../data_classes/simulators/simulators.py | 247 +++++++++++++----- 1 file changed, 186 insertions(+), 61 deletions(-) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 92f859f01..28996ad83 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -9,7 +9,6 @@ from cognite.client.data_classes._base import ( CogniteObject, - CogniteResource, CogniteResourceList, ExternalIDTransformerMixin, IdTransformerMixin, @@ -1153,65 +1152,32 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case) -class SimulationRun(CogniteResource): - """ - Every time a simulation routine executes, a simulation run object is created. - This object ensures that each execution of a routine is documented and traceable. - Each run has an associated simulation data resource, which stores the inputs and outputs of a - simulation run, capturing the values set into and read from the simulator model to ensure - the traceability and integrity of the simulation data. - - Simulation runs provide a historical record of the simulations performed, allowing users to analyze - and compare different runs, track changes over time, and make informed decisions based on the simulation results. +class SimulationRunCore(WriteableCogniteResource["SimulationRunWrite"], ABC): + """""" - Limitations: - * A retention policy is in place for simulation runs, allowing up to 100000 entries. - * Once this limit is reached, the oldest runs will be deleted to accommodate new runs. - - This is the read/response format of a simulation run. - - Args: - id (int): A unique id of a simulation run - simulator_external_id (str): External id of the associated simulator - simulator_integration_external_id (str): External id of the associated simulator integration - model_external_id (str): External id of the associated simulator model - model_revision_external_id (str): External id of the associated simulator model revision - routine_external_id (str): External id of the associated simulator routine - routine_revision_external_id (str): External id of the associated simulator routine revision - run_time (int | None): Run time in milliseconds. Reference timestamp used for data pre-processing and data sampling. - simulation_time (int | None): Simulation time in milliseconds. Timestamp when the input data was sampled. Used for indexing input and output time series. - status (str): The status of the simulation run - status_message (str | None): The status message of the simulation run - data_set_id (int): The id of the dataset associated with the simulation run - run_type (str): The type of the simulation run - user_id (str): The id of the user who executed the simulation run - log_id (int): The id of the log associated with the simulation run - created_time (int): The number of milliseconds since epoch - last_updated_time (int): The number of milliseconds since epoch + """_summary_ + Returns: + _type_: _description_ """ def __init__( self, - id: int, - simulator_external_id: str, - simulator_integration_external_id: str, - model_external_id: str, - model_revision_external_id: str, - routine_external_id: str, - routine_revision_external_id: str, - run_time: int | None, - simulation_time: int | None, - status: str, - status_message: str | None, - data_set_id: int, - run_type: str, - user_id: str, - log_id: int, - created_time: int, - last_updated_time: int, + simulator_external_id: str | None = None, + simulator_integration_external_id: str | None = None, + model_external_id: str | None = None, + model_revision_external_id: str | None = None, + routine_external_id: str | None = None, + routine_revision_external_id: str | None = None, + run_time: int | None = None, + simulation_time: int | None = None, + status: str | None = None, + status_message: str | None = None, + data_set_id: int | None = None, + run_type: str | None = None, + user_id: str | None = None, + log_id: int | None = None, ) -> None: - self.id = id self.simulator_external_id = simulator_external_id self.simulator_integration_external_id = simulator_integration_external_id self.model_external_id = model_external_id @@ -1226,34 +1192,186 @@ def __init__( self.run_type = run_type self.user_id = user_id self.log_id = log_id - self.created_time = created_time - self.last_updated_time = last_updated_time + + @classmethod + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + instance = super()._load(resource, cognite_client) + return instance + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + return super().dump(camel_case) + + +class SimulationRunWrite(SimulationRunCore): + def __init__( + self, + simulator_external_id: str | None = None, + simulator_integration_external_id: str | None = None, + model_external_id: str | None = None, + model_revision_external_id: str | None = None, + routine_external_id: str | None = None, + routine_revision_external_id: str | None = None, + run_time: int | None = None, + simulation_time: int | None = None, + status: str | None = None, + status_message: str | None = None, + data_set_id: int | None = None, + run_type: str | None = None, + user_id: str | None = None, + log_id: int | None = None, + ) -> None: + super().__init__( + simulator_external_id=simulator_external_id, + simulator_integration_external_id=simulator_integration_external_id, + model_external_id=model_external_id, + model_revision_external_id=model_revision_external_id, + routine_external_id=routine_external_id, + routine_revision_external_id=routine_revision_external_id, + run_time=run_time, + simulation_time=simulation_time, + status=status, + status_message=status_message, + data_set_id=data_set_id, + run_type=run_type, + user_id=user_id, + log_id=log_id, + ) @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: return cls( - id=resource["id"], simulator_external_id=resource["simulatorExternalId"], simulator_integration_external_id=resource["simulatorIntegrationExternalId"], model_external_id=resource["modelExternalId"], model_revision_external_id=resource["modelRevisionExternalId"], routine_external_id=resource["routineExternalId"], routine_revision_external_id=resource["routineRevisionExternalId"], - run_time=resource.get("runTime"), - simulation_time=resource.get("simulationTime"), + run_time=resource["runTime"], + simulation_time=resource["simulationTime"], status=resource["status"], status_message=resource.get("statusMessage"), data_set_id=resource["dataSetId"], run_type=resource["runType"], user_id=resource["userId"], log_id=resource["logId"], - created_time=resource["createdTime"], - last_updated_time=resource["lastUpdatedTime"], ) + def as_write(self) -> SimulationRunWrite: + """Returns self.""" + return self + + +class SimulationRun(SimulationRunCore): + """ + Every time a simulation routine executes, a simulation run object is created. + This object ensures that each execution of a routine is documented and traceable. + Each run has an associated simulation data resource, which stores the inputs and outputs of a + simulation run, capturing the values set into and read from the simulator model to ensure + the traceability and integrity of the simulation data. + + Simulation runs provide a historical record of the simulations performed, allowing users to analyze + and compare different runs, track changes over time, and make informed decisions based on the simulation results. + + Limitations: + * A retention policy is in place for simulation runs, allowing up to 100000 entries. + * Once this limit is reached, the oldest runs will be deleted to accommodate new runs. + + This is the read/response format of a simulation run. + + Args: + simulator_external_id (str | None): External id of the associated simulator + simulator_integration_external_id (str | None): External id of the associated simulator integration + model_external_id (str | None): External id of the associated simulator model + model_revision_external_id (str | None): External id of the associated simulator model revision + routine_external_id (str | None): External id of the associated simulator routine + routine_revision_external_id (str | None): External id of the associated simulator routine revision + run_time (int | None): Run time in milliseconds. Reference timestamp used for data pre-processing and data sampling. + simulation_time (int | None): Simulation time in milliseconds. Timestamp when the input data was sampled. Used for indexing input and output time series. + status (str | None): The status of the simulation run + status_message (str | None): The status message of the simulation run + data_set_id (int | None): The id of the dataset associated with the simulation run + run_type (str | None): The type of the simulation run + user_id (str | None): The id of the user who executed the simulation run + log_id (int | None): The id of the log associated with the simulation run + id (int | None): A unique id of a simulation run + created_time (int | None): The number of milliseconds since epoch + last_updated_time (int | None): The number of milliseconds since epoch + + """ + + def __init__( + self, + simulator_external_id: str | None = None, + simulator_integration_external_id: str | None = None, + model_external_id: str | None = None, + model_revision_external_id: str | None = None, + routine_external_id: str | None = None, + routine_revision_external_id: str | None = None, + run_time: int | None = None, + simulation_time: int | None = None, + status: str | None = None, + status_message: str | None = None, + data_set_id: int | None = None, + run_type: str | None = None, + user_id: str | None = None, + log_id: int | None = None, + id: int | None = None, + created_time: int | None = None, + last_updated_time: int | None = None, + ) -> None: + super().__init__( + simulator_external_id=simulator_external_id, + simulator_integration_external_id=simulator_integration_external_id, + model_external_id=model_external_id, + model_revision_external_id=model_revision_external_id, + routine_external_id=routine_external_id, + routine_revision_external_id=routine_revision_external_id, + run_time=run_time, + simulation_time=simulation_time, + status=status, + status_message=status_message, + data_set_id=data_set_id, + run_type=run_type, + user_id=user_id, + log_id=log_id, + ) + # id/created_time/last_updated_time are required when using the class to read, + # but don't make sense passing in when creating a new object. So in order to make the typing + # correct here (i.e. int and not Optional[int]), we force the type to be int rather than + # Optional[int]. + # TODO: In the next major version we can make these properties required in the constructor + self.id: int = id # type: ignore + self.created_time: int = created_time # type: ignore + self.last_updated_time: int = last_updated_time # type: ignore + + @classmethod + def _load(cls, resource: dict, cognite_client: CogniteClient | None = None) -> SimulationRun: + return super()._load(resource, cognite_client) + def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) + def as_write(self): + return SimulationRunWrite( + simulator_external_id=self.simulator_external_id, + simulator_integration_external_id=self.simulator_integration_external_id, + model_external_id=self.model_external_id, + model_revision_external_id=self.model_revision_external_id, + routine_external_id=self.routine_external_id, + routine_revision_external_id=self.routine_revision_external_id, + run_time=self.run_time, + simulation_time=self.simulation_time, + status=self.status, + status_message=self.status_message, + data_set_id=self.data_set_id, + run_type=self.run_type, + user_id=self.user_id, + log_id=self.log_id, + ) + + def __hash__(self) -> int: + return hash(self.id) + class SimulatorRoutineCore(WriteableCogniteResource["SimulatorRoutineWrite"], ABC): """ @@ -1482,5 +1600,12 @@ def as_write(self) -> SimulatorModelRevisionWriteList: ) -class SimulationRunsList(CogniteResourceList[SimulationRun]): +class SimulationRunWriteList(CogniteResourceList[SimulationRunWrite], ExternalIDTransformerMixin): + _RESOURCE = SimulationRunWrite + + +class SimulationRunsList(WriteableCogniteResourceList[SimulationRunWrite, SimulationRun], IdTransformerMixin): _RESOURCE = SimulationRun + + def as_write(self) -> SimulationRunWriteList: + return SimulationRunWriteList([a.as_write() for a in self.data], cognite_client=self._get_cognite_client()) From 00e56c692a30e1edf5335d62f95af1ce63c3799f Mon Sep 17 00:00:00 2001 From: abdullah-cognite <100700755+abdullah-cognite@users.noreply.github.com> Date: Thu, 5 Dec 2024 12:58:01 +0000 Subject: [PATCH 049/122] remove simulationrunwrite --- .../data_classes/simulators/simulators.py | 89 +------------------ 1 file changed, 3 insertions(+), 86 deletions(-) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 28996ad83..b5057d94c 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -9,6 +9,7 @@ from cognite.client.data_classes._base import ( CogniteObject, + CogniteResource, CogniteResourceList, ExternalIDTransformerMixin, IdTransformerMixin, @@ -1152,7 +1153,7 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case) -class SimulationRunCore(WriteableCogniteResource["SimulationRunWrite"], ABC): +class SimulationRunCore(CogniteResource, ABC): """""" """_summary_ @@ -1202,65 +1203,6 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case) -class SimulationRunWrite(SimulationRunCore): - def __init__( - self, - simulator_external_id: str | None = None, - simulator_integration_external_id: str | None = None, - model_external_id: str | None = None, - model_revision_external_id: str | None = None, - routine_external_id: str | None = None, - routine_revision_external_id: str | None = None, - run_time: int | None = None, - simulation_time: int | None = None, - status: str | None = None, - status_message: str | None = None, - data_set_id: int | None = None, - run_type: str | None = None, - user_id: str | None = None, - log_id: int | None = None, - ) -> None: - super().__init__( - simulator_external_id=simulator_external_id, - simulator_integration_external_id=simulator_integration_external_id, - model_external_id=model_external_id, - model_revision_external_id=model_revision_external_id, - routine_external_id=routine_external_id, - routine_revision_external_id=routine_revision_external_id, - run_time=run_time, - simulation_time=simulation_time, - status=status, - status_message=status_message, - data_set_id=data_set_id, - run_type=run_type, - user_id=user_id, - log_id=log_id, - ) - - @classmethod - def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - return cls( - simulator_external_id=resource["simulatorExternalId"], - simulator_integration_external_id=resource["simulatorIntegrationExternalId"], - model_external_id=resource["modelExternalId"], - model_revision_external_id=resource["modelRevisionExternalId"], - routine_external_id=resource["routineExternalId"], - routine_revision_external_id=resource["routineRevisionExternalId"], - run_time=resource["runTime"], - simulation_time=resource["simulationTime"], - status=resource["status"], - status_message=resource.get("statusMessage"), - data_set_id=resource["dataSetId"], - run_type=resource["runType"], - user_id=resource["userId"], - log_id=resource["logId"], - ) - - def as_write(self) -> SimulationRunWrite: - """Returns self.""" - return self - - class SimulationRun(SimulationRunCore): """ Every time a simulation routine executes, a simulation run object is created. @@ -1351,24 +1293,6 @@ def _load(cls, resource: dict, cognite_client: CogniteClient | None = None) -> S def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) - def as_write(self): - return SimulationRunWrite( - simulator_external_id=self.simulator_external_id, - simulator_integration_external_id=self.simulator_integration_external_id, - model_external_id=self.model_external_id, - model_revision_external_id=self.model_revision_external_id, - routine_external_id=self.routine_external_id, - routine_revision_external_id=self.routine_revision_external_id, - run_time=self.run_time, - simulation_time=self.simulation_time, - status=self.status, - status_message=self.status_message, - data_set_id=self.data_set_id, - run_type=self.run_type, - user_id=self.user_id, - log_id=self.log_id, - ) - def __hash__(self) -> int: return hash(self.id) @@ -1600,12 +1524,5 @@ def as_write(self) -> SimulatorModelRevisionWriteList: ) -class SimulationRunWriteList(CogniteResourceList[SimulationRunWrite], ExternalIDTransformerMixin): - _RESOURCE = SimulationRunWrite - - -class SimulationRunsList(WriteableCogniteResourceList[SimulationRunWrite, SimulationRun], IdTransformerMixin): +class SimulationRunsList(CogniteResourceList[SimulationRun], ExternalIDTransformerMixin): _RESOURCE = SimulationRun - - def as_write(self) -> SimulationRunWriteList: - return SimulationRunWriteList([a.as_write() for a in self.data], cognite_client=self._get_cognite_client()) From 5342df5093d2c497dc9afd1b5e58d1d1369bbb75 Mon Sep 17 00:00:00 2001 From: abdullah-cognite <100700755+abdullah-cognite@users.noreply.github.com> Date: Thu, 5 Dec 2024 13:00:41 +0000 Subject: [PATCH 050/122] use InternalIdTransformerMixin in run --- cognite/client/data_classes/simulators/simulators.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index b5057d94c..bdc95aa96 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -13,6 +13,7 @@ CogniteResourceList, ExternalIDTransformerMixin, IdTransformerMixin, + InternalIdTransformerMixin, WriteableCogniteResource, WriteableCogniteResourceList, ) @@ -1524,5 +1525,5 @@ def as_write(self) -> SimulatorModelRevisionWriteList: ) -class SimulationRunsList(CogniteResourceList[SimulationRun], ExternalIDTransformerMixin): +class SimulationRunsList(CogniteResourceList[SimulationRun], InternalIdTransformerMixin): _RESOURCE = SimulationRun From 70833abcc8fcee7892313e63c5fc122099cc10fe Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Thu, 5 Dec 2024 18:37:23 +0100 Subject: [PATCH 051/122] fix --- .../data_classes/simulators/__init__.py | 4 + .../data_classes/simulators/simulators.py | 107 ++++++++++++++---- 2 files changed, 90 insertions(+), 21 deletions(-) diff --git a/cognite/client/data_classes/simulators/__init__.py b/cognite/client/data_classes/simulators/__init__.py index 9d48db4f9..d10dd7b1e 100644 --- a/cognite/client/data_classes/simulators/__init__.py +++ b/cognite/client/data_classes/simulators/__init__.py @@ -1 +1,5 @@ from __future__ import annotations + +from cognite.client.data_classes.simulators.simulators import SimulatorRoutineSchedule + +__all__ = ["SimulatorRoutineSchedule"] diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index bdc95aa96..0c32dcb24 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -128,8 +128,10 @@ class SimulatorRoutineSchedule(CogniteObject): @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - instance = super()._load(resource, cognite_client) - return instance + return cls( + enabled=resource["enabled"], + cron_expression=resource.get("cronExpression"), + ) def dump(self, camel_case: bool = True) -> dict[str, Any]: return super().dump(camel_case=camel_case) @@ -212,7 +214,7 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = outputs = [SimulatorRoutineOutput._load(output_, cognite_client) for output_ in resource["outputs"]] return cls( - schedule=SimulatorRoutineSchedule._load(resource["schedule"], cognite_client), + schedule=SimulatorRoutineSchedule.load(resource["schedule"], cognite_client), data_sampling=SimulatorRoutineDataSampling._load(resource["dataSampling"], cognite_client), logical_check=[ SimulatorRoutineLogicalCheckEnabled._load(check_, cognite_client) for check_ in resource["logicalCheck"] @@ -528,8 +530,18 @@ def __init__( @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - instance = super()._load(resource, cognite_client) - return instance + load = super()._load(resource, cognite_client) + return cls( + external_id=load.external_id, + name=load.name, + file_extension_types=load.file_extension_types, + created_time=resource.get("createdTime"), + last_updated_time=resource.get("lastUpdatedTime"), + id=resource.get("id"), + model_types=load.model_types, + step_fields=load.step_fields, + unit_quantities=load.unit_quantities, + ) def as_write(self) -> SimulatorWrite: """Returns a writeable version of this resource""" @@ -688,8 +700,24 @@ def __init__( @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - instance = super()._load(resource, cognite_client) - return instance + load = super()._load(resource, cognite_client) + return cls( + external_id=load.external_id, + simulator_external_id=load.simulator_external_id, + heartbeat=load.heartbeat, + data_set_id=load.data_set_id, + connector_version=load.connector_version, + license_status=load.license_status, + simulator_version=load.simulator_version, + license_last_checked_time=load.license_last_checked_time, + connector_status=load.connector_status, + connector_status_updated_time=load.connector_status_updated_time, + created_time=resource.get("createdTime"), + last_updated_time=resource.get("lastUpdatedTime"), + id=resource.get("id"), + active=resource.get("active"), + log_id=resource.get("logId"), + ) def as_write(self) -> SimulatorIntegrationWrite: """Returns a writeable version of this resource""" @@ -774,9 +802,9 @@ def _load( cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None ) -> SimulatorModelRevisionWrite: return cls( - external_id=resource["externalId"], - model_external_id=resource["modelExternalId"], - file_id=resource["fileId"], + external_id=resource.get("externalId"), + model_external_id=resource.get("modelExternalId"), + file_id=resource.get("fileId"), description=resource.get("description"), ) @@ -978,8 +1006,23 @@ def __init__( @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - instance = super()._load(resource, cognite_client) - return instance + load = super()._load(resource, cognite_client) + return cls( + external_id=load.external_id, + simulator_external_id=load.simulator_external_id, + routine_external_id=load.routine_external_id, + simulator_integration_external_id=load.simulator_integration_external_id, + model_external_id=load.model_external_id, + data_set_id=load.data_set_id, + created_by_user_id=resource.get("createdByUserId"), + configuration=load.configuration, + script=load.script, + id=resource.get("id"), + created_time=resource.get("createdTime"), + last_updated_time=resource.get("lastUpdatedTime"), + version_number=resource.get("versionNumber"), + log_id=resource.get("logId"), + ) def as_write(self) -> SimulatorRoutineRevisionWrite: """Returns a writeable version of this resource""" @@ -1064,11 +1107,11 @@ def __init__( @classmethod def _load(cls, resource: dict, cognite_client: CogniteClient | None = None) -> SimulatorModelWrite: return cls( - external_id=resource["externalId"], - simulator_external_id=resource["simulatorExternalId"], - data_set_id=resource["dataSetId"], - name=resource["name"], - type=resource.get("typeKey"), + external_id=resource.get("externalId"), + simulator_external_id=resource.get("simulatorExternalId"), + data_set_id=resource.get("dataSetId"), + name=resource.get("name"), + type=resource.get("type"), description=resource.get("description"), ) @@ -1133,8 +1176,18 @@ def __init__( @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - instance = super()._load(resource, cognite_client) - return instance + load = super()._load(resource, cognite_client) + return cls( + external_id=load.external_id, + simulator_external_id=load.simulator_external_id, + data_set_id=load.data_set_id, + name=load.name, + id=resource.get("id"), + type=resource.get("type"), + description=load.description, + created_time=resource.get("createdTime"), + last_updated_time=resource.get("lastUpdatedTime"), + ) def as_write(self) -> SimulatorModelWrite: """Returns this SimulatorModel in its writing version.""" @@ -1396,10 +1449,10 @@ def __init__( simulator_integration_external_id: str, name: str, data_set_id: int, + description: str | None = None, created_time: int | None = None, last_updated_time: int | None = None, id: int | None = None, - description: str | None = None, ) -> None: self.external_id = external_id self.simulator_external_id = simulator_external_id @@ -1407,6 +1460,7 @@ def __init__( self.simulator_integration_external_id = simulator_integration_external_id self.name = name self.data_set_id = data_set_id + self.description = description # id/created_time/last_updated_time are required when using the class to read, # but don't make sense passing in when creating a new object. So in order to make the typing # correct here (i.e. int and not Optional[int]), we force the type to be int rather than @@ -1417,7 +1471,18 @@ def __init__( @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: - instance = super()._load(resource, cognite_client) + instance = cls( + external_id=resource["externalId"], + simulator_external_id=resource["simulatorExternalId"], + model_external_id=resource["modelExternalId"], + simulator_integration_external_id=resource["simulatorIntegrationExternalId"], + name=resource["name"], + data_set_id=resource["dataSetId"], + description=resource.get("description"), + created_time=resource.get("createdTime"), + last_updated_time=resource.get("lastUpdatedTime"), + id=resource.get("id"), + ) return instance def as_write(self) -> SimulatorRoutineWrite: From aa7702b3b8f3dfe4a31c20beb44686d5d1b3ad91 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 10:34:25 +0100 Subject: [PATCH 052/122] fix tests --- .../data_classes/simulators/__init__.py | 110 +++++++++++++++++- .../data_classes/simulators/simulators.py | 29 +++-- 2 files changed, 129 insertions(+), 10 deletions(-) diff --git a/cognite/client/data_classes/simulators/__init__.py b/cognite/client/data_classes/simulators/__init__.py index d10dd7b1e..77212f705 100644 --- a/cognite/client/data_classes/simulators/__init__.py +++ b/cognite/client/data_classes/simulators/__init__.py @@ -1,5 +1,111 @@ from __future__ import annotations -from cognite.client.data_classes.simulators.simulators import SimulatorRoutineSchedule +from cognite.client.data_classes.simulators.simulators import ( + SimulationRun, + SimulationRunCore, + SimulationRunsList, + SimulationValueUnitInput, + Simulator, + SimulatorCore, + SimulatorIntegration, + SimulatorIntegrationCore, + SimulatorIntegrationList, + SimulatorIntegrationWrite, + SimulatorIntegrationWriteList, + SimulatorList, + SimulatorModel, + SimulatorModelCore, + SimulatorModelList, + SimulatorModelRevision, + SimulatorModelRevisionCore, + SimulatorModelRevisionList, + SimulatorModelRevisionWrite, + SimulatorModelRevisionWriteList, + SimulatorModelType, + SimulatorModelWrite, + SimulatorModelWriteList, + SimulatorQuantity, + SimulatorRoutine, + SimulatorRoutineConfiguration, + SimulatorRoutineCore, + SimulatorRoutineDataSampling, + SimulatorRoutineInputConstant, + SimulatorRoutineInputTimeseries, + SimulatorRoutineList, + SimulatorRoutineLogicalCheckEnabled, + SimulatorRoutineOutput, + SimulatorRoutineRevision, + SimulatorRoutineRevisionCore, + SimulatorRoutineRevisionList, + SimulatorRoutineRevisionsList, + SimulatorRoutineRevisionWrite, + SimulatorRoutineRevisionWriteList, + SimulatorRoutineSchedule, + SimulatorRoutineStage, + SimulatorRoutineSteadyStateDetectionEnabled, + SimulatorRoutineStep, + SimulatorRoutineStepArguments, + SimulatorRoutineWrite, + SimulatorRoutineWriteList, + SimulatorStep, + SimulatorStepField, + SimulatorStepOption, + SimulatorUnitEntry, + SimulatorWrite, + SimulatorWriteList, +) -__all__ = ["SimulatorRoutineSchedule"] +__all__ = [ + "SimulationValueUnitInput", + "SimulatorRoutineInputTimeseries", + "SimulatorRoutineInputConstant", + "SimulatorRoutineOutput", + "SimulatorRoutineSchedule", + "SimulatorRoutineDataSampling", + "SimulatorRoutineLogicalCheckEnabled", + "SimulatorRoutineSteadyStateDetectionEnabled", + "SimulatorRoutineConfiguration", + "SimulatorRoutineStepArguments", + "SimulatorRoutineStep", + "SimulatorRoutineStage", + "SimulatorUnitEntry", + "SimulatorStepOption", + "SimulatorModelType", + "SimulatorQuantity", + "SimulatorStepField", + "SimulatorStep", + "SimulatorCore", + "SimulatorWrite", + "Simulator", + "SimulatorIntegrationCore", + "SimulatorIntegrationWrite", + "SimulatorIntegration", + "SimulatorModelRevisionCore", + "SimulatorModelRevisionWrite", + "SimulatorModelRevision", + "SimulatorRoutineRevisionCore", + "SimulatorRoutineRevisionWrite", + "SimulatorRoutineRevision", + "SimulatorModelCore", + "SimulatorModelWrite", + "SimulatorModel", + "SimulationRunCore", + "SimulationRun", + "SimulatorRoutineCore", + "SimulatorRoutineWrite", + "SimulatorRoutine", + "SimulatorRoutineRevisionWriteList", + "SimulatorRoutineRevisionList", + "SimulatorRoutineWriteList", + "SimulatorRoutineList", + "SimulatorRoutineRevisionsList", + "SimulatorWriteList", + "SimulatorList", + "SimulatorIntegrationWriteList", + "SimulatorIntegrationList", + "SimulatorModelWriteList", + "SimulatorModelList", + "SimulatorModelRevisionWriteList", + "SimulatorModelRevisionList", + "SimulationRunsList", +] diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 0c32dcb24..97490e632 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -203,15 +203,25 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = outputs = [] if resource.get("inputs", None) is not None: - inputs = [ - SimulatorRoutineInputConstant._load(input_, cognite_client) - if "value" in input_ - else SimulatorRoutineInputTimeseries._load(input_, cognite_client) - for input_ in resource["inputs"] - ] + for input_ in resource["inputs"]: + if isinstance(input_, SimulatorRoutineInputConstant) or isinstance( + input_, SimulatorRoutineInputTimeseries + ): + inputs.append(input_) + + else: + if "value" in input_: + inputs.append(SimulatorRoutineInputConstant._load(input_, cognite_client)) + else: + inputs.append(SimulatorRoutineInputTimeseries._load(input_, cognite_client)) if resource.get("outputs", None) is not None: - outputs = [SimulatorRoutineOutput._load(output_, cognite_client) for output_ in resource["outputs"]] + for output_ in resource["outputs"]: + if isinstance(output_, SimulatorRoutineOutput): + outputs.append(output_) + + else: + outputs.append(SimulatorRoutineOutput._load(output_, cognite_client)) return cls( schedule=SimulatorRoutineSchedule.load(resource["schedule"], cognite_client), @@ -269,7 +279,10 @@ class SimulatorRoutineStage(CogniteObject): def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: return cls( order=resource["order"], - steps=[SimulatorRoutineStep._load(step_, cognite_client) for step_ in resource["steps"]], + steps=[ + SimulatorRoutineStep._load(step_, cognite_client) if isinstance(step_, dict) else step_ + for step_ in resource["steps"] + ], description=resource.get("description"), ) From 3473533d4faed2a0c48895954675eb344e1ca9e0 Mon Sep 17 00:00:00 2001 From: abdullah-cognite <100700755+abdullah-cognite@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:30:37 +0000 Subject: [PATCH 053/122] add missing dump calls in parent class --- .../data_classes/simulators/simulators.py | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 97490e632..f89958e76 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -126,15 +126,20 @@ class SimulatorRoutineSchedule(CogniteObject): enabled: bool = False cron_expression: str | None = None + def __init__(self, enabled: bool | None = None, cron_expression: str | None = None, **_: Any) -> None: + self.enabled = enabled + self.cron_expression = cron_expression + @classmethod - def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: + def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> SimulatorRoutineSchedule: return cls( enabled=resource["enabled"], cron_expression=resource.get("cronExpression"), ) def dump(self, camel_case: bool = True) -> dict[str, Any]: - return super().dump(camel_case=camel_case) + output = super().dump(camel_case=camel_case) + return output @dataclass @@ -237,6 +242,19 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = outputs=outputs, ) + def dump(self, camel_case: bool = True) -> dict[str, Any]: + output = super().dump(camel_case=camel_case) + output["schedule"] = self.schedule.dump(camel_case=camel_case) + output["dataSampling"] = self.data_sampling.dump(camel_case=camel_case) + output["logicalCheck"] = [check_.dump(camel_case=camel_case) for check_ in self.logical_check] + output["steadyStateDetection"] = [ + detection_.dump(camel_case=camel_case) for detection_ in self.steady_state_detection + ] + output["inputs"] = [input_.dump(camel_case=camel_case) for input_ in self.inputs] + output["outputs"] = [output_.dump(camel_case=camel_case) for output_ in self.outputs] + + return output + @dataclass class SimulatorRoutineStepArguments(CogniteObject): @@ -287,7 +305,9 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = ) def dump(self, camel_case: bool = True) -> dict[str, Any]: - return super().dump(camel_case=camel_case) + output = super().dump(camel_case=camel_case) + output["steps"] = [step_.dump(camel_case=camel_case) for step_ in self.steps] + return output @dataclass @@ -829,6 +849,7 @@ class SimulatorModelRevision(SimulatorModelRevisionCore): Each revision ensures that modifications to models are traceable and allows users to understand the evolution of a given model. Args: + id (int | None): No description. external_id (str | None): External id of the simulator model revision simulator_external_id (str | None): No description. model_external_id (str | None): External id of the associated simulator model @@ -847,6 +868,7 @@ class SimulatorModelRevision(SimulatorModelRevisionCore): def __init__( self, + id: int | None = None, external_id: str | None = None, simulator_external_id: str | None = None, model_external_id: str | None = None, @@ -880,9 +902,9 @@ def __init__( # but don't make sense passing in when creating a new object. So in order to make the typing # correct here (i.e. int and not Optional[int]), we force the type to be int rather than # Optional[int]. - self.id: int = id # type: ignore - self.created_time: int = created_time # type: ignore - self.last_updated_time: int = last_updated_time # type: ignore + self.id: int | None = id + self.created_time: int | None = created_time + self.last_updated_time: int | None = last_updated_time @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self: From 2400a67831035896ed71a6d7d0932412e3c4e5de Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 11:32:32 +0100 Subject: [PATCH 054/122] fix schedule test --- cognite/client/data_classes/simulators/simulators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index f89958e76..77c4508e5 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -126,7 +126,7 @@ class SimulatorRoutineSchedule(CogniteObject): enabled: bool = False cron_expression: str | None = None - def __init__(self, enabled: bool | None = None, cron_expression: str | None = None, **_: Any) -> None: + def __init__(self, enabled: bool, cron_expression: str | None = None, **_: Any) -> None: self.enabled = enabled self.cron_expression = cron_expression From 78d2d79a7e4ca810a16912a8bb449c7f25bb7ab8 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 12:57:30 +0100 Subject: [PATCH 055/122] fix tests --- .../test_api/test_simulators/seed/data.py | 62 +++++-- .../test_simulators/test_simulators.py | 160 ++++++++++++------ 2 files changed, 156 insertions(+), 66 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index b3db2c021..8b0aa56ec 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -1,6 +1,19 @@ +import time + +resource_names = { + "simulator_external_id": "integration_tests_workflow", + "simulator_integration_external_id": "integration_tests_workflow_connector", + "simulator_model_external_id": "integration_tests_workflow_model_01", + "simulator_model_revision_external_id": "integration_tests_workflow_model_revision_1", + "simulator_model_file_external_id": "ShowerMixer_simulator_model_file_3", + "simulator_routine_external_id": "integration_tests_workflow_routine", + "simulator_routine_revision_external_id": "integration_tests_workflow_routine_revision", + "simulator_test_data_set_id": 97552494921583, +} + simulator = { - "name": "DWSIM", - "externalId": "integration_tests_workflow", + "name": resource_names["simulator_external_id"], + "externalId": resource_names["simulator_external_id"], "fileExtensionTypes": ["dwxmz"], "modelTypes": [{"name": "Steady State", "key": "SteadyState"}], "stepFields": [ @@ -164,14 +177,34 @@ {"label": "F", "name": "F"}, ], }, + { + "name": "volumetricFlow", + "label": "Volumetric Flow", + "units": [ + {"label": "m3/h", "name": "m3/h"}, + {"label": "cm3/s", "name": "cm3/s"}, + {"label": "L/h", "name": "L/h"}, + {"label": "L/min", "name": "L/min"}, + {"label": "L/s", "name": "L/s"}, + {"label": "ft3/h", "name": "ft3/h"}, + {"label": "ft3/min", "name": "ft3/min"}, + {"label": "ft3/s", "name": "ft3/s"}, + {"label": "gal[US]/h", "name": "gal[US]/h"}, + {"label": "gal[US]/min", "name": "gal[US]/min"}, + {"label": "gal[US]/s", "name": "gal[US]/s"}, + {"label": "gal[UK]/h", "name": "gal[UK]/h"}, + {"label": "gal[UK]/min", "name": "gal[UK]/min"}, + {"label": "gal[UK]/s", "name": "gal[UK]/s"}, + ], + }, ], } simulator_integration = { - "externalId": "integration_tests_workflow_connector", - "simulatorExternalId": "integration_tests_workflow", - "heartbeat": 1706396950969, + "externalId": resource_names["simulator_integration_external_id"], + "simulatorExternalId": resource_names["simulator_external_id"], + "heartbeat": int(time.time() * 1000), "dataSetId": 97552494921583, "connectorVersion": "1.0.0", "simulatorVersion": "1.0.0", @@ -183,33 +216,32 @@ simulator_model = { - "externalId": "integration_tests_workflow_model", - "simulatorExternalId": "integration_tests_workflow", + "externalId": resource_names["simulator_model_external_id"], + "simulatorExternalId": resource_names["simulator_external_id"], "name": "Test Simulator Model", "description": "Test Simulator Model Desc", "dataSetId": 97552494921583, - "labels": [{"externalId": "simconfig-labels-PROSPER"}], "type": "SteadyState", } simulator_model_revision = { - "externalId": "integration_tests_workflow_model_revision", - "modelExternalId": "integration_tests_workflow_model", + "externalId": resource_names["simulator_model_revision_external_id"], + "modelExternalId": resource_names["simulator_model_external_id"], "description": "test sim model revision description", "fileId": 00000000000000, } simulator_routine = { - "externalId": "integration_tests_workflow_routine", - "modelExternalId": "integration_tests_workflow_model", - "simulatorIntegrationExternalId": "integration_tests_workflow_connector", + "externalId": resource_names["simulator_routine_external_id"], + "modelExternalId": resource_names["simulator_model_external_id"], + "simulatorIntegrationExternalId": resource_names["simulator_integration_external_id"], "name": "Routine test", "description": "test", } simulator_routine_revision = { - "externalId": "integration_tests_workflow_routine_revision", - "routineExternalId": "integration_tests_workflow_routine", + "externalId": resource_names["simulator_routine_revision_external_id"], + "routineExternalId": resource_names["simulator_routine_external_id"], "configuration": { "schedule": {"enabled": True, "cronExpression": "*/10 * * * *"}, "dataSampling": {"enabled": True, "validationWindow": None, "samplingWindow": 15, "granularity": 1}, diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 50bd289dd..67f677be8 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -1,8 +1,14 @@ import pytest from cognite.client import CogniteClient -from cognite.client.data_classes.simulators.filters import SimulatorIntegrationFilter +from cognite.client.data_classes.files import FileMetadata +from cognite.client.data_classes.simulators.filters import ( + SimulatorIntegrationFilter, + SimulatorModelRevisionsFilter, + SimulatorModelsFilter, +) from tests.tests_integration.test_api.test_simulators.seed.data import ( + resource_names, simulator, simulator_integration, simulator_model, @@ -12,52 +18,97 @@ ) +@pytest.fixture(scope="class") +def seed_resource_names() -> dict[str, str]: + return resource_names + + @pytest.fixture -def add_simulator_resoures(cognite_client: CogniteClient) -> None: - simulator_external_id = "integration_tests_workflow" - simulator_model_file_external_id = "ShowerMixer_simulator_model_file" - - file = cognite_client.files.upload( - path="tests/tests_integration/test_api/test_simulators/seed/data/ShowerMixer.dwxmz", - external_id=simulator_model_file_external_id, - name="ShowerMixer.dwxmz", - data_set_id=97552494921583, +def seed_file(cognite_client: CogniteClient, seed_resource_names) -> FileMetadata | None: + # check if file already exists + file = cognite_client.files.retrieve(external_id=seed_resource_names["simulator_model_file_external_id"]) + if (file is None) or (file is False): + file = cognite_client.files.upload( + path="tests/tests_integration/test_api/test_simulators/seed/ShowerMixer.dwxmz", + external_id=seed_resource_names["simulator_model_file_external_id"], + name="ShowerMixer.dwxmz", + data_set_id=97552494921583, + ) + yield file + + +@pytest.fixture +def seed_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: + simulator_external_id = seed_resource_names["simulator_external_id"] + simulators = cognite_client.simulators.list() + for sim in simulators: + if sim.external_id == simulator_external_id: + return + + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators", + json={"items": [simulator]}, ) - resources = [ - {"url": f"/api/v1/projects/{cognite_client.config.project}/simulators", "seed": simulator}, - { - "url": f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations", - "seed": simulator_integration, - }, - {"url": f"/api/v1/projects/{cognite_client.config.project}/simulators/models", "seed": simulator_model}, - { - "url": f"/api/v1/projects/{cognite_client.config.project}/simulators/models/revisions", - "seed": {**simulator_model_revision, "fileId": file.id}, - }, - {"url": f"/api/v1/projects/{cognite_client.config.project}/simulators/routines", "seed": simulator_routine}, - { - "url": f"/api/v1/projects/{cognite_client.config.project}/simulators/routines/revisions", - "seed": simulator_routine_revision, - }, - ] - - for resource in resources: + +@pytest.fixture +def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> None: + def create_integration(): cognite_client.post( - resource["url"], - json={"items": [resource["seed"]]}, - headers={"cdf-version": "alpha"}, + f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations", + json={"items": [simulator_integration]}, ) - yield None + try: + create_integration() + except Exception: + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations/delete", + json={"items": [{"externalId": simulator_integration["externalId"]}]}, + ) + create_integration() + pass + +@pytest.fixture +def seed_simulator_models(cognite_client: CogniteClient, seed_simulator_integration) -> None: cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", - json={"items": [{"externalId": simulator_external_id}]}, - headers={"cdf-version": "alpha"}, + f"/api/v1/projects/{cognite_client.config.project}/simulators/models", + json={"items": [simulator_model]}, # Post actual simulator models here ) - cognite_client.files.delete(external_id=simulator_model_file_external_id) + +@pytest.fixture +def seed_simulator_model_revisions(cognite_client: CogniteClient, seed_simulator_models, seed_file) -> None: + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/models/revisions", + json={"items": [{**simulator_model_revision, "fileId": seed_file.id}]}, # Post actual simulator models here + ) + + +@pytest.fixture +def seed_simulator_routines(cognite_client: CogniteClient, seed_simulator_model_revisions) -> None: + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/routines", + json={"items": [simulator_routine]}, + ) + + +@pytest.fixture +def seed_simulator_routine_revisions(cognite_client: CogniteClient, seed_simulator_routines) -> None: + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/routines/revisions", + json={"items": [simulator_routine_revision]}, + ) + + +@pytest.fixture(scope="class") +def delete_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: + yield + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", + json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, + ) class TestSimulators: @@ -71,6 +122,7 @@ class TestSimulatorIntegrations: # test list # test filter # test retrieve + @pytest.mark.usefixtures("seed_simulator_integration") def test_list_integrations(self, cognite_client: CogniteClient) -> None: integrations = cognite_client.simulators.integrations.list(limit=5) @@ -91,24 +143,36 @@ def test_filter_integrations(self, cognite_client: CogniteClient) -> None: assert len(all_integrations) != len(dwsim_integrations) +@pytest.mark.usefixtures("seed_resource_names", "seed_simulator", "delete_simulator") class TestSimulatorModels: - def test_list_models(self, cognite_client: CogniteClient) -> None: - models = cognite_client.simulators.models.list(limit=5) + @pytest.mark.usefixtures("seed_simulator_models", "seed_simulator_model_revisions") + def test_list_models(self, cognite_client: CogniteClient, seed_resource_names) -> None: + models = cognite_client.simulators.models.list( + limit=5, filter=SimulatorModelsFilter(simulator_external_ids=[seed_resource_names["simulator_external_id"]]) + ) assert len(models) > 0 - def test_retrieve_model(self, cognite_client: CogniteClient) -> None: + def test_retrieve_model(self, cognite_client: CogniteClient, seed_resource_names) -> None: model = cognite_client.simulators.models.retrieve(external_id="TEST_WORKFLOWS_SIMINT_INTEGRATION_MODEL") assert model is not None assert model.external_id == "TEST_WORKFLOWS_SIMINT_INTEGRATION_MODEL" - def test_list_model_revisions(self, cognite_client: CogniteClient) -> None: - revisions = cognite_client.simulators.models.revisions.list(limit=5) + def test_list_model_revisions(self, cognite_client: CogniteClient, seed_resource_names) -> None: + revisions = cognite_client.simulators.models.list( + limit=5, + filter=SimulatorModelRevisionsFilter( + model_external_ids=[seed_resource_names["simulator_model_external_id"]] + ), + ) assert len(revisions) > 0 - def test_retrieve_model_revision(self, cognite_client: CogniteClient) -> None: - model = cognite_client.simulators.models.revisions.retrieve(external_id="Shower_mixer-1") + def test_retrieve_model_revision(self, cognite_client: CogniteClient, seed_resource_names) -> None: + # TODO : this test is incorrect, it should retrieve model revisions instead of model + model = cognite_client.simulators.models.retrieve( + external_id=seed_resource_names["simulator_model_external_id"] + ) assert model is not None - assert model.external_id == "Shower_mixer-1" + assert model.external_id == seed_resource_names["simulator_model_external_id"] class TestSimulatorRoutines: @@ -126,9 +190,3 @@ def test_retrieve_routine_revision(self, cognite_client: CogniteClient) -> None: revision = cognite_client.simulators.routines.revisions.retrieve(external_id="ShowerMixerForTests-1") assert revision is not None assert revision.external_id == "ShowerMixerForTests-1" - - -class TestSimulationRuns: - def test_list_runs(self, cognite_client: CogniteClient) -> None: - routines = cognite_client.simulators.runs.list(limit=5) - assert len(routines) > 0 From cd40c3be6fc9c08c676b82fe2f1d220b49c106e5 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 13:22:17 +0100 Subject: [PATCH 056/122] print dataset --- .../test_api/test_simulators/test_simulators.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 67f677be8..226080590 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -124,6 +124,8 @@ class TestSimulatorIntegrations: # test retrieve @pytest.mark.usefixtures("seed_simulator_integration") def test_list_integrations(self, cognite_client: CogniteClient) -> None: + datasets = cognite_client.data_sets.list(limit=5) + assert datasets == {} integrations = cognite_client.simulators.integrations.list(limit=5) assert len(integrations) > 0 From 5e4e0afc607657bee909c02997fdfa4322bcc49b Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 13:27:35 +0100 Subject: [PATCH 057/122] disable fixture --- .../test_api/test_simulators/test_simulators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 226080590..5f367f095 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -122,7 +122,7 @@ class TestSimulatorIntegrations: # test list # test filter # test retrieve - @pytest.mark.usefixtures("seed_simulator_integration") + #@pytest.mark.usefixtures("seed_simulator_integration") def test_list_integrations(self, cognite_client: CogniteClient) -> None: datasets = cognite_client.data_sets.list(limit=5) assert datasets == {} From f0139d046f0952920e9a93ec01c472f96393ee31 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 13:35:19 +0100 Subject: [PATCH 058/122] fix --- .../test_api/test_simulators/test_simulators.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 5f367f095..2e2766554 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -122,10 +122,15 @@ class TestSimulatorIntegrations: # test list # test filter # test retrieve - #@pytest.mark.usefixtures("seed_simulator_integration") + # @pytest.mark.usefixtures("seed_simulator_integration") def test_list_integrations(self, cognite_client: CogniteClient) -> None: datasets = cognite_client.data_sets.list(limit=5) - assert datasets == {} + ds_ids = [] + for dataset in datasets: + ds_ids.append(dataset.id) + ds_ids.append(dataset.name) + + assert ds_ids == {} integrations = cognite_client.simulators.integrations.list(limit=5) assert len(integrations) > 0 From bb51ef66a6ed84f0daea5010ca76acccc9319b19 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 13:42:49 +0100 Subject: [PATCH 059/122] fix --- .../test_api/test_simulators/seed/data.py | 9 ++++++--- .../test_api/test_simulators/test_simulators.py | 9 +-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index 8b0aa56ec..8185e49f1 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -1,5 +1,8 @@ import time +data_set_id = 1521375514069 +development_data_set_id = 97552494921583 + resource_names = { "simulator_external_id": "integration_tests_workflow", "simulator_integration_external_id": "integration_tests_workflow_connector", @@ -8,7 +11,7 @@ "simulator_model_file_external_id": "ShowerMixer_simulator_model_file_3", "simulator_routine_external_id": "integration_tests_workflow_routine", "simulator_routine_revision_external_id": "integration_tests_workflow_routine_revision", - "simulator_test_data_set_id": 97552494921583, + "simulator_test_data_set_id": data_set_id, } simulator = { @@ -205,7 +208,7 @@ "externalId": resource_names["simulator_integration_external_id"], "simulatorExternalId": resource_names["simulator_external_id"], "heartbeat": int(time.time() * 1000), - "dataSetId": 97552494921583, + "dataSetId": resource_names["simulator_test_data_set_id"], "connectorVersion": "1.0.0", "simulatorVersion": "1.0.0", "licenseStatus": "AVAILABLE", @@ -220,7 +223,7 @@ "simulatorExternalId": resource_names["simulator_external_id"], "name": "Test Simulator Model", "description": "Test Simulator Model Desc", - "dataSetId": 97552494921583, + "dataSetId": resource_names["simulator_test_data_set_id"], "type": "SteadyState", } diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 2e2766554..67f677be8 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -122,15 +122,8 @@ class TestSimulatorIntegrations: # test list # test filter # test retrieve - # @pytest.mark.usefixtures("seed_simulator_integration") + @pytest.mark.usefixtures("seed_simulator_integration") def test_list_integrations(self, cognite_client: CogniteClient) -> None: - datasets = cognite_client.data_sets.list(limit=5) - ds_ids = [] - for dataset in datasets: - ds_ids.append(dataset.id) - ds_ids.append(dataset.name) - - assert ds_ids == {} integrations = cognite_client.simulators.integrations.list(limit=5) assert len(integrations) > 0 From 2fb1eef30d28a10c8ce687e061247e59b80b892c Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 13:56:23 +0100 Subject: [PATCH 060/122] fix --- .../test_api/test_simulators/seed/data.py | 2 +- .../test_simulators/test_simulators.py | 23 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index 8185e49f1..73b9a2a69 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -6,7 +6,7 @@ resource_names = { "simulator_external_id": "integration_tests_workflow", "simulator_integration_external_id": "integration_tests_workflow_connector", - "simulator_model_external_id": "integration_tests_workflow_model_01", + "simulator_model_external_id": "integration_tests_workflow_model_02", "simulator_model_revision_external_id": "integration_tests_workflow_model_revision_1", "simulator_model_file_external_id": "ShowerMixer_simulator_model_file_3", "simulator_routine_external_id": "integration_tests_workflow_routine", diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 67f677be8..930e4156b 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -111,6 +111,7 @@ def delete_simulator(cognite_client: CogniteClient, seed_resource_names) -> None ) +@pytest.mark.usefixtures("seed_resource_names", "seed_simulator", "delete_simulator") class TestSimulators: def test_list_simulators(self, cognite_client: CogniteClient) -> None: simulators = cognite_client.simulators.list(limit=5) @@ -118,11 +119,8 @@ def test_list_simulators(self, cognite_client: CogniteClient) -> None: assert len(simulators) > 0 +@pytest.mark.usefixtures("seed_resource_names", "seed_simulator_integration", "delete_simulator") class TestSimulatorIntegrations: - # test list - # test filter - # test retrieve - @pytest.mark.usefixtures("seed_simulator_integration") def test_list_integrations(self, cognite_client: CogniteClient) -> None: integrations = cognite_client.simulators.integrations.list(limit=5) @@ -143,9 +141,14 @@ def test_filter_integrations(self, cognite_client: CogniteClient) -> None: assert len(all_integrations) != len(dwsim_integrations) -@pytest.mark.usefixtures("seed_resource_names", "seed_simulator", "delete_simulator") +@pytest.mark.usefixtures( + "seed_resource_names", + "seed_simulator", + "seed_simulator_models", + "seed_simulator_model_revisions", + "delete_simulator", +) class TestSimulatorModels: - @pytest.mark.usefixtures("seed_simulator_models", "seed_simulator_model_revisions") def test_list_models(self, cognite_client: CogniteClient, seed_resource_names) -> None: models = cognite_client.simulators.models.list( limit=5, filter=SimulatorModelsFilter(simulator_external_ids=[seed_resource_names["simulator_external_id"]]) @@ -175,6 +178,9 @@ def test_retrieve_model_revision(self, cognite_client: CogniteClient, seed_resou assert model.external_id == seed_resource_names["simulator_model_external_id"] +@pytest.mark.usefixtures( + "seed_resource_names", "seed_simulator", "seed_simulator_routine_revisions", "delete_simulator" +) class TestSimulatorRoutines: def test_list_routines(self, cognite_client: CogniteClient) -> None: routines = cognite_client.simulators.routines.list(limit=5) @@ -185,8 +191,3 @@ def test_list_routine_revisions(self, cognite_client: CogniteClient) -> None: assert revisions[0].configuration is not None assert revisions[0].script is not None assert len(revisions) > 0 - - def test_retrieve_routine_revision(self, cognite_client: CogniteClient) -> None: - revision = cognite_client.simulators.routines.revisions.retrieve(external_id="ShowerMixerForTests-1") - assert revision is not None - assert revision.external_id == "ShowerMixerForTests-1" From b668282ffa4907e3812d4d111d13e2b5b065543f Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 14:10:47 +0100 Subject: [PATCH 061/122] fix --- .../test_api/test_simulators/test_simulators.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 930e4156b..726aecbd2 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -4,8 +4,6 @@ from cognite.client.data_classes.files import FileMetadata from cognite.client.data_classes.simulators.filters import ( SimulatorIntegrationFilter, - SimulatorModelRevisionsFilter, - SimulatorModelsFilter, ) from tests.tests_integration.test_api.test_simulators.seed.data import ( resource_names, @@ -141,7 +139,7 @@ def test_filter_integrations(self, cognite_client: CogniteClient) -> None: assert len(all_integrations) != len(dwsim_integrations) -@pytest.mark.usefixtures( +"""@pytest.mark.usefixtures( "seed_resource_names", "seed_simulator", "seed_simulator_models", @@ -191,3 +189,4 @@ def test_list_routine_revisions(self, cognite_client: CogniteClient) -> None: assert revisions[0].configuration is not None assert revisions[0].script is not None assert len(revisions) > 0 +""" From c8527a91c04959b36f6ef1ec0ce890717316de06 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 14:17:48 +0100 Subject: [PATCH 062/122] fix --- .../test_api/test_simulators/seed/data.py | 2 +- .../test_api/test_simulators/test_simulators.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index 73b9a2a69..b8e6acfa2 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -4,7 +4,7 @@ development_data_set_id = 97552494921583 resource_names = { - "simulator_external_id": "integration_tests_workflow", + "simulator_external_id": "py_sdk_integration_tests", "simulator_integration_external_id": "integration_tests_workflow_connector", "simulator_model_external_id": "integration_tests_workflow_model_02", "simulator_model_revision_external_id": "integration_tests_workflow_model_revision_1", diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 726aecbd2..8074b2841 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -100,7 +100,7 @@ def seed_simulator_routine_revisions(cognite_client: CogniteClient, seed_simulat ) -@pytest.fixture(scope="class") +@pytest.fixture def delete_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: yield cognite_client.post( @@ -124,19 +124,19 @@ def test_list_integrations(self, cognite_client: CogniteClient) -> None: assert len(integrations) > 0 - def test_filter_integrations(self, cognite_client: CogniteClient) -> None: + def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_names) -> None: all_integrations = cognite_client.simulators.integrations.list() active_integrations = cognite_client.simulators.integrations.list( filter=SimulatorIntegrationFilter(active=True) ) - dwsim_integrations = cognite_client.simulators.integrations.list( - filter=SimulatorIntegrationFilter(simulator_external_ids=["DWSIM"]) + integrations = cognite_client.simulators.integrations.list( + filter=SimulatorIntegrationFilter(simulator_external_ids=[seed_resource_names["simulator_external_id"]]) ) assert len(active_integrations) > 0 assert len(all_integrations) != len(active_integrations) - assert len(dwsim_integrations) > 0 - assert len(all_integrations) != len(dwsim_integrations) + assert len(integrations) > 0 + assert len(all_integrations) != len(integrations) """@pytest.mark.usefixtures( From 979847549e020b9a5198c577833feea2a9c6382e Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 14:19:26 +0100 Subject: [PATCH 063/122] fix --- .../test_api/test_simulators/test_simulators.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 8074b2841..d58dca38c 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -125,18 +125,15 @@ def test_list_integrations(self, cognite_client: CogniteClient) -> None: assert len(integrations) > 0 def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_names) -> None: - all_integrations = cognite_client.simulators.integrations.list() active_integrations = cognite_client.simulators.integrations.list( filter=SimulatorIntegrationFilter(active=True) ) - integrations = cognite_client.simulators.integrations.list( + filtered_integrations = cognite_client.simulators.integrations.list( filter=SimulatorIntegrationFilter(simulator_external_ids=[seed_resource_names["simulator_external_id"]]) ) assert len(active_integrations) > 0 - assert len(all_integrations) != len(active_integrations) - assert len(integrations) > 0 - assert len(all_integrations) != len(integrations) + assert len(filtered_integrations) > 0 """@pytest.mark.usefixtures( From c076dc924bc8b25fd1ff60bcc8bee4e6ca9c28b0 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 14:27:54 +0100 Subject: [PATCH 064/122] fix --- .../test_api/test_simulators/test_simulators.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index d58dca38c..aa03eedd3 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -125,6 +125,7 @@ def test_list_integrations(self, cognite_client: CogniteClient) -> None: assert len(integrations) > 0 def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_names) -> None: + all_integrations = cognite_client.simulators.integrations.list() active_integrations = cognite_client.simulators.integrations.list( filter=SimulatorIntegrationFilter(active=True) ) @@ -132,6 +133,9 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ filter=SimulatorIntegrationFilter(simulator_external_ids=[seed_resource_names["simulator_external_id"]]) ) + assert all_integrations[0].external_id == "w" + assert len(all_integrations) == 1 + assert len(active_integrations) > 0 assert len(filtered_integrations) > 0 From 77d431be5fa9b4e56b67e9d76299ff8d36161f28 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 14:38:55 +0100 Subject: [PATCH 065/122] fix --- .../test_api/test_simulators/seed/data.py | 2 +- .../test_api/test_simulators/test_simulators.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index b8e6acfa2..222c6ede9 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -1,6 +1,6 @@ import time -data_set_id = 1521375514069 +data_set_id = 97552494921583 development_data_set_id = 97552494921583 resource_names = { diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index aa03eedd3..448e0f2be 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -133,11 +133,10 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ filter=SimulatorIntegrationFilter(simulator_external_ids=[seed_resource_names["simulator_external_id"]]) ) - assert all_integrations[0].external_id == "w" - assert len(all_integrations) == 1 + assert len(all_integrations) > 0 - assert len(active_integrations) > 0 - assert len(filtered_integrations) > 0 + # assert len(active_integrations) > 0 + # assert len(filtered_integrations) > 0 """@pytest.mark.usefixtures( From e43ce277d9266401d472f082a1d4dc490b051204 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 14:49:50 +0100 Subject: [PATCH 066/122] fix --- .../test_simulators/test_simulators.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 448e0f2be..5689abfe5 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -39,15 +39,21 @@ def seed_file(cognite_client: CogniteClient, seed_resource_names) -> FileMetadat def seed_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: simulator_external_id = seed_resource_names["simulator_external_id"] simulators = cognite_client.simulators.list() - for sim in simulators: - if sim.external_id == simulator_external_id: - return + fl = list(filter(lambda x: x.external_id == simulator_external_id, simulators)) + assert len(fl) == 0 cognite_client.post( f"/api/v1/projects/{cognite_client.config.project}/simulators", json={"items": [simulator]}, ) + yield + + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", + json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, + ) + @pytest.fixture def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> None: @@ -109,7 +115,7 @@ def delete_simulator(cognite_client: CogniteClient, seed_resource_names) -> None ) -@pytest.mark.usefixtures("seed_resource_names", "seed_simulator", "delete_simulator") +@pytest.mark.usefixtures("seed_resource_names", "seed_simulator") class TestSimulators: def test_list_simulators(self, cognite_client: CogniteClient) -> None: simulators = cognite_client.simulators.list(limit=5) @@ -117,7 +123,7 @@ def test_list_simulators(self, cognite_client: CogniteClient) -> None: assert len(simulators) > 0 -@pytest.mark.usefixtures("seed_resource_names", "seed_simulator_integration", "delete_simulator") +@pytest.mark.usefixtures("seed_resource_names", "seed_simulator_integration") class TestSimulatorIntegrations: def test_list_integrations(self, cognite_client: CogniteClient) -> None: integrations = cognite_client.simulators.integrations.list(limit=5) @@ -134,9 +140,10 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ ) assert len(all_integrations) > 0 + assert filtered_integrations[0].simulator_external_id == seed_resource_names["simulator_external_id"] - # assert len(active_integrations) > 0 - # assert len(filtered_integrations) > 0 + assert len(active_integrations) > 0 + assert len(filtered_integrations) > 0 """@pytest.mark.usefixtures( From f49d9fa80ac836bfb844318f11b3814ff10b8396 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 14:55:59 +0100 Subject: [PATCH 067/122] fix --- .../test_api/test_simulators/test_simulators.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 5689abfe5..06b6e0d81 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -39,8 +39,12 @@ def seed_file(cognite_client: CogniteClient, seed_resource_names) -> FileMetadat def seed_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: simulator_external_id = seed_resource_names["simulator_external_id"] simulators = cognite_client.simulators.list() - fl = list(filter(lambda x: x.external_id == simulator_external_id, simulators)) - assert len(fl) == 0 + simulator_exists = len(list(filter(lambda x: x.external_id == simulator_external_id, simulators))) > 0 + if simulator_exists: + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", + json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, + ) cognite_client.post( f"/api/v1/projects/{cognite_client.config.project}/simulators", From b683f027c305c59fa8904f705a013f4841ac4539 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 15:03:51 +0100 Subject: [PATCH 068/122] fix dataset --- tests/tests_integration/test_api/test_simulators/seed/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index 222c6ede9..b8e6acfa2 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -1,6 +1,6 @@ import time -data_set_id = 97552494921583 +data_set_id = 1521375514069 development_data_set_id = 97552494921583 resource_names = { From b1b5c9d49d0bdbc0ba25d4c4b8c588e0bfc60c6d Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Mon, 9 Dec 2024 15:52:46 +0100 Subject: [PATCH 069/122] verify --- .../test_api/test_simulators/test_simulators.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 06b6e0d81..63397e17c 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -145,6 +145,8 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ assert len(all_integrations) > 0 assert filtered_integrations[0].simulator_external_id == seed_resource_names["simulator_external_id"] + assert filtered_integrations[0].heartbeat == 10 + assert filtered_integrations[0].active is True assert len(active_integrations) > 0 assert len(filtered_integrations) > 0 From 7084a4d90acf6983a9768df800602d41aac33d31 Mon Sep 17 00:00:00 2001 From: abdullah-cognite <100700755+abdullah-cognite@users.noreply.github.com> Date: Tue, 10 Dec 2024 06:58:58 +0000 Subject: [PATCH 070/122] slight change --- .../test_api/test_simulators/test_simulators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 63397e17c..2e3c3df98 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -145,10 +145,10 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ assert len(all_integrations) > 0 assert filtered_integrations[0].simulator_external_id == seed_resource_names["simulator_external_id"] - assert filtered_integrations[0].heartbeat == 10 + # assert filtered_integrations[0].heartbeat == 10 assert filtered_integrations[0].active is True - assert len(active_integrations) > 0 + # assert len(active_integrations) > 0 assert len(filtered_integrations) > 0 From 4d5fa3bda45dc6666d475abd2d2d0c58d0ba0c2e Mon Sep 17 00:00:00 2001 From: abdullah-cognite <100700755+abdullah-cognite@users.noreply.github.com> Date: Tue, 10 Dec 2024 07:06:39 +0000 Subject: [PATCH 071/122] slight change --- tests/tests_integration/test_api/test_simulators/seed/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index b8e6acfa2..ef1696d4e 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -207,7 +207,7 @@ simulator_integration = { "externalId": resource_names["simulator_integration_external_id"], "simulatorExternalId": resource_names["simulator_external_id"], - "heartbeat": int(time.time() * 1000), + "heartbeat": int(time.time()), "dataSetId": resource_names["simulator_test_data_set_id"], "connectorVersion": "1.0.0", "simulatorVersion": "1.0.0", From dbbe91afc4756012d214088b719ea0c5dc2fc6e8 Mon Sep 17 00:00:00 2001 From: abdullah-cognite <100700755+abdullah-cognite@users.noreply.github.com> Date: Tue, 10 Dec 2024 07:18:25 +0000 Subject: [PATCH 072/122] slight change --- tests/tests_integration/test_api/test_simulators/seed/data.py | 2 +- .../test_api/test_simulators/test_simulators.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index ef1696d4e..b8e6acfa2 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -207,7 +207,7 @@ simulator_integration = { "externalId": resource_names["simulator_integration_external_id"], "simulatorExternalId": resource_names["simulator_external_id"], - "heartbeat": int(time.time()), + "heartbeat": int(time.time() * 1000), "dataSetId": resource_names["simulator_test_data_set_id"], "connectorVersion": "1.0.0", "simulatorVersion": "1.0.0", diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 2e3c3df98..698897f5b 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -145,7 +145,7 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ assert len(all_integrations) > 0 assert filtered_integrations[0].simulator_external_id == seed_resource_names["simulator_external_id"] - # assert filtered_integrations[0].heartbeat == 10 + assert filtered_integrations[0].heartbeat == 10 assert filtered_integrations[0].active is True # assert len(active_integrations) > 0 From 9520e8a051fb0bb9ecfd8d835ee0d922191f359e Mon Sep 17 00:00:00 2001 From: abdullah-cognite <100700755+abdullah-cognite@users.noreply.github.com> Date: Tue, 10 Dec 2024 08:11:08 +0000 Subject: [PATCH 073/122] slight change --- .../test_api/test_simulators/test_simulators.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 698897f5b..098d26dce 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -1,3 +1,4 @@ +import time import pytest from cognite.client import CogniteClient @@ -145,6 +146,8 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ assert len(all_integrations) > 0 assert filtered_integrations[0].simulator_external_id == seed_resource_names["simulator_external_id"] + # check time difference + assert filtered_integrations[0].heartbeat == filtered_integrations[0].heartbeat - (time.time() * 1000) assert filtered_integrations[0].heartbeat == 10 assert filtered_integrations[0].active is True From 66f4074a108262f288e479a2d1728240d325af68 Mon Sep 17 00:00:00 2001 From: abdullah-cognite <100700755+abdullah-cognite@users.noreply.github.com> Date: Tue, 10 Dec 2024 08:57:23 +0000 Subject: [PATCH 074/122] slight change --- .../test_simulators/test_simulators.py | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 098d26dce..e5416623c 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -41,17 +41,12 @@ def seed_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: simulator_external_id = seed_resource_names["simulator_external_id"] simulators = cognite_client.simulators.list() simulator_exists = len(list(filter(lambda x: x.external_id == simulator_external_id, simulators))) > 0 - if simulator_exists: + if not simulator_exists: cognite_client.post( f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, ) - cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators", - json={"items": [simulator]}, - ) - yield cognite_client.post( @@ -62,20 +57,19 @@ def seed_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: @pytest.fixture def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> None: - def create_integration(): + try: + simulator_integration["heartbeat"] = int(time.time() * 1000) cognite_client.post( f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations", json={"items": [simulator_integration]}, ) - - try: - create_integration() except Exception: - cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations/delete", - json={"items": [{"externalId": simulator_integration["externalId"]}]}, - ) - create_integration() + # update hearbeat instead + # cognite_client.post( + # f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations/update", + # json={"items": [{"externalId": simulator_integration["externalId"]}]}, + # ) + # create_integration() pass @@ -128,8 +122,9 @@ def test_list_simulators(self, cognite_client: CogniteClient) -> None: assert len(simulators) > 0 -@pytest.mark.usefixtures("seed_resource_names", "seed_simulator_integration") + class TestSimulatorIntegrations: + @pytest.mark.usefixtures("seed_resource_names", "seed_simulator_integration") def test_list_integrations(self, cognite_client: CogniteClient) -> None: integrations = cognite_client.simulators.integrations.list(limit=5) @@ -147,11 +142,11 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ assert len(all_integrations) > 0 assert filtered_integrations[0].simulator_external_id == seed_resource_names["simulator_external_id"] # check time difference - assert filtered_integrations[0].heartbeat == filtered_integrations[0].heartbeat - (time.time() * 1000) - assert filtered_integrations[0].heartbeat == 10 + # assert filtered_integrations[0].heartbeat == filtered_integrations[0].heartbeat - (time.time() * 1000) + # assert filtered_integrations[0].heartbeat == 10 assert filtered_integrations[0].active is True - # assert len(active_integrations) > 0 + assert len(active_integrations) > 0 assert len(filtered_integrations) > 0 From 655d29881aefc619b048e1a3eaddad8b91e2ee0f Mon Sep 17 00:00:00 2001 From: abdullah-cognite <100700755+abdullah-cognite@users.noreply.github.com> Date: Tue, 10 Dec 2024 09:03:30 +0000 Subject: [PATCH 075/122] slight change --- .../test_api/test_simulators/test_simulators.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index e5416623c..2c76486f9 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -47,12 +47,12 @@ def seed_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, ) - yield + # yield - cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", - json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, - ) + # cognite_client.post( + # f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", + # json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, + # ) @pytest.fixture From 92b3d9adf9741671b3126b4fdb28e0c9e5b6835e Mon Sep 17 00:00:00 2001 From: abdullah-cognite <100700755+abdullah-cognite@users.noreply.github.com> Date: Tue, 10 Dec 2024 09:04:44 +0000 Subject: [PATCH 076/122] slight change --- .../test_api/test_simulators/test_simulators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 2c76486f9..c4ed3a1bd 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -43,7 +43,7 @@ def seed_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: simulator_exists = len(list(filter(lambda x: x.external_id == simulator_external_id, simulators))) > 0 if not simulator_exists: cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", + f"/api/v1/projects/{cognite_client.config.project}/simulators", json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, ) From c316ce31d0b325688eebe002085069c0ca803910 Mon Sep 17 00:00:00 2001 From: abdullah-cognite <100700755+abdullah-cognite@users.noreply.github.com> Date: Tue, 10 Dec 2024 09:05:38 +0000 Subject: [PATCH 077/122] slight change --- .../test_api/test_simulators/test_simulators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index c4ed3a1bd..097c47bb7 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -44,7 +44,7 @@ def seed_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: if not simulator_exists: cognite_client.post( f"/api/v1/projects/{cognite_client.config.project}/simulators", - json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, + json={"items": [simulator]}, ) # yield From 560188b7762ce522813dbaddaab50fb4ac2c6447 Mon Sep 17 00:00:00 2001 From: abdullah-cognite <100700755+abdullah-cognite@users.noreply.github.com> Date: Tue, 10 Dec 2024 09:13:10 +0000 Subject: [PATCH 078/122] slight change --- .../test_api/test_simulators/test_simulators.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 097c47bb7..c868e9ff4 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -64,11 +64,13 @@ def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> json={"items": [simulator_integration]}, ) except Exception: + simulator_integrations = cognite_client.simulators.integrations.list() + id = list(filter(lambda x: x.simulator_external_id == simulator_integration["simulatorExternalId"], simulator_integrations))[0].id # update hearbeat instead - # cognite_client.post( - # f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations/update", - # json={"items": [{"externalId": simulator_integration["externalId"]}]}, - # ) + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations/update", + json={"items": [{"id": id, "update": {"heartbeat": {"set":int(time.time() * 1000)}}}]}, + ) # create_integration() pass From 7b7d82bd02d4dd3a12db8b33b48a2dc02a8191d0 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 09:34:38 +0100 Subject: [PATCH 079/122] fix --- .../test_api/test_simulators/test_simulators.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index c868e9ff4..04148373b 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -144,9 +144,8 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ assert len(all_integrations) > 0 assert filtered_integrations[0].simulator_external_id == seed_resource_names["simulator_external_id"] # check time difference - # assert filtered_integrations[0].heartbeat == filtered_integrations[0].heartbeat - (time.time() * 1000) - # assert filtered_integrations[0].heartbeat == 10 assert filtered_integrations[0].active is True + assert filtered_integrations[0].heartbeat == 10 assert len(active_integrations) > 0 assert len(filtered_integrations) > 0 From 5a77f2ec6602b2f025d7e908009fde0da57acebe Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 10:28:02 +0100 Subject: [PATCH 080/122] fix filtered check --- .../test_api/test_simulators/seed/data.py | 5 +++-- .../test_simulators/test_simulators.py | 20 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index b8e6acfa2..d865bfdfc 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -1,7 +1,8 @@ import time -data_set_id = 1521375514069 -development_data_set_id = 97552494921583 +# data_set_id = 1521375514069 +# development_data_set_id = 97552494921583 +data_set_id = 97552494921583 resource_names = { "simulator_external_id": "py_sdk_integration_tests", diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 04148373b..0790f285c 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -1,4 +1,5 @@ import time + import pytest from cognite.client import CogniteClient @@ -41,18 +42,16 @@ def seed_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: simulator_external_id = seed_resource_names["simulator_external_id"] simulators = cognite_client.simulators.list() simulator_exists = len(list(filter(lambda x: x.external_id == simulator_external_id, simulators))) > 0 - if not simulator_exists: + if simulator_exists: cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators", - json={"items": [simulator]}, + f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", + json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, ) - # yield - - # cognite_client.post( - # f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", - # json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, - # ) + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators", + json={"items": [simulator]}, + ) @pytest.fixture @@ -124,7 +123,6 @@ def test_list_simulators(self, cognite_client: CogniteClient) -> None: assert len(simulators) > 0 - class TestSimulatorIntegrations: @pytest.mark.usefixtures("seed_resource_names", "seed_simulator_integration") def test_list_integrations(self, cognite_client: CogniteClient) -> None: @@ -137,6 +135,7 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ active_integrations = cognite_client.simulators.integrations.list( filter=SimulatorIntegrationFilter(active=True) ) + filtered_integrations = cognite_client.simulators.integrations.list( filter=SimulatorIntegrationFilter(simulator_external_ids=[seed_resource_names["simulator_external_id"]]) ) @@ -145,7 +144,6 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ assert filtered_integrations[0].simulator_external_id == seed_resource_names["simulator_external_id"] # check time difference assert filtered_integrations[0].active is True - assert filtered_integrations[0].heartbeat == 10 assert len(active_integrations) > 0 assert len(filtered_integrations) > 0 From fd3342b13fe824a1ed6d58ecaec06e01fef1b6ec Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 10:31:09 +0100 Subject: [PATCH 081/122] fix lint --- .../test_api/test_simulators/test_simulators.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 0790f285c..155cbcb5a 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -64,11 +64,16 @@ def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> ) except Exception: simulator_integrations = cognite_client.simulators.integrations.list() - id = list(filter(lambda x: x.simulator_external_id == simulator_integration["simulatorExternalId"], simulator_integrations))[0].id + id = list( + filter( + lambda x: x.simulator_external_id == simulator_integration["simulatorExternalId"], + simulator_integrations, + ) + )[0].id # update hearbeat instead cognite_client.post( f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations/update", - json={"items": [{"id": id, "update": {"heartbeat": {"set":int(time.time() * 1000)}}}]}, + json={"items": [{"id": id, "update": {"heartbeat": {"set": int(time.time() * 1000)}}}]}, ) # create_integration() pass From d7236a8e859184ccc6e913d437eed0b7e85c16aa Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 10:34:53 +0100 Subject: [PATCH 082/122] remove limits from docstrings --- cognite/client/_api/simulators/simulation_runs.py | 2 +- .../client/_api/simulators/simulator_integrations.py | 2 +- cognite/client/_api/simulators/simulator_models.py | 4 ++-- cognite/client/_api/simulators/simulator_routines.py | 4 ++-- cognite/client/_api/simulators/simulators.py | 2 +- cognite/client/data_classes/simulators/simulators.py | 10 ---------- 6 files changed, 7 insertions(+), 17 deletions(-) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py index d787d33fc..d40493bf6 100644 --- a/cognite/client/_api/simulators/simulation_runs.py +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -29,7 +29,7 @@ def list( List simulation runs Args: - limit (int): The maximum number of simulation runs to return. Defaults to 100. + limit (int): The maximum number of simulation runs to return. filter (SimulationRunsFilter | dict[str, Any] | None): The filter that helps narrow down the list of simulation runs. Returns: diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index 5cef2845b..a7f3b07b0 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -35,7 +35,7 @@ def list( List simulator integrations Args: - limit (int): The maximum number of simulator integrations to return. Defaults to 100. + limit (int): The maximum number of simulator integrations to return. filter (SimulatorIntegrationFilter | dict[str, Any] | None): The filter to narrow down simulator integrations. Returns: diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index b02c5449a..9ca288d15 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -37,7 +37,7 @@ def list( List simulator model revisions Args: - limit (int): The maximum number of simulator model revisions to return. Defaults to 100. + limit (int): The maximum number of simulator model revisions to return. filter (SimulatorModelRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator model revisions. Returns: @@ -149,7 +149,7 @@ def list( List simulator models Args: - limit (int): The maximum number of simulator models to return. Defaults to 100. + limit (int): The maximum number of simulator models to return. filter (SimulatorModelsFilter | dict[str, Any] | None): The filter to narrow down simulator models. Returns: diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 27451fcf3..9cc463539 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -37,7 +37,7 @@ def list( List simulator routine revisions Args: - limit (int): The maximum number of simulator routine revisions to return. Defaults to 10. + limit (int): The maximum number of simulator routine revisions to return. filter (SimulatorRoutineRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator routine revisions. Returns: @@ -148,7 +148,7 @@ def list( List simulator routines Args: - limit (int): The maximum number of simulator routines to return. Defaults to 100. + limit (int): The maximum number of simulator routines to return. filter (SimulatorRoutinesFilter | dict[str, Any] | None): The filter to narrow down simulator routines. Returns: diff --git a/cognite/client/_api/simulators/simulators.py b/cognite/client/_api/simulators/simulators.py index 7599951d0..ca8bf24d7 100644 --- a/cognite/client/_api/simulators/simulators.py +++ b/cognite/client/_api/simulators/simulators.py @@ -38,7 +38,7 @@ def list(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorList: List simulators Args: - limit (int): The maximum number of simulators to return. Defaults to 10. + limit (int): The maximum number of simulators to return. Returns: SimulatorList: List of simulators diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 77c4508e5..99f3d3d01 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -449,7 +449,6 @@ class SimulatorCore(WriteableCogniteResource["SimulatorWrite"], ABC): when dealing with a specific simulator. Each simulator is uniquely identified and can be associated with various file extension types, model types, step fields, and unit quantities. Simulators are essential for managing data flows between CDF and external simulation tools, ensuring consistency and reliability in data handling. #### - Limitations: - A project can have a maximum of 100 simulators This is the read/response format of the simulator. @@ -598,8 +597,6 @@ class SimulatorIntegrationCore(WriteableCogniteResource["SimulatorIntegrationWri details such as dataset, name, license status, connector version, simulator version, and more. This resource is essential for monitoring and managing the interactions between CDF and external simulators, ensuring proper data flow and integration. - Limitations: - A project can have a maximum of 100 simulators - This is the read/response format of the simulator integration. Args: @@ -1303,10 +1300,6 @@ class SimulationRun(SimulationRunCore): Simulation runs provide a historical record of the simulations performed, allowing users to analyze and compare different runs, track changes over time, and make informed decisions based on the simulation results. - Limitations: - * A retention policy is in place for simulation runs, allowing up to 100000 entries. - * Once this limit is reached, the oldest runs will be deleted to accommodate new runs. - This is the read/response format of a simulation run. Args: @@ -1398,9 +1391,6 @@ class SimulatorRoutineCore(WriteableCogniteResource["SimulatorRoutineWrite"], AB Each model can have multiple routines, each performing different objectives such as calculating optimal operation setpoints, forecasting production, benchmarking asset performance, and more. - Limitations: - - Each simulator model can have a maximum of 10 simulator routines - Each simulator routine can have a maximum of 10 revisions This is the read/response format of a simulator routine. From 64cd8b5f6fe88179797128ae8fd8bb97ddaadafc Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 10:42:37 +0100 Subject: [PATCH 083/122] fix dataset --- .../tests_integration/test_api/test_simulators/seed/data.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index d865bfdfc..b8e6acfa2 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -1,8 +1,7 @@ import time -# data_set_id = 1521375514069 -# development_data_set_id = 97552494921583 -data_set_id = 97552494921583 +data_set_id = 1521375514069 +development_data_set_id = 97552494921583 resource_names = { "simulator_external_id": "py_sdk_integration_tests", From 2a06f9887ba8cea033aa0d018b2079ee00af7128 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 10:57:03 +0100 Subject: [PATCH 084/122] fix --- .../test_api/test_simulators/test_simulators.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 155cbcb5a..911582520 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -42,17 +42,12 @@ def seed_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: simulator_external_id = seed_resource_names["simulator_external_id"] simulators = cognite_client.simulators.list() simulator_exists = len(list(filter(lambda x: x.external_id == simulator_external_id, simulators))) > 0 - if simulator_exists: + if not simulator_exists: cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", - json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, + f"/api/v1/projects/{cognite_client.config.project}/simulators", + json={"items": [simulator]}, ) - cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators", - json={"items": [simulator]}, - ) - @pytest.fixture def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> None: From 6e795d68ff6a1319a9a1115188f4f7d77885f9f1 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 11:04:27 +0100 Subject: [PATCH 085/122] fix --- .../test_api/test_simulators/test_simulators.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 911582520..fa702e267 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -7,6 +7,7 @@ from cognite.client.data_classes.simulators.filters import ( SimulatorIntegrationFilter, ) +from cognite.client.exceptions import CogniteAPIError from tests.tests_integration.test_api.test_simulators.seed.data import ( resource_names, simulator, @@ -57,9 +58,9 @@ def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations", json={"items": [simulator_integration]}, ) - except Exception: + except CogniteAPIError: simulator_integrations = cognite_client.simulators.integrations.list() - id = list( + integration_id = list( filter( lambda x: x.simulator_external_id == simulator_integration["simulatorExternalId"], simulator_integrations, @@ -68,10 +69,8 @@ def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> # update hearbeat instead cognite_client.post( f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations/update", - json={"items": [{"id": id, "update": {"heartbeat": {"set": int(time.time() * 1000)}}}]}, + json={"items": [{"id": integration_id, "update": {"heartbeat": {"set": int(time.time() * 1000)}}}]}, ) - # create_integration() - pass @pytest.fixture From 3560687bb641a9b07e85a0062f56bcb6d49a81b3 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 11:20:42 +0100 Subject: [PATCH 086/122] fix --- .../test_api/test_simulators/test_simulators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index fa702e267..53d51adf9 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -62,7 +62,7 @@ def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> simulator_integrations = cognite_client.simulators.integrations.list() integration_id = list( filter( - lambda x: x.simulator_external_id == simulator_integration["simulatorExternalId"], + lambda x: x.external_id == simulator_integration["externalId"], simulator_integrations, ) )[0].id From 48d6195327b68d9d0f36fb717b3bf14c20ff8aa6 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 11:26:43 +0100 Subject: [PATCH 087/122] fix --- .../test_api/test_simulators/test_simulators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 53d51adf9..447d00153 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -136,11 +136,11 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ ) filtered_integrations = cognite_client.simulators.integrations.list( - filter=SimulatorIntegrationFilter(simulator_external_ids=[seed_resource_names["simulator_external_id"]]) + filter=SimulatorIntegrationFilter(simulator_external_ids=[seed_resource_names["simulator_integration_external_id"]]) ) assert len(all_integrations) > 0 - assert filtered_integrations[0].simulator_external_id == seed_resource_names["simulator_external_id"] + assert filtered_integrations[0].simulator_external_id == seed_resource_names["simulator_integration_external_id"] # check time difference assert filtered_integrations[0].active is True From eb024dbe71d162daae77669eb1d7be21b3754afd Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 11:31:03 +0100 Subject: [PATCH 088/122] fix --- .../test_api/test_simulators/test_simulators.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 447d00153..d08c3a7f1 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -136,11 +136,13 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ ) filtered_integrations = cognite_client.simulators.integrations.list( - filter=SimulatorIntegrationFilter(simulator_external_ids=[seed_resource_names["simulator_integration_external_id"]]) + filter=SimulatorIntegrationFilter( + simulator_external_ids=[seed_resource_names["simulator_integration_external_id"]] + ) ) assert len(all_integrations) > 0 - assert filtered_integrations[0].simulator_external_id == seed_resource_names["simulator_integration_external_id"] + assert filtered_integrations[0].external_id == seed_resource_names["simulator_integration_external_id"] # check time difference assert filtered_integrations[0].active is True From c75f49260d626d8d5c078c4ade03c66f22ae4c97 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 11:41:03 +0100 Subject: [PATCH 089/122] fix --- .../test_api/test_simulators/test_simulators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index d08c3a7f1..ae6552f5e 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -137,7 +137,7 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ filtered_integrations = cognite_client.simulators.integrations.list( filter=SimulatorIntegrationFilter( - simulator_external_ids=[seed_resource_names["simulator_integration_external_id"]] + simulator_external_ids=[seed_resource_names["simulator_external_id"]] ) ) From c104a3b6657c5c37ce2b61786a8aec5d65b5afad Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 11:54:26 +0100 Subject: [PATCH 090/122] fix --- tests/tests_integration/test_api/test_simulators/seed/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index b8e6acfa2..2f573ec30 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -5,7 +5,7 @@ resource_names = { "simulator_external_id": "py_sdk_integration_tests", - "simulator_integration_external_id": "integration_tests_workflow_connector", + "simulator_integration_external_id": "py_sdk_integration_tests_connector", "simulator_model_external_id": "integration_tests_workflow_model_02", "simulator_model_revision_external_id": "integration_tests_workflow_model_revision_1", "simulator_model_file_external_id": "ShowerMixer_simulator_model_file_3", From 6718fb4cb8fdca201fb3c2e8bbcc622222bcfcbb Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 12:18:42 +0100 Subject: [PATCH 091/122] fix --- .../test_api/test_simulators/seed/data.py | 5 +++-- .../test_api/test_simulators/test_simulators.py | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index 2f573ec30..e65bb3384 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -1,7 +1,8 @@ import time -data_set_id = 1521375514069 -development_data_set_id = 97552494921583 +#data_set_id = 1521375514069 +#development_data_set_id = 97552494921583 +data_set_id = 97552494921583 resource_names = { "simulator_external_id": "py_sdk_integration_tests", diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index ae6552f5e..5b26d0061 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -75,6 +75,15 @@ def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> @pytest.fixture def seed_simulator_models(cognite_client: CogniteClient, seed_simulator_integration) -> None: + models = cognite_client.simulators.models.list() + model_seed = list(filter(lambda x: x.external_id == simulator_model["externalId"], models)) + + if len(model_seed) > 0: + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/models/delete", + json={"items": [{"id": model_seed[0].id}]}, # Post actual simulator models here + ) + cognite_client.post( f"/api/v1/projects/{cognite_client.config.project}/simulators/models", json={"items": [simulator_model]}, # Post actual simulator models here @@ -185,10 +194,10 @@ def test_retrieve_model_revision(self, cognite_client: CogniteClient, seed_resou ) assert model is not None assert model.external_id == seed_resource_names["simulator_model_external_id"] - +""" @pytest.mark.usefixtures( - "seed_resource_names", "seed_simulator", "seed_simulator_routine_revisions", "delete_simulator" + "seed_resource_names", "seed_simulator_routine_revisions" ) class TestSimulatorRoutines: def test_list_routines(self, cognite_client: CogniteClient) -> None: @@ -200,4 +209,3 @@ def test_list_routine_revisions(self, cognite_client: CogniteClient) -> None: assert revisions[0].configuration is not None assert revisions[0].script is not None assert len(revisions) > 0 -""" From 960775aff8c0901f100436453a2c9a2298246784 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 12:24:07 +0100 Subject: [PATCH 092/122] model tests --- .../test_api/test_simulators/seed/data.py | 5 ++-- .../test_simulators/test_simulators.py | 23 ++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index e65bb3384..2f573ec30 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -1,8 +1,7 @@ import time -#data_set_id = 1521375514069 -#development_data_set_id = 97552494921583 -data_set_id = 97552494921583 +data_set_id = 1521375514069 +development_data_set_id = 97552494921583 resource_names = { "simulator_external_id": "py_sdk_integration_tests", diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 5b26d0061..b58f031d1 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -6,6 +6,8 @@ from cognite.client.data_classes.files import FileMetadata from cognite.client.data_classes.simulators.filters import ( SimulatorIntegrationFilter, + SimulatorModelRevisionsFilter, + SimulatorModelsFilter, ) from cognite.client.exceptions import CogniteAPIError from tests.tests_integration.test_api.test_simulators.seed.data import ( @@ -145,9 +147,7 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ ) filtered_integrations = cognite_client.simulators.integrations.list( - filter=SimulatorIntegrationFilter( - simulator_external_ids=[seed_resource_names["simulator_external_id"]] - ) + filter=SimulatorIntegrationFilter(simulator_external_ids=[seed_resource_names["simulator_external_id"]]) ) assert len(all_integrations) > 0 @@ -159,12 +159,9 @@ def test_filter_integrations(self, cognite_client: CogniteClient, seed_resource_ assert len(filtered_integrations) > 0 -"""@pytest.mark.usefixtures( +@pytest.mark.usefixtures( "seed_resource_names", - "seed_simulator", - "seed_simulator_models", "seed_simulator_model_revisions", - "delete_simulator", ) class TestSimulatorModels: def test_list_models(self, cognite_client: CogniteClient, seed_resource_names) -> None: @@ -174,9 +171,11 @@ def test_list_models(self, cognite_client: CogniteClient, seed_resource_names) - assert len(models) > 0 def test_retrieve_model(self, cognite_client: CogniteClient, seed_resource_names) -> None: - model = cognite_client.simulators.models.retrieve(external_id="TEST_WORKFLOWS_SIMINT_INTEGRATION_MODEL") + model = cognite_client.simulators.models.retrieve( + external_id=seed_resource_names["simulator_model_external_id"] + ) assert model is not None - assert model.external_id == "TEST_WORKFLOWS_SIMINT_INTEGRATION_MODEL" + assert model.external_id == seed_resource_names["simulator_model_external_id"] def test_list_model_revisions(self, cognite_client: CogniteClient, seed_resource_names) -> None: revisions = cognite_client.simulators.models.list( @@ -194,11 +193,9 @@ def test_retrieve_model_revision(self, cognite_client: CogniteClient, seed_resou ) assert model is not None assert model.external_id == seed_resource_names["simulator_model_external_id"] -""" -@pytest.mark.usefixtures( - "seed_resource_names", "seed_simulator_routine_revisions" -) + +@pytest.mark.usefixtures("seed_resource_names", "seed_simulator_routine_revisions") class TestSimulatorRoutines: def test_list_routines(self, cognite_client: CogniteClient) -> None: routines = cognite_client.simulators.routines.list(limit=5) From 6bdc7f3c892e3b45f8fb6beabacfb3857081b49d Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 12:28:51 +0100 Subject: [PATCH 093/122] dataset retrigger --- tests/tests_integration/test_api/test_simulators/seed/data.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index 2f573ec30..5ca0a69b5 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -3,6 +3,7 @@ data_set_id = 1521375514069 development_data_set_id = 97552494921583 + resource_names = { "simulator_external_id": "py_sdk_integration_tests", "simulator_integration_external_id": "py_sdk_integration_tests_connector", From 1cdc8b2ebb9c7bef1422fd0145970251febf23dc Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 13:25:57 +0100 Subject: [PATCH 094/122] fix --- .../test_api/test_simulators/test_simulators.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index b58f031d1..ca8370828 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -12,6 +12,7 @@ from cognite.client.exceptions import CogniteAPIError from tests.tests_integration.test_api.test_simulators.seed.data import ( resource_names, + data_set_id, simulator, simulator_integration, simulator_model, @@ -35,7 +36,7 @@ def seed_file(cognite_client: CogniteClient, seed_resource_names) -> FileMetadat path="tests/tests_integration/test_api/test_simulators/seed/ShowerMixer.dwxmz", external_id=seed_resource_names["simulator_model_file_external_id"], name="ShowerMixer.dwxmz", - data_set_id=97552494921583, + data_set_id=data_set_id, ) yield file From 9fead1a61c87d14c43d8d2e2d40026c39ead0c94 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 13:50:12 +0100 Subject: [PATCH 095/122] fix --- .../test_api/test_simulators/seed/data.py | 14 +++--- .../test_simulators/test_simulators.py | 43 ++++++++++++------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index 5ca0a69b5..e3f18cde7 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -1,17 +1,17 @@ import time -data_set_id = 1521375514069 -development_data_set_id = 97552494921583 - +# data_set_id = 1521375514069 +# development_data_set_id = 97552494921583 +data_set_id = 97552494921583 resource_names = { "simulator_external_id": "py_sdk_integration_tests", "simulator_integration_external_id": "py_sdk_integration_tests_connector", - "simulator_model_external_id": "integration_tests_workflow_model_02", - "simulator_model_revision_external_id": "integration_tests_workflow_model_revision_1", + "simulator_model_external_id": "py_sdk_integration_tests_model", + "simulator_model_revision_external_id": "pysdk_model_revision", "simulator_model_file_external_id": "ShowerMixer_simulator_model_file_3", - "simulator_routine_external_id": "integration_tests_workflow_routine", - "simulator_routine_revision_external_id": "integration_tests_workflow_routine_revision", + "simulator_routine_external_id": "pysdk_routine", + "simulator_routine_revision_external_id": "pysdk_routine_revision", "simulator_test_data_set_id": data_set_id, } diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index ca8370828..05074697c 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -1,3 +1,4 @@ +import random import time import pytest @@ -11,8 +12,8 @@ ) from cognite.client.exceptions import CogniteAPIError from tests.tests_integration.test_api.test_simulators.seed.data import ( - resource_names, data_set_id, + resource_names, simulator, simulator_integration, simulator_model, @@ -21,6 +22,8 @@ simulator_routine_revision, ) +model_unique_external_id = f"{resource_names['simulator_model_external_id']}_{random.randint(100,500)}" + @pytest.fixture(scope="class") def seed_resource_names() -> dict[str, str]: @@ -79,7 +82,7 @@ def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> @pytest.fixture def seed_simulator_models(cognite_client: CogniteClient, seed_simulator_integration) -> None: models = cognite_client.simulators.models.list() - model_seed = list(filter(lambda x: x.external_id == simulator_model["externalId"], models)) + model_seed = list(filter(lambda x: x.external_id == model_unique_external_id, models)) if len(model_seed) > 0: cognite_client.post( @@ -89,7 +92,19 @@ def seed_simulator_models(cognite_client: CogniteClient, seed_simulator_integrat cognite_client.post( f"/api/v1/projects/{cognite_client.config.project}/simulators/models", - json={"items": [simulator_model]}, # Post actual simulator models here + json={ + "items": [{**simulator_model, "externalId": model_unique_external_id}] + }, # Post actual simulator models here + ) + + yield + + models = cognite_client.simulators.models.list() + model_seed = list(filter(lambda x: x.external_id == model_unique_external_id, models)) + + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/models/delete", + json={"items": [{"id": model_seed[0].id}]}, # Post actual simulator models here ) @@ -97,7 +112,9 @@ def seed_simulator_models(cognite_client: CogniteClient, seed_simulator_integrat def seed_simulator_model_revisions(cognite_client: CogniteClient, seed_simulator_models, seed_file) -> None: cognite_client.post( f"/api/v1/projects/{cognite_client.config.project}/simulators/models/revisions", - json={"items": [{**simulator_model_revision, "fileId": seed_file.id}]}, # Post actual simulator models here + json={ + "items": [{**simulator_model_revision, "fileId": seed_file.id, "modelExternalId": model_unique_external_id}] + }, # Post actual simulator models here ) @@ -105,7 +122,7 @@ def seed_simulator_model_revisions(cognite_client: CogniteClient, seed_simulator def seed_simulator_routines(cognite_client: CogniteClient, seed_simulator_model_revisions) -> None: cognite_client.post( f"/api/v1/projects/{cognite_client.config.project}/simulators/routines", - json={"items": [simulator_routine]}, + json={"items": [{**simulator_routine, "modelExternalId": model_unique_external_id}]}, ) @@ -172,28 +189,22 @@ def test_list_models(self, cognite_client: CogniteClient, seed_resource_names) - assert len(models) > 0 def test_retrieve_model(self, cognite_client: CogniteClient, seed_resource_names) -> None: - model = cognite_client.simulators.models.retrieve( - external_id=seed_resource_names["simulator_model_external_id"] - ) + model = cognite_client.simulators.models.retrieve(external_id=model_unique_external_id) assert model is not None - assert model.external_id == seed_resource_names["simulator_model_external_id"] + assert model.external_id == model_unique_external_id def test_list_model_revisions(self, cognite_client: CogniteClient, seed_resource_names) -> None: revisions = cognite_client.simulators.models.list( limit=5, - filter=SimulatorModelRevisionsFilter( - model_external_ids=[seed_resource_names["simulator_model_external_id"]] - ), + filter=SimulatorModelRevisionsFilter(model_external_ids=[model_unique_external_id]), ) assert len(revisions) > 0 def test_retrieve_model_revision(self, cognite_client: CogniteClient, seed_resource_names) -> None: # TODO : this test is incorrect, it should retrieve model revisions instead of model - model = cognite_client.simulators.models.retrieve( - external_id=seed_resource_names["simulator_model_external_id"] - ) + model = cognite_client.simulators.models.retrieve(external_id=model_unique_external_id) assert model is not None - assert model.external_id == seed_resource_names["simulator_model_external_id"] + assert model.external_id == model_unique_external_id @pytest.mark.usefixtures("seed_resource_names", "seed_simulator_routine_revisions") From 5d125bdf1480e57231e00eb28cbb7d35448f8268 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 13:50:59 +0100 Subject: [PATCH 096/122] fix --- .../tests_integration/test_api/test_simulators/seed/data.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index e3f18cde7..6915628e3 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -1,8 +1,7 @@ import time -# data_set_id = 1521375514069 -# development_data_set_id = 97552494921583 -data_set_id = 97552494921583 +data_set_id = 1521375514069 +development_data_set_id = 97552494921583 resource_names = { "simulator_external_id": "py_sdk_integration_tests", From d15226f0490bb7a335a1fc717c22d79b259bc7e2 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 14:23:46 +0100 Subject: [PATCH 097/122] fix --- .../test_api/test_simulators/test_simulators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index 05074697c..c9f3aae04 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -66,12 +66,12 @@ def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> ) except CogniteAPIError: simulator_integrations = cognite_client.simulators.integrations.list() - integration_id = list( + integration_id = next( filter( lambda x: x.external_id == simulator_integration["externalId"], simulator_integrations, ) - )[0].id + ).id # update hearbeat instead cognite_client.post( f"/api/v1/projects/{cognite_client.config.project}/simulators/integrations/update", From eef86be4274951c19680119502f3062ad95416d8 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 14:29:13 +0100 Subject: [PATCH 098/122] fix test and delete fixture --- .../test_api/test_simulators/test_simulators.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index c9f3aae04..b6307124f 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -201,10 +201,9 @@ def test_list_model_revisions(self, cognite_client: CogniteClient, seed_resource assert len(revisions) > 0 def test_retrieve_model_revision(self, cognite_client: CogniteClient, seed_resource_names) -> None: - # TODO : this test is incorrect, it should retrieve model revisions instead of model - model = cognite_client.simulators.models.retrieve(external_id=model_unique_external_id) - assert model is not None - assert model.external_id == model_unique_external_id + model_revision = cognite_client.simulators.models.revisions.retrieve(external_id=seed_resource_names["simulator_model_revision_external_id"]) + assert model_revision is not None + assert model_revision.model_external_id == model_unique_external_id @pytest.mark.usefixtures("seed_resource_names", "seed_simulator_routine_revisions") From bb04ccac3fca2add41ae09d82e8029cd8d45f252 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 14:29:18 +0100 Subject: [PATCH 099/122] fix test and delete fixture --- .../test_api/test_simulators/test_simulators.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index b6307124f..aa8a7cd6a 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -201,7 +201,9 @@ def test_list_model_revisions(self, cognite_client: CogniteClient, seed_resource assert len(revisions) > 0 def test_retrieve_model_revision(self, cognite_client: CogniteClient, seed_resource_names) -> None: - model_revision = cognite_client.simulators.models.revisions.retrieve(external_id=seed_resource_names["simulator_model_revision_external_id"]) + model_revision = cognite_client.simulators.models.revisions.retrieve( + external_id=seed_resource_names["simulator_model_revision_external_id"] + ) assert model_revision is not None assert model_revision.model_external_id == model_unique_external_id From a48b6268bb1e6ce44c207030d56d9841ee5de489 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Tue, 10 Dec 2024 14:32:13 +0100 Subject: [PATCH 100/122] remove unknown change --- cognite/client/utils/_concurrency.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/utils/_concurrency.py b/cognite/client/utils/_concurrency.py index be2ed2411..cc81c77c3 100644 --- a/cognite/client/utils/_concurrency.py +++ b/cognite/client/utils/_concurrency.py @@ -183,7 +183,7 @@ def uses_mainthread(cls) -> bool: @classmethod def get_executor(cls, max_workers: int) -> TaskExecutor: if cls.uses_threadpool(): - return cls.get_thread_pool_executor(max_workers) # type: ignore[return-value] + return cls.get_thread_pool_executor(max_workers) elif cls.uses_mainthread(): return cls.get_mainthread_executor() raise RuntimeError(f"Invalid executor type '{cls.executor_type}'") From c76eab1ea187df5aaec72af989e87168eaa13f55 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:47:02 +0100 Subject: [PATCH 101/122] Update cognite/client/_api/simulators/simulator_models.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 9ca288d15..c47d814e9 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -146,7 +146,7 @@ def list( ) -> SimulatorModelList: """`Filter simulator models `_ - List simulator models + Retrieves a list of simulator models that match the given criteria Args: limit (int): The maximum number of simulator models to return. From d5600fb6412c6bc4966db8912e37152def645150 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:47:23 +0100 Subject: [PATCH 102/122] Update cognite/client/_api/simulators/simulators.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulators.py b/cognite/client/_api/simulators/simulators.py index ca8bf24d7..7c099524a 100644 --- a/cognite/client/_api/simulators/simulators.py +++ b/cognite/client/_api/simulators/simulators.py @@ -38,7 +38,7 @@ def list(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorList: List simulators Args: - limit (int): The maximum number of simulators to return. + limit (int): Maximum number of results to return. Defaults to 1000. Set to -1, float(“inf”) or None to return all items. Returns: SimulatorList: List of simulators From f12fb215db36421c9793c9690a541887a5d2d22f Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:47:55 +0100 Subject: [PATCH 103/122] Update cognite/client/_api/simulators/simulator_routines.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_routines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 9cc463539..a907b96f9 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -148,7 +148,7 @@ def list( List simulator routines Args: - limit (int): The maximum number of simulator routines to return. + limit (int): Maximum number of results to return. Defaults to 1000. Set to -1, float(“inf”) or None to return all items. filter (SimulatorRoutinesFilter | dict[str, Any] | None): The filter to narrow down simulator routines. Returns: From 60c83a0c120c7a4dc19935c11759af41ea2e4879 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:48:18 +0100 Subject: [PATCH 104/122] Update cognite/client/_api/simulators/simulator_routines.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_routines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index a907b96f9..0547444f2 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -145,7 +145,7 @@ def list( ) -> SimulatorRoutineList: """`Filter simulator routines `_ - List simulator routines + Retrieves a list of simulator routines that match the given criteria Args: limit (int): Maximum number of results to return. Defaults to 1000. Set to -1, float(“inf”) or None to return all items. From 4898f542e6a4dc083a9240eed7a1f4043f1a6ee6 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:49:05 +0100 Subject: [PATCH 105/122] Update cognite/client/_api/simulators/simulator_routines.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_routines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 0547444f2..248a6f199 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -68,7 +68,7 @@ def list( def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorRoutineRevision | None: """`Retrieve simulator routine revisions `_ - Retrieve multiple simulator routine revisions by IDs or external IDs + Retrieve a simulator routine revision by ID or external ID Args: id (int | None): The id of the simulator routine revision. From 9945ff85877abc9675478b2e85ef1d0b4334720b Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:49:49 +0100 Subject: [PATCH 106/122] Update cognite/client/_api/simulators/simulator_models.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index c47d814e9..917d1983f 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -38,7 +38,7 @@ def list( Args: limit (int): The maximum number of simulator model revisions to return. - filter (SimulatorModelRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator model revisions. + filter (SimulatorModelRevisionsFilter | dict[str, Any] | None): Filter to apply. Returns: SimulatorModelRevisionList: List of simulator model revisions From c8180cba4eaeae444809c909b84ca3869debbd42 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:50:02 +0100 Subject: [PATCH 107/122] Update cognite/client/_api/simulators/simulator_models.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 917d1983f..32ce13dbb 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -181,7 +181,7 @@ def list( def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModel | None: """`Retrieve simulator model `_ - Retrieve a single simulator model by id/externalId + Retrieve a simulator model by ID or external ID Args: id (int | None): The id of the simulator model. From 16fe676fc67e904b815d47718b4e0421a35162eb Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:50:32 +0100 Subject: [PATCH 108/122] Update cognite/client/_api/simulators/simulator_routines.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_routines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 248a6f199..73efea49b 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -38,7 +38,7 @@ def list( Args: limit (int): The maximum number of simulator routine revisions to return. - filter (SimulatorRoutineRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator routine revisions. + filter (SimulatorRoutineRevisionsFilter | dict[str, Any] | None): Filter to apply. Returns: SimulatorRoutineRevisionsList: List of simulator routine revisions From cd4498c7c6030e38702a382c7efd2ef02e3236df Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:50:44 +0100 Subject: [PATCH 109/122] Update cognite/client/_api/simulators/simulator_models.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 32ce13dbb..b17f6b394 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -150,7 +150,7 @@ def list( Args: limit (int): The maximum number of simulator models to return. - filter (SimulatorModelsFilter | dict[str, Any] | None): The filter to narrow down simulator models. + filter (SimulatorModelsFilter | dict[str, Any] | None): Filter to apply. Returns: SimulatorModelList: List of simulator models From 1c85b886dd8689d04da02d2fea5506bffc6243a3 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:52:07 +0100 Subject: [PATCH 110/122] Update cognite/client/_api/simulators/simulation_runs.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulation_runs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py index d40493bf6..49003955f 100644 --- a/cognite/client/_api/simulators/simulation_runs.py +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -26,7 +26,7 @@ def list( ) -> SimulationRunsList: """`Filter simulation runs `_ - List simulation runs + Retrieves a list of simulation runs that match the given criteria Args: limit (int): The maximum number of simulation runs to return. From 7def1389bbe6e8da38a9e83eb7a11b0cec107fae Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:52:26 +0100 Subject: [PATCH 111/122] Update cognite/client/_api/simulators/simulator_routines.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_routines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 73efea49b..3f593f7af 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -37,7 +37,7 @@ def list( List simulator routine revisions Args: - limit (int): The maximum number of simulator routine revisions to return. + limit (int): Maximum number of results to return. Defaults to 10. Set to -1, float(“inf”) or None to return all items. filter (SimulatorRoutineRevisionsFilter | dict[str, Any] | None): Filter to apply. Returns: From 49ad5fc0161990490e9c4d2c1d74bd92cd3239a1 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:52:40 +0100 Subject: [PATCH 112/122] Update cognite/client/_api/simulators/simulator_routines.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_routines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 3f593f7af..fddec0c83 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -34,7 +34,7 @@ def list( ) -> SimulatorRoutineRevisionsList: """`Filter simulator routine revisions `_ - List simulator routine revisions + Retrieves a list of simulator routine revisions that match the given criteria. Args: limit (int): Maximum number of results to return. Defaults to 10. Set to -1, float(“inf”) or None to return all items. From 6e4f8bbe8383ce98e00a99771848b35865b6487d Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:52:55 +0100 Subject: [PATCH 113/122] Update cognite/client/_api/simulators/simulator_models.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index b17f6b394..173a0074f 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -149,7 +149,7 @@ def list( Retrieves a list of simulator models that match the given criteria Args: - limit (int): The maximum number of simulator models to return. + limit (int): Maximum number of results to return. Defaults to 1000. Set to -1, float(“inf”) or None to return all items. filter (SimulatorModelsFilter | dict[str, Any] | None): Filter to apply. Returns: From 0a9d0070259049125ca093dda70fbcaf91075c24 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:57:35 +0100 Subject: [PATCH 114/122] Update cognite/client/_api/simulators/simulator_integrations.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_integrations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index a7f3b07b0..ac24a410b 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -36,7 +36,7 @@ def list( Args: limit (int): The maximum number of simulator integrations to return. - filter (SimulatorIntegrationFilter | dict[str, Any] | None): The filter to narrow down simulator integrations. + filter (SimulatorIntegrationFilter | dict[str, Any] | None): Filter to apply. Returns: SimulatorIntegrationList: List of simulator integrations From daf3e8a9be947df7591465d6aa662fb57919507d Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:05:39 +0100 Subject: [PATCH 115/122] Update cognite/client/_api/simulators/simulator_routines.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_routines.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index fddec0c83..0f363edc8 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -103,6 +103,8 @@ def retrieve_multiple( ) -> SimulatorRoutineRevisionsList: """`Retrieve simulator routine revisions `_ + Retrieve one or more simulator routine revisions by IDs or external IDs + Args: ids (Sequence[int] | None): IDs external_ids (SequenceNotStr[str] | None): External IDs From f614c494adab34175a3b428c05fe5ffcf65b5bc6 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:06:31 +0100 Subject: [PATCH 116/122] Update cognite/client/_api/simulators/simulator_integrations.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_integrations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_integrations.py b/cognite/client/_api/simulators/simulator_integrations.py index ac24a410b..376c50100 100644 --- a/cognite/client/_api/simulators/simulator_integrations.py +++ b/cognite/client/_api/simulators/simulator_integrations.py @@ -32,7 +32,7 @@ def list( ) -> SimulatorIntegrationList: """`Filter simulator integrations `_ - List simulator integrations + Retrieves a list of simulator integrations that match the given criteria Args: limit (int): The maximum number of simulator integrations to return. From 88446b459939733802b1d38c892b156f9d9b35db Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:07:31 +0100 Subject: [PATCH 117/122] Update cognite/client/_api/simulators/simulation_runs.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulation_runs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py index 49003955f..1a8136fb5 100644 --- a/cognite/client/_api/simulators/simulation_runs.py +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -30,7 +30,7 @@ def list( Args: limit (int): The maximum number of simulation runs to return. - filter (SimulationRunsFilter | dict[str, Any] | None): The filter that helps narrow down the list of simulation runs. + filter (SimulationRunsFilter | dict[str, Any] | None): Filter to apply. Returns: SimulationRunsList: List of simulation runs From 6b31e78a8c9192dda3e9ba4e3651a6576f8cf9b6 Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:09:22 +0100 Subject: [PATCH 118/122] Update cognite/client/_api/simulators/simulator_models.py Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 173a0074f..34684d41a 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -34,7 +34,7 @@ def list( ) -> SimulatorModelRevisionList: """`Filter simulator model revisions `_ - List simulator model revisions + Retrieves a list of simulator model revisions that match the given criteria Args: limit (int): The maximum number of simulator model revisions to return. From ebfe6446922cd7889be68b1189e026d07ebc3e1e Mon Sep 17 00:00:00 2001 From: Luis Pereira <91738660+lpereiracgn@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:11:45 +0100 Subject: [PATCH 119/122] Apply suggestions from code review Co-authored-by: Everton Colling <33816483+evertoncolling@users.noreply.github.com> --- cognite/client/_api/simulators/simulator_models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 34684d41a..1fb387d41 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -37,7 +37,7 @@ def list( Retrieves a list of simulator model revisions that match the given criteria Args: - limit (int): The maximum number of simulator model revisions to return. + limit (int): Maximum number of results to return. Defaults to 1000. Set to -1, float(“inf”) or None to return all items. filter (SimulatorModelRevisionsFilter | dict[str, Any] | None): Filter to apply. Returns: @@ -68,7 +68,7 @@ def list( def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModelRevision | None: """`Retrieve simulator model revision `_ - Retrieve multiple simulator model revisions by IDs or external IDs + Retrieve a simulator model revision by ID or external ID Args: id (int | None): The id of the simulator model revision. @@ -104,6 +104,8 @@ def retrieve_multiple( ) -> SimulatorModelRevisionList: """`Retrieve simulator model revisions `_ + Retrieve one or more simulator model revisions by IDs or external IDs. + Args: ids (Sequence[int] | None): IDs external_ids (SequenceNotStr[str] | None): External IDs From 433e585cf9a98cd2e5c4e0fcd66ead7d5314950d Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Thu, 12 Dec 2024 13:08:17 +0100 Subject: [PATCH 120/122] sort --- .../client/_api/simulators/simulation_runs.py | 15 ++++++++-- .../_api/simulators/simulator_models.py | 22 +++++++++------ .../_api/simulators/simulator_routines.py | 17 ++++++++--- .../data_classes/simulators/simulators.py | 28 ++++++++++++++++++- 4 files changed, 66 insertions(+), 16 deletions(-) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py index 1a8136fb5..54642b08a 100644 --- a/cognite/client/_api/simulators/simulation_runs.py +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -5,7 +5,7 @@ from cognite.client._api_client import APIClient from cognite.client._constants import DEFAULT_LIMIT_READ from cognite.client.data_classes.simulators.filters import SimulationRunsFilter -from cognite.client.data_classes.simulators.simulators import SimulationRun, SimulationRunsList +from cognite.client.data_classes.simulators.simulators import SimulationRun, SimulationRunsList, CreatedTimeSort, SimulationTimeSort from cognite.client.utils._experimental import FeaturePreviewWarning if TYPE_CHECKING: @@ -22,7 +22,10 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client ) def list( - self, limit: int = DEFAULT_LIMIT_READ, filter: SimulationRunsFilter | dict[str, Any] | None = None + self, + limit: int = DEFAULT_LIMIT_READ, + filter: SimulationRunsFilter | dict[str, Any] | None = None, + sort: CreatedTimeSort | SimulationTimeSort | None = None, ) -> SimulationRunsList: """`Filter simulation runs `_ @@ -44,6 +47,13 @@ def list( >>> res = client.simulators.runs.list() """ + + sort_by = None + if isinstance(sort, CreatedTimeSort): + sort_by = [CreatedTimeSort.load(sort).dump()] + elif isinstance(sort, SimulationTimeSort): + sort_by = [SimulationTimeSort.load(sort).dump()] + self._warning.warn() return self._list( method="POST", @@ -51,6 +61,7 @@ def list( url_path="/simulators/runs/list", resource_cls=SimulationRun, list_cls=SimulationRunsList, + sort=sort_by, filter=filter.dump() if isinstance(filter, SimulationRunsFilter) else filter diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 1fb387d41..549b303cf 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -11,6 +11,7 @@ SimulatorModelList, SimulatorModelRevision, SimulatorModelRevisionList, + CreatedTimeSort ) from cognite.client.utils._experimental import FeaturePreviewWarning from cognite.client.utils._identifier import IdentifierSequence @@ -30,7 +31,10 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client ) def list( - self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelRevisionsFilter | dict[str, Any] | None = None + self, + limit: int = DEFAULT_LIMIT_READ, + sort: CreatedTimeSort | None = None, + filter: SimulatorModelRevisionsFilter | dict[str, Any] | None = None ) -> SimulatorModelRevisionList: """`Filter simulator model revisions `_ @@ -58,6 +62,7 @@ def list( url_path="/simulators/models/revisions/list", resource_cls=SimulatorModelRevision, list_cls=SimulatorModelRevisionList, + sort=[CreatedTimeSort.load(sort).dump()] if sort else None, filter=filter.dump() if isinstance(filter, SimulatorModelRevisionsFilter) else filter @@ -100,7 +105,6 @@ def retrieve_multiple( self, ids: Sequence[int] | None = None, external_ids: SequenceNotStr[str] | None = None, - ignore_unknown_ids: bool = False, ) -> SimulatorModelRevisionList: """`Retrieve simulator model revisions `_ @@ -129,7 +133,6 @@ def retrieve_multiple( list_cls=SimulatorModelRevisionList, resource_cls=SimulatorModelRevision, identifiers=identifiers, - ignore_unknown_ids=ignore_unknown_ids, ) @@ -144,7 +147,10 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client ) def list( - self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelsFilter | dict[str, Any] | None = None + self, + limit: int = DEFAULT_LIMIT_READ, + filter: SimulatorModelsFilter | dict[str, Any] | None = None, + sort: CreatedTimeSort | None = None, ) -> SimulatorModelList: """`Filter simulator models `_ @@ -173,6 +179,7 @@ def list( url_path="/simulators/models/list", resource_cls=SimulatorModel, list_cls=SimulatorModelList, + sort=[CreatedTimeSort.load(sort).dump()] if sort else None, filter=filter.dump() if isinstance(filter, SimulatorModelsFilter) else filter @@ -194,15 +201,12 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Sim Examples: - List simulator models: + Retrieve simulator model by id: >>> from cognite.client import CogniteClient >>> client = CogniteClient() - >>> res = client.simulators.models.list() - - Get simulator model by id: >>> res = client.simulators.models.retrieve(id=1) - Get simulator model by external id: + Retrieve simulator model by external id: >>> res = client.simulators.models.retrieve(external_id="1") """ diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 0f363edc8..46c1a870b 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -1,7 +1,7 @@ from __future__ import annotations from collections.abc import Sequence -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, Literal from cognite.client._api_client import APIClient from cognite.client._constants import DEFAULT_LIMIT_READ @@ -11,6 +11,7 @@ SimulatorRoutineList, SimulatorRoutineRevision, SimulatorRoutineRevisionsList, + CreatedTimeSort, ) from cognite.client.utils._experimental import FeaturePreviewWarning from cognite.client.utils._identifier import IdentifierSequence @@ -19,7 +20,6 @@ if TYPE_CHECKING: from cognite.client import ClientConfig, CogniteClient - class SimulatorRoutineRevisionsAPI(APIClient): _RESOURCE_PATH = "/simulators/routines/revisions" @@ -30,7 +30,11 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client ) def list( - self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutineRevisionsFilter | dict[str, Any] | None = None + self, + limit: int = 20, # the maximum number of revisions to return is limited to 20 items. + sort: CreatedTimeSort | None = None, + filter: SimulatorRoutineRevisionsFilter | dict[str, Any] | None = None, + includeAllFields: bool = False, ) -> SimulatorRoutineRevisionsList: """`Filter simulator routine revisions `_ @@ -63,6 +67,8 @@ def list( else filter if isinstance(filter, dict) else None, + sort=[CreatedTimeSort.load(sort).dump()] if sort else None, + other_params={"includeAllFields": includeAllFields}, ) def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorRoutineRevision | None: @@ -143,7 +149,9 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client ) def list( - self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutinesFilter | dict[str, Any] | None = None + self, + limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutinesFilter | dict[str, Any] | None = None, + sort: CreatedTimeSort | None = None, ) -> SimulatorRoutineList: """`Filter simulator routines `_ @@ -172,6 +180,7 @@ def list( url_path="/simulators/routines/list", resource_cls=SimulatorRoutine, list_cls=SimulatorRoutineList, + sort=[CreatedTimeSort.load(sort).dump()] if sort else None, filter=filter.dump() if isinstance(filter, SimulatorRoutinesFilter) else filter diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index 99f3d3d01..ee92778f6 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -3,7 +3,8 @@ from abc import ABC from collections.abc import Sequence from dataclasses import dataclass -from typing import TYPE_CHECKING, Any +from enum import auto +from typing import TYPE_CHECKING, Any, Literal, TypeAlias from typing_extensions import Self @@ -16,6 +17,8 @@ InternalIdTransformerMixin, WriteableCogniteResource, WriteableCogniteResourceList, + EnumProperty, + CogniteSort ) from cognite.client.utils.useful_types import SequenceNotStr @@ -1526,6 +1529,29 @@ def __hash__(self) -> int: return hash(self.external_id) +class PropertySort(CogniteSort): + + def dump(self, camel_case: bool = True) -> dict[str, Any]: + dumped = super().dump(camel_case=camel_case) + dumped["property"] = self.property + return dumped + +class CreatedTimeSort(PropertySort): + def __init__( + self, + property: Literal["createdTime"] = "createdTime", + order: Literal["asc", "desc"] = "asc", + ): + super().__init__(property, order) + +class SimulationTimeSort(PropertySort): + def __init__( + self, + property: Literal["simulationTime"] = "simulationTime", + order: Literal["asc", "desc"] = "asc", + ): + super().__init__(property, order) + class SimulatorRoutineRevisionWriteList(CogniteResourceList[SimulatorRoutineRevisionWrite], ExternalIDTransformerMixin): _RESOURCE = SimulatorRoutineRevisionWrite From 9428ecb180e83fe14ce27fd555a373db05a9a122 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Thu, 12 Dec 2024 16:03:17 +0100 Subject: [PATCH 121/122] tests --- .../client/_api/simulators/simulation_runs.py | 7 +- .../_api/simulators/simulator_models.py | 32 ++-- .../_api/simulators/simulator_routines.py | 38 ++-- .../data_classes/simulators/__init__.py | 82 ++++----- .../data_classes/simulators/simulators.py | 10 +- .../test_api/test_simulators/seed/data.py | 5 +- .../test_simulators/test_simulators.py | 165 +++++++++++++----- 7 files changed, 208 insertions(+), 131 deletions(-) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py index 54642b08a..615b127fc 100644 --- a/cognite/client/_api/simulators/simulation_runs.py +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -5,7 +5,12 @@ from cognite.client._api_client import APIClient from cognite.client._constants import DEFAULT_LIMIT_READ from cognite.client.data_classes.simulators.filters import SimulationRunsFilter -from cognite.client.data_classes.simulators.simulators import SimulationRun, SimulationRunsList, CreatedTimeSort, SimulationTimeSort +from cognite.client.data_classes.simulators.simulators import ( + CreatedTimeSort, + SimulationRun, + SimulationRunsList, + SimulationTimeSort, +) from cognite.client.utils._experimental import FeaturePreviewWarning if TYPE_CHECKING: diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index 549b303cf..e6f5a194c 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -7,11 +7,11 @@ from cognite.client._constants import DEFAULT_LIMIT_READ from cognite.client.data_classes.simulators.filters import SimulatorModelRevisionsFilter, SimulatorModelsFilter from cognite.client.data_classes.simulators.simulators import ( + CreatedTimeSort, SimulatorModel, SimulatorModelList, SimulatorModelRevision, SimulatorModelRevisionList, - CreatedTimeSort ) from cognite.client.utils._experimental import FeaturePreviewWarning from cognite.client.utils._identifier import IdentifierSequence @@ -34,7 +34,7 @@ def list( self, limit: int = DEFAULT_LIMIT_READ, sort: CreatedTimeSort | None = None, - filter: SimulatorModelRevisionsFilter | dict[str, Any] | None = None + filter: SimulatorModelRevisionsFilter | dict[str, Any] | None = None, ) -> SimulatorModelRevisionList: """`Filter simulator model revisions `_ @@ -108,25 +108,25 @@ def retrieve_multiple( ) -> SimulatorModelRevisionList: """`Retrieve simulator model revisions `_ - Retrieve one or more simulator model revisions by IDs or external IDs. + Retrieve one or more simulator model revisions by IDs or external IDs. - Args: - ids (Sequence[int] | None): IDs - external_ids (SequenceNotStr[str] | None): External IDs - ignore_unknown_ids (bool): Ignore IDs and external IDs that are not found rather than throw an exception. + Args: + ids (Sequence[int] | None): IDs + external_ids (SequenceNotStr[str] | None): External IDs + ignore_unknown_ids (bool): Ignore IDs and external IDs that are not found rather than throw an exception. - Returns: - SimulatorModelRevisionList: Requested simulator model revisions + Returns: + SimulatorModelRevisionList: Requested simulator model revisions - Examples: + Examples: - Get simulator model revisions by ids: - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> res = client.simulators.models.revisions.retrieve_multiple(ids=[1, 2, 3]) + Get simulator model revisions by ids: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.models.revisions.retrieve_multiple(ids=[1, 2, 3]) - Get simulator model revisions by external ids: - >>> res = client.simulators.models.revisions.retrieve_multiple(external_ids=["abc", "def"]) + Get simulator model revisions by external ids: + >>> res = client.simulators.models.revisions.retrieve_multiple(external_ids=["abc", "def"]) """ identifiers = IdentifierSequence.load(ids=ids, external_ids=external_ids) return self._retrieve_multiple( diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index 46c1a870b..e80bc8207 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -1,17 +1,17 @@ from __future__ import annotations from collections.abc import Sequence -from typing import TYPE_CHECKING, Any, Literal +from typing import TYPE_CHECKING, Any from cognite.client._api_client import APIClient from cognite.client._constants import DEFAULT_LIMIT_READ from cognite.client.data_classes.simulators.filters import SimulatorRoutineRevisionsFilter, SimulatorRoutinesFilter from cognite.client.data_classes.simulators.simulators import ( + CreatedTimeSort, SimulatorRoutine, SimulatorRoutineList, SimulatorRoutineRevision, SimulatorRoutineRevisionsList, - CreatedTimeSort, ) from cognite.client.utils._experimental import FeaturePreviewWarning from cognite.client.utils._identifier import IdentifierSequence @@ -20,6 +20,7 @@ if TYPE_CHECKING: from cognite.client import ClientConfig, CogniteClient + class SimulatorRoutineRevisionsAPI(APIClient): _RESOURCE_PATH = "/simulators/routines/revisions" @@ -31,7 +32,7 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client def list( self, - limit: int = 20, # the maximum number of revisions to return is limited to 20 items. + limit: int = 20, # the maximum number of revisions to return is limited to 20 items. sort: CreatedTimeSort | None = None, filter: SimulatorRoutineRevisionsFilter | dict[str, Any] | None = None, includeAllFields: bool = False, @@ -109,25 +110,25 @@ def retrieve_multiple( ) -> SimulatorRoutineRevisionsList: """`Retrieve simulator routine revisions `_ - Retrieve one or more simulator routine revisions by IDs or external IDs + Retrieve one or more simulator routine revisions by IDs or external IDs - Args: - ids (Sequence[int] | None): IDs - external_ids (SequenceNotStr[str] | None): External IDs - ignore_unknown_ids (bool): Ignore IDs and external IDs that are not found rather than throw an exception. + Args: + ids (Sequence[int] | None): IDs + external_ids (SequenceNotStr[str] | None): External IDs + ignore_unknown_ids (bool): Ignore IDs and external IDs that are not found rather than throw an exception. - Returns: - SimulatorRoutineRevisionsList: Requested simulator routine revisions + Returns: + SimulatorRoutineRevisionsList: Requested simulator routine revisions - Examples: + Examples: - Get simulator routine revisions by id: - >>> from cognite.client import CogniteClient - >>> client = CogniteClient() - >>> res = client.simulators.routines.revisions.retrieve_multiple(ids=[1, 2, 3]) + Get simulator routine revisions by id: + >>> from cognite.client import CogniteClient + >>> client = CogniteClient() + >>> res = client.simulators.routines.revisions.retrieve_multiple(ids=[1, 2, 3]) - Get simulator routine revisions by external id: - >>> res = client.simulators.routines.revisions.retrieve_multiple(external_ids=["abc", "def"]) + Get simulator routine revisions by external id: + >>> res = client.simulators.routines.revisions.retrieve_multiple(external_ids=["abc", "def"]) """ identifiers = IdentifierSequence.load(ids=ids, external_ids=external_ids) return self._retrieve_multiple( @@ -150,7 +151,8 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client def list( self, - limit: int = DEFAULT_LIMIT_READ, filter: SimulatorRoutinesFilter | dict[str, Any] | None = None, + limit: int = DEFAULT_LIMIT_READ, + filter: SimulatorRoutinesFilter | dict[str, Any] | None = None, sort: CreatedTimeSort | None = None, ) -> SimulatorRoutineList: """`Filter simulator routines `_ diff --git a/cognite/client/data_classes/simulators/__init__.py b/cognite/client/data_classes/simulators/__init__.py index 77212f705..16b1e6985 100644 --- a/cognite/client/data_classes/simulators/__init__.py +++ b/cognite/client/data_classes/simulators/__init__.py @@ -56,56 +56,56 @@ ) __all__ = [ + "SimulationRun", + "SimulationRunCore", + "SimulationRunsList", "SimulationValueUnitInput", - "SimulatorRoutineInputTimeseries", - "SimulatorRoutineInputConstant", - "SimulatorRoutineOutput", - "SimulatorRoutineSchedule", - "SimulatorRoutineDataSampling", - "SimulatorRoutineLogicalCheckEnabled", - "SimulatorRoutineSteadyStateDetectionEnabled", - "SimulatorRoutineConfiguration", - "SimulatorRoutineStepArguments", - "SimulatorRoutineStep", - "SimulatorRoutineStage", - "SimulatorUnitEntry", - "SimulatorStepOption", - "SimulatorModelType", - "SimulatorQuantity", - "SimulatorStepField", - "SimulatorStep", - "SimulatorCore", - "SimulatorWrite", "Simulator", + "SimulatorCore", + "SimulatorIntegration", "SimulatorIntegrationCore", + "SimulatorIntegrationList", "SimulatorIntegrationWrite", - "SimulatorIntegration", + "SimulatorIntegrationWriteList", + "SimulatorList", + "SimulatorModel", + "SimulatorModelCore", + "SimulatorModelList", + "SimulatorModelRevision", "SimulatorModelRevisionCore", + "SimulatorModelRevisionList", "SimulatorModelRevisionWrite", - "SimulatorModelRevision", - "SimulatorRoutineRevisionCore", - "SimulatorRoutineRevisionWrite", - "SimulatorRoutineRevision", - "SimulatorModelCore", + "SimulatorModelRevisionWriteList", + "SimulatorModelType", "SimulatorModelWrite", - "SimulatorModel", - "SimulationRunCore", - "SimulationRun", - "SimulatorRoutineCore", - "SimulatorRoutineWrite", + "SimulatorModelWriteList", + "SimulatorQuantity", "SimulatorRoutine", - "SimulatorRoutineRevisionWriteList", - "SimulatorRoutineRevisionList", - "SimulatorRoutineWriteList", + "SimulatorRoutineConfiguration", + "SimulatorRoutineCore", + "SimulatorRoutineDataSampling", + "SimulatorRoutineInputConstant", + "SimulatorRoutineInputTimeseries", "SimulatorRoutineList", + "SimulatorRoutineLogicalCheckEnabled", + "SimulatorRoutineOutput", + "SimulatorRoutineRevision", + "SimulatorRoutineRevisionCore", + "SimulatorRoutineRevisionList", + "SimulatorRoutineRevisionWrite", + "SimulatorRoutineRevisionWriteList", "SimulatorRoutineRevisionsList", + "SimulatorRoutineSchedule", + "SimulatorRoutineStage", + "SimulatorRoutineSteadyStateDetectionEnabled", + "SimulatorRoutineStep", + "SimulatorRoutineStepArguments", + "SimulatorRoutineWrite", + "SimulatorRoutineWriteList", + "SimulatorStep", + "SimulatorStepField", + "SimulatorStepOption", + "SimulatorUnitEntry", + "SimulatorWrite", "SimulatorWriteList", - "SimulatorList", - "SimulatorIntegrationWriteList", - "SimulatorIntegrationList", - "SimulatorModelWriteList", - "SimulatorModelList", - "SimulatorModelRevisionWriteList", - "SimulatorModelRevisionList", - "SimulationRunsList", ] diff --git a/cognite/client/data_classes/simulators/simulators.py b/cognite/client/data_classes/simulators/simulators.py index ee92778f6..a77f16f8e 100644 --- a/cognite/client/data_classes/simulators/simulators.py +++ b/cognite/client/data_classes/simulators/simulators.py @@ -3,8 +3,7 @@ from abc import ABC from collections.abc import Sequence from dataclasses import dataclass -from enum import auto -from typing import TYPE_CHECKING, Any, Literal, TypeAlias +from typing import TYPE_CHECKING, Any, Literal from typing_extensions import Self @@ -12,13 +11,12 @@ CogniteObject, CogniteResource, CogniteResourceList, + CogniteSort, ExternalIDTransformerMixin, IdTransformerMixin, InternalIdTransformerMixin, WriteableCogniteResource, WriteableCogniteResourceList, - EnumProperty, - CogniteSort ) from cognite.client.utils.useful_types import SequenceNotStr @@ -1530,12 +1528,12 @@ def __hash__(self) -> int: class PropertySort(CogniteSort): - def dump(self, camel_case: bool = True) -> dict[str, Any]: dumped = super().dump(camel_case=camel_case) dumped["property"] = self.property return dumped + class CreatedTimeSort(PropertySort): def __init__( self, @@ -1544,6 +1542,7 @@ def __init__( ): super().__init__(property, order) + class SimulationTimeSort(PropertySort): def __init__( self, @@ -1552,6 +1551,7 @@ def __init__( ): super().__init__(property, order) + class SimulatorRoutineRevisionWriteList(CogniteResourceList[SimulatorRoutineRevisionWrite], ExternalIDTransformerMixin): _RESOURCE = SimulatorRoutineRevisionWrite diff --git a/tests/tests_integration/test_api/test_simulators/seed/data.py b/tests/tests_integration/test_api/test_simulators/seed/data.py index 6915628e3..e3f18cde7 100644 --- a/tests/tests_integration/test_api/test_simulators/seed/data.py +++ b/tests/tests_integration/test_api/test_simulators/seed/data.py @@ -1,7 +1,8 @@ import time -data_set_id = 1521375514069 -development_data_set_id = 97552494921583 +# data_set_id = 1521375514069 +# development_data_set_id = 97552494921583 +data_set_id = 97552494921583 resource_names = { "simulator_external_id": "py_sdk_integration_tests", diff --git a/tests/tests_integration/test_api/test_simulators/test_simulators.py b/tests/tests_integration/test_api/test_simulators/test_simulators.py index aa8a7cd6a..d9c2aa90d 100644 --- a/tests/tests_integration/test_api/test_simulators/test_simulators.py +++ b/tests/tests_integration/test_api/test_simulators/test_simulators.py @@ -1,5 +1,6 @@ import random import time +import uuid import pytest @@ -9,7 +10,10 @@ SimulatorIntegrationFilter, SimulatorModelRevisionsFilter, SimulatorModelsFilter, + SimulatorRoutineRevisionsFilter, + SimulatorRoutinesFilter, ) +from cognite.client.data_classes.simulators.simulators import CreatedTimeSort from cognite.client.exceptions import CogniteAPIError from tests.tests_integration.test_api.test_simulators.seed.data import ( data_set_id, @@ -22,7 +26,14 @@ simulator_routine_revision, ) -model_unique_external_id = f"{resource_names['simulator_model_external_id']}_{random.randint(100,500)}" + +def truncated_uuid4(): + return str(uuid.uuid4())[:8] + + +model_unique_external_id = f"{resource_names['simulator_model_external_id']}_{truncated_uuid4()}" +model_revision_unique_external_id = f"{resource_names['simulator_model_revision_external_id']}_{truncated_uuid4()}" +simulator_routine_unique_external_id = f"{resource_names['simulator_routine_external_id']}_{truncated_uuid4()}" @pytest.fixture(scope="class") @@ -82,65 +93,85 @@ def seed_simulator_integration(cognite_client: CogniteClient, seed_simulator) -> @pytest.fixture def seed_simulator_models(cognite_client: CogniteClient, seed_simulator_integration) -> None: models = cognite_client.simulators.models.list() - model_seed = list(filter(lambda x: x.external_id == model_unique_external_id, models)) + model_exists = len(list(filter(lambda x: x.external_id == model_unique_external_id, models))) > 0 - if len(model_seed) > 0: + if not model_exists: cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators/models/delete", - json={"items": [{"id": model_seed[0].id}]}, # Post actual simulator models here + f"/api/v1/projects/{cognite_client.config.project}/simulators/models", + json={ + "items": [{**simulator_model, "externalId": model_unique_external_id}] + }, # Post actual simulator models here ) - cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators/models", - json={ - "items": [{**simulator_model, "externalId": model_unique_external_id}] - }, # Post actual simulator models here - ) - - yield - - models = cognite_client.simulators.models.list() - model_seed = list(filter(lambda x: x.external_id == model_unique_external_id, models)) - - cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators/models/delete", - json={"items": [{"id": model_seed[0].id}]}, # Post actual simulator models here - ) - @pytest.fixture def seed_simulator_model_revisions(cognite_client: CogniteClient, seed_simulator_models, seed_file) -> None: - cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators/models/revisions", - json={ - "items": [{**simulator_model_revision, "fileId": seed_file.id, "modelExternalId": model_unique_external_id}] - }, # Post actual simulator models here + model_revisions = cognite_client.simulators.models.revisions.list( + filter=SimulatorModelRevisionsFilter(model_external_ids=[model_unique_external_id]) ) + model_revision_not_exists = ( + len(list(filter(lambda x: x.external_id == model_revision_unique_external_id, model_revisions))) == 0 + ) + + if model_revision_not_exists: + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/models/revisions", + json={ + "items": [ + { + **simulator_model_revision, + "fileId": seed_file.id, + "modelExternalId": model_unique_external_id, + "externalId": model_revision_unique_external_id, + } + ] + }, + ) @pytest.fixture def seed_simulator_routines(cognite_client: CogniteClient, seed_simulator_model_revisions) -> None: - cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators/routines", - json={"items": [{**simulator_routine, "modelExternalId": model_unique_external_id}]}, + routines = cognite_client.simulators.routines.list( + filter=SimulatorRoutinesFilter(model_external_ids=[model_unique_external_id]) ) + routine_not_exists = ( + len(list(filter(lambda x: x.external_id == simulator_routine_unique_external_id, routines))) == 0 + ) + + if routine_not_exists: + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/routines", + json={ + "items": [ + { + **simulator_routine, + "modelExternalId": model_unique_external_id, + "externalId": simulator_routine_unique_external_id, + } + ] + }, + ) @pytest.fixture def seed_simulator_routine_revisions(cognite_client: CogniteClient, seed_simulator_routines) -> None: - cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators/routines/revisions", - json={"items": [simulator_routine_revision]}, + revisions_all = cognite_client.simulators.routines.revisions.list( + filter=SimulatorRoutineRevisionsFilter( + routine_external_ids=[simulator_routine_unique_external_id], all_versions=True + ), ) - -@pytest.fixture -def delete_simulator(cognite_client: CogniteClient, seed_resource_names) -> None: - yield - cognite_client.post( - f"/api/v1/projects/{cognite_client.config.project}/simulators/delete", - json={"items": [{"externalId": seed_resource_names["simulator_external_id"]}]}, - ) + if len(revisions_all) == 0: + for _ in range(10): + revision = { + **simulator_routine_revision, + "externalId": f"{simulator_routine_revision['externalId']}_{truncated_uuid4()}", + "routineExternalId": simulator_routine_unique_external_id, + } + cognite_client.post( + f"/api/v1/projects/{cognite_client.config.project}/simulators/routines/revisions", + json={"items": [revision]}, + ) @pytest.mark.usefixtures("seed_resource_names", "seed_simulator") @@ -194,7 +225,7 @@ def test_retrieve_model(self, cognite_client: CogniteClient, seed_resource_names assert model.external_id == model_unique_external_id def test_list_model_revisions(self, cognite_client: CogniteClient, seed_resource_names) -> None: - revisions = cognite_client.simulators.models.list( + revisions = cognite_client.simulators.models.revisions.list( limit=5, filter=SimulatorModelRevisionsFilter(model_external_ids=[model_unique_external_id]), ) @@ -202,7 +233,7 @@ def test_list_model_revisions(self, cognite_client: CogniteClient, seed_resource def test_retrieve_model_revision(self, cognite_client: CogniteClient, seed_resource_names) -> None: model_revision = cognite_client.simulators.models.revisions.retrieve( - external_id=seed_resource_names["simulator_model_revision_external_id"] + external_id=model_revision_unique_external_id ) assert model_revision is not None assert model_revision.model_external_id == model_unique_external_id @@ -214,8 +245,46 @@ def test_list_routines(self, cognite_client: CogniteClient) -> None: routines = cognite_client.simulators.routines.list(limit=5) assert len(routines) > 0 - def test_list_routine_revisions(self, cognite_client: CogniteClient) -> None: - revisions = cognite_client.simulators.routines.revisions.list(limit=5) - assert revisions[0].configuration is not None - assert revisions[0].script is not None - assert len(revisions) > 0 + def test_list_and_filtering_routine_revisions(self, cognite_client: CogniteClient) -> None: + revisions_all = cognite_client.simulators.routines.revisions.list( + filter=SimulatorRoutineRevisionsFilter( + routine_external_ids=[simulator_routine_unique_external_id], all_versions=True + ), + ) + assert len(revisions_all) > 1 + revisions_filter = cognite_client.simulators.routines.revisions.list( + filter=SimulatorRoutineRevisionsFilter(model_external_ids=[model_unique_external_id], all_versions=True), + ) + assert len(revisions_filter) == 10 + revisions_sort_asc = cognite_client.simulators.routines.revisions.list( + sort=CreatedTimeSort(order="asc", property="createdTime"), + filter=SimulatorRoutineRevisionsFilter( + routine_external_ids=[simulator_routine_unique_external_id], all_versions=True + ), + ) + revisions_sort_desc = cognite_client.simulators.routines.revisions.list( + sort=CreatedTimeSort(order="desc", property="createdTime"), + filter=SimulatorRoutineRevisionsFilter( + routine_external_ids=[simulator_routine_unique_external_id], all_versions=True + ), + ) + assert revisions_sort_asc[0].external_id == revisions_sort_desc[-1].external_id + + def test_retrieve_routine_revision(self, cognite_client: CogniteClient) -> None: + revisions_all = cognite_client.simulators.routines.revisions.list( + filter=SimulatorRoutineRevisionsFilter( + routine_external_ids=[simulator_routine_unique_external_id], all_versions=True + ), + ) + + assert len(revisions_all) > 5 + + rev1 = revisions_all[random.randint(0, 4)] + rev2 = revisions_all[random.randint(0, 4)] + + rev1_retrieve = cognite_client.simulators.routines.revisions.retrieve(external_id=rev1.external_id) + assert rev1_retrieve is not None + assert rev1_retrieve.external_id == rev1.external_id + rev2_retrieve = cognite_client.simulators.routines.revisions.retrieve(external_id=rev2.external_id) + assert rev2_retrieve is not None + assert rev2_retrieve.external_id == rev2.external_id From 74013681625b39f69d107ff9c927b9d8a34c903c Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Fri, 13 Dec 2024 08:17:46 +0100 Subject: [PATCH 122/122] fix docstrings --- cognite/client/_api/simulators/simulation_runs.py | 1 + cognite/client/_api/simulators/simulator_models.py | 2 ++ cognite/client/_api/simulators/simulator_routines.py | 7 +++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cognite/client/_api/simulators/simulation_runs.py b/cognite/client/_api/simulators/simulation_runs.py index 615b127fc..805d43513 100644 --- a/cognite/client/_api/simulators/simulation_runs.py +++ b/cognite/client/_api/simulators/simulation_runs.py @@ -39,6 +39,7 @@ def list( Args: limit (int): The maximum number of simulation runs to return. filter (SimulationRunsFilter | dict[str, Any] | None): Filter to apply. + sort (CreatedTimeSort | SimulationTimeSort | None): Sort simulation runs by created time or simulation time. Returns: SimulationRunsList: List of simulation runs diff --git a/cognite/client/_api/simulators/simulator_models.py b/cognite/client/_api/simulators/simulator_models.py index e6f5a194c..5174ad8c6 100644 --- a/cognite/client/_api/simulators/simulator_models.py +++ b/cognite/client/_api/simulators/simulator_models.py @@ -42,6 +42,7 @@ def list( Args: limit (int): Maximum number of results to return. Defaults to 1000. Set to -1, float(“inf”) or None to return all items. + sort (CreatedTimeSort | None): Sort order for the results. filter (SimulatorModelRevisionsFilter | dict[str, Any] | None): Filter to apply. Returns: @@ -159,6 +160,7 @@ def list( Args: limit (int): Maximum number of results to return. Defaults to 1000. Set to -1, float(“inf”) or None to return all items. filter (SimulatorModelsFilter | dict[str, Any] | None): Filter to apply. + sort (CreatedTimeSort | None): The criteria to sort by. Returns: SimulatorModelList: List of simulator models diff --git a/cognite/client/_api/simulators/simulator_routines.py b/cognite/client/_api/simulators/simulator_routines.py index e80bc8207..5d40998a4 100644 --- a/cognite/client/_api/simulators/simulator_routines.py +++ b/cognite/client/_api/simulators/simulator_routines.py @@ -35,7 +35,7 @@ def list( limit: int = 20, # the maximum number of revisions to return is limited to 20 items. sort: CreatedTimeSort | None = None, filter: SimulatorRoutineRevisionsFilter | dict[str, Any] | None = None, - includeAllFields: bool = False, + include_all_fields: bool = False, ) -> SimulatorRoutineRevisionsList: """`Filter simulator routine revisions `_ @@ -43,7 +43,9 @@ def list( Args: limit (int): Maximum number of results to return. Defaults to 10. Set to -1, float(“inf”) or None to return all items. + sort (CreatedTimeSort | None): The criteria to sort by. filter (SimulatorRoutineRevisionsFilter | dict[str, Any] | None): Filter to apply. + include_all_fields (bool): If all fields should be included in the response. Defaults to false which does not include script, configuration.inputs and configuration.outputs in the response. Returns: SimulatorRoutineRevisionsList: List of simulator routine revisions @@ -69,7 +71,7 @@ def list( if isinstance(filter, dict) else None, sort=[CreatedTimeSort.load(sort).dump()] if sort else None, - other_params={"includeAllFields": includeAllFields}, + other_params={"includeAllFields": include_all_fields}, ) def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorRoutineRevision | None: @@ -162,6 +164,7 @@ def list( Args: limit (int): Maximum number of results to return. Defaults to 1000. Set to -1, float(“inf”) or None to return all items. filter (SimulatorRoutinesFilter | dict[str, Any] | None): The filter to narrow down simulator routines. + sort (CreatedTimeSort | None): The criteria to sort by. Returns: SimulatorRoutineList: List of simulator routines