-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simulators API #2006
base: master
Are you sure you want to change the base?
Simulators API #2006
Changes from 1 commit
f42cc6c
8e936c2
67f3680
2852e9f
4fb7728
8a96799
f061996
2a67cb5
966f31d
947c0c2
f25b46d
741c6a0
7c5fc0f
3460781
7d5e13c
4061ed2
ef47c43
7de0581
bd058e4
0fd679d
76d3c51
a70bab1
74ae117
e041dad
c940dbc
5a9f01e
079075b
27fe6bd
8e7ae96
2001b37
3a5a139
75c6189
334bfad
281a669
5947ad7
b6672ff
5d09fb0
016227c
7bd1684
a3d3a04
e01cec3
e9bde70
47d33a7
985e1ff
ce5c8f1
0a37df1
5fff3a4
6b82751
774252b
8991a38
e4d437e
00e56c6
5342df5
70833ab
2a6ae37
aa7702b
3473533
2400a67
78d2d79
cd40c3b
5e4e0af
f0139d0
bb51ef6
2fb1eef
b668282
c8527a9
9798475
c076dc9
77d431b
e43ce27
f49d9fa
b683f02
b1b5c9d
7084a4d
4d5fa3b
dbbe91a
9520e8a
66f4074
655d298
92b3d9a
c316ce3
560188b
7b7d82b
5a77f2e
fd3342b
d7236a8
64cd8b5
2a06f98
6e795d6
3560687
48d6195
eb024db
c75f492
c104a3b
6718fb4
960775a
6bdc7f3
1cdc8b2
9fead1a
5d125bd
d15226f
eef86be
bb04cca
a48b626
c76eab1
d5600fb
f12fb21
60c83a0
4898f54
9945ff8
c8180cb
16fe676
cd4498c
1c85b88
7def138
49ad5fc
6e4f8bb
0a9d007
68bf6a8
d79b8ff
daf3e8a
f614c49
88446b4
6b31e78
ebfe644
433e585
9428ecb
7401368
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 <https://developer.cognite.com/api#tag/Simulation-Runs/operation/filter_simulation_runs_simulators_runs_list_post>`_ | ||||||
|
||||||
|
@@ -44,13 +47,21 @@ 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", | ||||||
limit=limit, | ||||||
url_path="/simulators/runs/list", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed as this follows the API design guidelines
Suggested change
|
||||||
resource_cls=SimulationRun, | ||||||
list_cls=SimulationRunsList, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This list class needs to be renamed:
Suggested change
|
||||||
sort=sort_by, | ||||||
filter=filter.dump() | ||||||
if isinstance(filter, SimulationRunsFilter) | ||||||
else filter | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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( | ||||||
lpereiracgn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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 <https://developer.cognite.com/api#tag/Simulator-Models/operation/filter_simulator_model_revisions_simulators_models_revisions_list_post>`_ | ||||||
|
||||||
|
@@ -58,6 +62,7 @@ def list( | |||||
url_path="/simulators/models/revisions/list", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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 <https://developer.cognite.com/api#tag/Simulator-Models/operation/retrieve_simulator_model_revisions_simulators_models_revisions_byids_post>`_ | ||||||
|
||||||
lpereiracgn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
@@ -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( | ||||||
lpereiracgn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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 <https://developer.cognite.com/api#tag/Simulator-Models/operation/filter_simulator_models_simulators_models_list_post>`_ | ||||||
|
||||||
|
@@ -173,6 +179,7 @@ def list( | |||||
url_path="/simulators/models/list", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please avoid using numbers when illustrating usage of external ID 😄
Suggested change
|
||||||
|
||||||
""" | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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( | ||||||
lpereiracgn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐍
Suggested change
|
||||||
) -> SimulatorRoutineRevisionsList: | ||||||
"""`Filter simulator routine revisions <https://developer.cognite.com/api#tag/Simulator-Routines/operation/filter_simulator_routine_revisions_simulators_routines_revisions_list_post>`_ | ||||||
|
||||||
|
@@ -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}, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) | ||||||
|
||||||
def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorRoutineRevision | None: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here as above, merge Remember to set |
||||||
|
@@ -143,7 +149,9 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client | |||||
) | ||||||
|
||||||
def list( | ||||||
lpereiracgn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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 <https://developer.cognite.com/api#tag/Simulator-Routines/operation/filter_simulator_routines_simulators_routines_list_post>`_ | ||||||
|
||||||
|
@@ -172,6 +180,7 @@ def list( | |||||
url_path="/simulators/routines/list", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
resource_cls=SimulatorRoutine, | ||||||
list_cls=SimulatorRoutineList, | ||||||
sort=[CreatedTimeSort.load(sort).dump()] if sort else None, | ||||||
filter=filter.dump() | ||||||
if isinstance(filter, SimulatorRoutinesFilter) | ||||||
else filter | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be enough? Also see my other comment regarding these sort-classes.