cognite-toolkit 0.6.97__py3-none-any.whl → 0.7.39__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cognite_toolkit/_cdf.py +21 -23
- cognite_toolkit/_cdf_tk/apps/__init__.py +4 -0
- cognite_toolkit/_cdf_tk/apps/_core_app.py +19 -5
- cognite_toolkit/_cdf_tk/apps/_data_app.py +1 -1
- cognite_toolkit/_cdf_tk/apps/_dev_app.py +86 -0
- cognite_toolkit/_cdf_tk/apps/_download_app.py +693 -25
- cognite_toolkit/_cdf_tk/apps/_dump_app.py +44 -102
- cognite_toolkit/_cdf_tk/apps/_import_app.py +41 -0
- cognite_toolkit/_cdf_tk/apps/_landing_app.py +18 -4
- cognite_toolkit/_cdf_tk/apps/_migrate_app.py +424 -9
- cognite_toolkit/_cdf_tk/apps/_modules_app.py +0 -3
- cognite_toolkit/_cdf_tk/apps/_purge.py +15 -43
- cognite_toolkit/_cdf_tk/apps/_run.py +11 -0
- cognite_toolkit/_cdf_tk/apps/_upload_app.py +45 -6
- cognite_toolkit/_cdf_tk/builders/__init__.py +2 -2
- cognite_toolkit/_cdf_tk/builders/_base.py +28 -42
- cognite_toolkit/_cdf_tk/builders/_raw.py +1 -1
- cognite_toolkit/_cdf_tk/cdf_toml.py +20 -1
- cognite_toolkit/_cdf_tk/client/_toolkit_client.py +32 -12
- cognite_toolkit/_cdf_tk/client/api/infield.py +114 -17
- cognite_toolkit/_cdf_tk/client/api/{canvas.py → legacy/canvas.py} +15 -7
- cognite_toolkit/_cdf_tk/client/api/{charts.py → legacy/charts.py} +1 -1
- cognite_toolkit/_cdf_tk/client/api/{extended_data_modeling.py → legacy/extended_data_modeling.py} +1 -1
- cognite_toolkit/_cdf_tk/client/api/{extended_files.py → legacy/extended_files.py} +2 -2
- cognite_toolkit/_cdf_tk/client/api/{extended_functions.py → legacy/extended_functions.py} +15 -18
- cognite_toolkit/_cdf_tk/client/api/{extended_raw.py → legacy/extended_raw.py} +1 -1
- cognite_toolkit/_cdf_tk/client/api/{extended_timeseries.py → legacy/extended_timeseries.py} +5 -2
- cognite_toolkit/_cdf_tk/client/api/{location_filters.py → legacy/location_filters.py} +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/__init__.py +8 -0
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/capabilities.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/data_postprocessing.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/frames.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/locations.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/maps.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/robots.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/{search_config.py → legacy/search_config.py} +5 -1
- cognite_toolkit/_cdf_tk/client/api/migration.py +177 -4
- cognite_toolkit/_cdf_tk/client/api/project.py +9 -8
- cognite_toolkit/_cdf_tk/client/api/search.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/streams.py +88 -0
- cognite_toolkit/_cdf_tk/client/api/three_d.py +384 -0
- cognite_toolkit/_cdf_tk/client/data_classes/api_classes.py +13 -0
- cognite_toolkit/_cdf_tk/client/data_classes/base.py +37 -33
- cognite_toolkit/_cdf_tk/client/data_classes/charts_data.py +95 -213
- cognite_toolkit/_cdf_tk/client/data_classes/infield.py +32 -18
- cognite_toolkit/_cdf_tk/client/data_classes/instance_api.py +18 -13
- cognite_toolkit/_cdf_tk/client/data_classes/legacy/__init__.py +0 -0
- cognite_toolkit/_cdf_tk/client/data_classes/{canvas.py → legacy/canvas.py} +47 -4
- cognite_toolkit/_cdf_tk/client/data_classes/{charts.py → legacy/charts.py} +3 -3
- cognite_toolkit/_cdf_tk/client/data_classes/{migration.py → legacy/migration.py} +10 -2
- cognite_toolkit/_cdf_tk/client/data_classes/streams.py +90 -0
- cognite_toolkit/_cdf_tk/client/data_classes/three_d.py +112 -0
- cognite_toolkit/_cdf_tk/client/testing.py +42 -18
- cognite_toolkit/_cdf_tk/commands/__init__.py +7 -6
- cognite_toolkit/_cdf_tk/commands/_changes.py +3 -42
- cognite_toolkit/_cdf_tk/commands/_download.py +21 -11
- cognite_toolkit/_cdf_tk/commands/_migrate/__init__.py +0 -2
- cognite_toolkit/_cdf_tk/commands/_migrate/command.py +22 -20
- cognite_toolkit/_cdf_tk/commands/_migrate/conversion.py +140 -92
- cognite_toolkit/_cdf_tk/commands/_migrate/creators.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/data_classes.py +108 -26
- cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py +448 -45
- cognite_toolkit/_cdf_tk/commands/_migrate/data_model.py +1 -0
- cognite_toolkit/_cdf_tk/commands/_migrate/default_mappings.py +6 -6
- cognite_toolkit/_cdf_tk/commands/_migrate/issues.py +52 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py +377 -11
- cognite_toolkit/_cdf_tk/commands/_migrate/selectors.py +9 -4
- cognite_toolkit/_cdf_tk/commands/_profile.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_purge.py +36 -39
- cognite_toolkit/_cdf_tk/commands/_questionary_style.py +16 -0
- cognite_toolkit/_cdf_tk/commands/_upload.py +109 -86
- cognite_toolkit/_cdf_tk/commands/about.py +221 -0
- cognite_toolkit/_cdf_tk/commands/auth.py +19 -12
- cognite_toolkit/_cdf_tk/commands/build_cmd.py +16 -62
- cognite_toolkit/_cdf_tk/commands/build_v2/__init__.py +0 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/build_cmd.py +241 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/build_input.py +85 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/build_issues.py +27 -0
- cognite_toolkit/_cdf_tk/commands/clean.py +63 -16
- cognite_toolkit/_cdf_tk/commands/deploy.py +20 -17
- cognite_toolkit/_cdf_tk/commands/dump_resource.py +10 -8
- cognite_toolkit/_cdf_tk/commands/init.py +225 -3
- cognite_toolkit/_cdf_tk/commands/modules.py +20 -44
- cognite_toolkit/_cdf_tk/commands/pull.py +6 -19
- cognite_toolkit/_cdf_tk/commands/resources.py +179 -0
- cognite_toolkit/_cdf_tk/commands/run.py +1 -1
- cognite_toolkit/_cdf_tk/constants.py +20 -1
- cognite_toolkit/_cdf_tk/cruds/__init__.py +19 -5
- cognite_toolkit/_cdf_tk/cruds/_base_cruds.py +14 -70
- cognite_toolkit/_cdf_tk/cruds/_data_cruds.py +10 -19
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/__init__.py +4 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/agent.py +11 -9
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/auth.py +5 -15
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/classic.py +45 -44
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/configuration.py +5 -12
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/data_organization.py +4 -13
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/datamodel.py +206 -67
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/extraction_pipeline.py +6 -18
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/fieldops.py +126 -35
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/file.py +7 -28
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/function.py +23 -30
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/hosted_extractors.py +12 -30
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/industrial_tool.py +4 -8
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/location.py +4 -16
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/migration.py +5 -13
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/raw.py +5 -11
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/relationship.py +3 -8
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/robotics.py +16 -45
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/streams.py +94 -0
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/three_d_model.py +3 -7
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/timeseries.py +5 -15
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/transformation.py +75 -32
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/workflow.py +20 -40
- cognite_toolkit/_cdf_tk/cruds/_worker.py +24 -36
- cognite_toolkit/_cdf_tk/data_classes/_module_toml.py +1 -0
- cognite_toolkit/_cdf_tk/feature_flags.py +16 -36
- cognite_toolkit/_cdf_tk/plugins.py +2 -1
- cognite_toolkit/_cdf_tk/resource_classes/__init__.py +4 -0
- cognite_toolkit/_cdf_tk/resource_classes/capabilities.py +12 -0
- cognite_toolkit/_cdf_tk/resource_classes/functions.py +3 -1
- cognite_toolkit/_cdf_tk/resource_classes/infield_cdm_location_config.py +109 -0
- cognite_toolkit/_cdf_tk/resource_classes/migration.py +8 -17
- cognite_toolkit/_cdf_tk/resource_classes/search_config.py +1 -1
- cognite_toolkit/_cdf_tk/resource_classes/streams.py +29 -0
- cognite_toolkit/_cdf_tk/resource_classes/workflow_version.py +164 -5
- cognite_toolkit/_cdf_tk/storageio/__init__.py +9 -21
- cognite_toolkit/_cdf_tk/storageio/_annotations.py +19 -16
- cognite_toolkit/_cdf_tk/storageio/_applications.py +340 -28
- cognite_toolkit/_cdf_tk/storageio/_asset_centric.py +67 -104
- cognite_toolkit/_cdf_tk/storageio/_base.py +61 -29
- cognite_toolkit/_cdf_tk/storageio/_datapoints.py +276 -20
- cognite_toolkit/_cdf_tk/storageio/_file_content.py +435 -0
- cognite_toolkit/_cdf_tk/storageio/_instances.py +35 -3
- cognite_toolkit/_cdf_tk/storageio/_raw.py +26 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/__init__.py +71 -4
- cognite_toolkit/_cdf_tk/storageio/selectors/_base.py +14 -2
- cognite_toolkit/_cdf_tk/storageio/selectors/_canvas.py +14 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/_charts.py +14 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/_datapoints.py +23 -3
- cognite_toolkit/_cdf_tk/storageio/selectors/_file_content.py +164 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/_three_d.py +34 -0
- cognite_toolkit/_cdf_tk/tk_warnings/other.py +4 -0
- cognite_toolkit/_cdf_tk/tracker.py +2 -2
- cognite_toolkit/_cdf_tk/utils/cdf.py +1 -1
- cognite_toolkit/_cdf_tk/utils/dtype_conversion.py +9 -3
- cognite_toolkit/_cdf_tk/utils/fileio/__init__.py +2 -0
- cognite_toolkit/_cdf_tk/utils/fileio/_base.py +5 -1
- cognite_toolkit/_cdf_tk/utils/fileio/_readers.py +112 -20
- cognite_toolkit/_cdf_tk/utils/fileio/_writers.py +15 -15
- cognite_toolkit/_cdf_tk/utils/http_client/__init__.py +28 -0
- cognite_toolkit/_cdf_tk/utils/http_client/_client.py +285 -18
- cognite_toolkit/_cdf_tk/utils/http_client/_data_classes.py +56 -4
- cognite_toolkit/_cdf_tk/utils/http_client/_data_classes2.py +247 -0
- cognite_toolkit/_cdf_tk/utils/http_client/_tracker.py +5 -2
- cognite_toolkit/_cdf_tk/utils/interactive_select.py +60 -18
- cognite_toolkit/_cdf_tk/utils/sql_parser.py +2 -3
- cognite_toolkit/_cdf_tk/utils/useful_types.py +6 -2
- cognite_toolkit/_cdf_tk/validation.py +83 -1
- cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml +1 -1
- cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml +1 -1
- cognite_toolkit/_resources/cdf.toml +5 -4
- cognite_toolkit/_version.py +1 -1
- cognite_toolkit/config.dev.yaml +13 -0
- {cognite_toolkit-0.6.97.dist-info → cognite_toolkit-0.7.39.dist-info}/METADATA +24 -24
- cognite_toolkit-0.7.39.dist-info/RECORD +322 -0
- cognite_toolkit-0.7.39.dist-info/WHEEL +4 -0
- {cognite_toolkit-0.6.97.dist-info → cognite_toolkit-0.7.39.dist-info}/entry_points.txt +1 -0
- cognite_toolkit/_cdf_tk/client/api/robotics/__init__.py +0 -3
- cognite_toolkit/_cdf_tk/commands/_migrate/canvas.py +0 -201
- cognite_toolkit/_cdf_tk/commands/dump_data.py +0 -489
- cognite_toolkit/_cdf_tk/commands/featureflag.py +0 -27
- cognite_toolkit/_cdf_tk/prototypes/import_app.py +0 -41
- cognite_toolkit/_cdf_tk/utils/table_writers.py +0 -434
- cognite_toolkit-0.6.97.dist-info/RECORD +0 -306
- cognite_toolkit-0.6.97.dist-info/WHEEL +0 -4
- cognite_toolkit-0.6.97.dist-info/licenses/LICENSE +0 -18
- /cognite_toolkit/_cdf_tk/{prototypes/commands → client/api/legacy}/__init__.py +0 -0
- /cognite_toolkit/_cdf_tk/client/api/{dml.py → legacy/dml.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/api/{fixed_transformations.py → legacy/fixed_transformations.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/api.py +0 -0
- /cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/utlis.py +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{apm_config_v1.py → legacy/apm_config_v1.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{extendable_cognite_file.py → legacy/extendable_cognite_file.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{extended_filemetadata.py → legacy/extended_filemetadata.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{extended_filemetdata.py → legacy/extended_filemetdata.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{extended_timeseries.py → legacy/extended_timeseries.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{functions.py → legacy/functions.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{graphql_data_models.py → legacy/graphql_data_models.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{instances.py → legacy/instances.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{location_filters.py → legacy/location_filters.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{pending_instances_ids.py → legacy/pending_instances_ids.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{project.py → legacy/project.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{raw.py → legacy/raw.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{robotics.py → legacy/robotics.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{search_config.py → legacy/search_config.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{sequences.py → legacy/sequences.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{streamlit_.py → legacy/streamlit_.py} +0 -0
- /cognite_toolkit/_cdf_tk/{prototypes/commands/import_.py → commands/_import_cmd.py} +0 -0
|
@@ -1,70 +1,30 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
from dataclasses import dataclass, field, fields
|
|
3
|
-
from functools import lru_cache
|
|
4
1
|
from typing import Any
|
|
5
2
|
|
|
6
|
-
from cognite.client import CogniteClient
|
|
7
|
-
from cognite.client.data_classes._base import CogniteObject
|
|
8
3
|
from cognite.client.data_classes.data_modeling import NodeId, ViewId
|
|
9
|
-
from
|
|
4
|
+
from pydantic import JsonValue, field_serializer, field_validator
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
from typing import Self
|
|
13
|
-
else:
|
|
14
|
-
from typing_extensions import Self
|
|
6
|
+
from .base import BaseModelObject
|
|
15
7
|
|
|
16
8
|
|
|
17
|
-
|
|
18
|
-
class ChartObject(CogniteObject):
|
|
19
|
-
# ChartObjects are used in the frontend and the backend does not do any validation of these fields.
|
|
20
|
-
# Therefore, to ensure that we do not lose any data, we store unknown fields in a separate dictionary.
|
|
21
|
-
# This allows unknown fields to be preserved when loading and dumping ChartObjects
|
|
22
|
-
# (serialization and deserialization).
|
|
23
|
-
_unknown_fields: dict[str, object] | None = field(default=None, init=False, repr=False)
|
|
24
|
-
|
|
25
|
-
@classmethod
|
|
26
|
-
def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self:
|
|
27
|
-
"""Load a ChartObject from a dictionary."""
|
|
28
|
-
instance = super()._load(resource, cognite_client=cognite_client)
|
|
29
|
-
instance._unknown_fields = {k: v for k, v in resource.items() if k not in cls._known_camel_case_props()}
|
|
30
|
-
return instance
|
|
31
|
-
|
|
32
|
-
@classmethod
|
|
33
|
-
@lru_cache(maxsize=1)
|
|
34
|
-
def _known_camel_case_props(cls) -> set[str]:
|
|
35
|
-
return {to_camel_case(f.name) for f in fields(cls)}
|
|
36
|
-
|
|
37
|
-
def dump(self, camel_case: bool = True) -> dict[str, Any]:
|
|
38
|
-
"""Dump the ChartObject to a dictionary."""
|
|
39
|
-
data = super().dump(camel_case=camel_case)
|
|
40
|
-
if self._unknown_fields:
|
|
41
|
-
data.update(self._unknown_fields)
|
|
42
|
-
return data
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
@dataclass
|
|
46
|
-
class UserInfo(ChartObject):
|
|
9
|
+
class UserInfo(BaseModelObject):
|
|
47
10
|
id: str | None = None
|
|
48
11
|
email: str | None = None
|
|
49
12
|
display_name: str | None = None
|
|
50
13
|
|
|
51
14
|
|
|
52
|
-
|
|
53
|
-
class ChartSettings(ChartObject):
|
|
15
|
+
class ChartSettings(BaseModelObject):
|
|
54
16
|
show_y_axis: bool = True
|
|
55
17
|
show_min_max: bool = True
|
|
56
18
|
show_gridlines: bool = True
|
|
57
19
|
merge_units: bool = False
|
|
58
20
|
|
|
59
21
|
|
|
60
|
-
|
|
61
|
-
class ThresholdFilter(ChartObject):
|
|
22
|
+
class ThresholdFilter(BaseModelObject):
|
|
62
23
|
min_unit: str | None = None
|
|
63
24
|
max_unit: str | None = None
|
|
64
25
|
|
|
65
26
|
|
|
66
|
-
|
|
67
|
-
class ChartCall(ChartObject):
|
|
27
|
+
class ChartCall(BaseModelObject):
|
|
68
28
|
id: str | None = None
|
|
69
29
|
hash: int | None = None
|
|
70
30
|
call_id: str | None = None
|
|
@@ -72,162 +32,143 @@ class ChartCall(ChartObject):
|
|
|
72
32
|
status: str | None = None
|
|
73
33
|
|
|
74
34
|
|
|
75
|
-
|
|
76
|
-
class SubSetting(ChartObject):
|
|
35
|
+
class SubSetting(BaseModelObject):
|
|
77
36
|
auto_align: bool | None = None
|
|
78
37
|
|
|
79
38
|
|
|
80
|
-
|
|
81
|
-
|
|
39
|
+
class ChartPosition(BaseModelObject):
|
|
40
|
+
x: float | None = None
|
|
41
|
+
y: float | None = None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class FlowElement(BaseModelObject):
|
|
82
45
|
id: str | None = None
|
|
83
46
|
type: str | None = None
|
|
84
|
-
position:
|
|
85
|
-
data:
|
|
47
|
+
position: ChartPosition | None = None
|
|
48
|
+
data: JsonValue | None = None
|
|
49
|
+
source: str | None = None
|
|
50
|
+
target: str | None = None
|
|
51
|
+
source_handle: str | None = None
|
|
52
|
+
target_handle: str | None = None
|
|
86
53
|
|
|
87
54
|
|
|
88
|
-
|
|
89
|
-
class Flow(ChartObject):
|
|
55
|
+
class Flow(BaseModelObject):
|
|
90
56
|
zoom: float | None = None
|
|
91
57
|
elements: list[FlowElement] | None = None
|
|
92
58
|
position: tuple[float | None, float | None] | None = None
|
|
93
59
|
|
|
94
|
-
def dump(self, camel_case: bool = True) -> dict[str, Any]:
|
|
95
|
-
data = super().dump(camel_case=camel_case)
|
|
96
|
-
if self.elements:
|
|
97
|
-
data["elements"] = [el.dump(camel_case=camel_case) for el in self.elements]
|
|
98
|
-
return data
|
|
99
60
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
instance = super()._load(resource, cognite_client=cognite_client)
|
|
104
|
-
if "elements" in resource:
|
|
105
|
-
instance.elements = [FlowElement._load(el, cognite_client=cognite_client) for el in resource["elements"]]
|
|
106
|
-
return instance
|
|
61
|
+
class ChartElement(BaseModelObject):
|
|
62
|
+
id: str | None = None
|
|
63
|
+
type: str | None = None
|
|
107
64
|
|
|
108
65
|
|
|
109
|
-
|
|
110
|
-
class ChartSource(ChartObject):
|
|
111
|
-
type: str | None = None
|
|
112
|
-
id: str | None = None
|
|
66
|
+
class ChartSource(ChartElement): ...
|
|
113
67
|
|
|
114
68
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
name: str | None = None
|
|
69
|
+
class ChartCoreTimeseries(ChartElement):
|
|
70
|
+
node_reference: NodeId | None = None
|
|
71
|
+
view_reference: ViewId | None = None
|
|
72
|
+
display_mode: str | None = None
|
|
120
73
|
color: str | None = None
|
|
74
|
+
created_at: int | None = None
|
|
121
75
|
enabled: bool | None = None
|
|
122
|
-
line_weight: float | None = None
|
|
123
|
-
line_style: str | None = None
|
|
124
76
|
interpolation: str | None = None
|
|
125
|
-
|
|
77
|
+
line_style: str | None = None
|
|
78
|
+
line_weight: float | None = None
|
|
79
|
+
name: str | None = None
|
|
126
80
|
preferred_unit: str | None = None
|
|
127
|
-
|
|
128
|
-
range: tuple[float | None, float | None] | None = None
|
|
129
|
-
description: str | None = None
|
|
81
|
+
range: list[float | None] | None = None
|
|
130
82
|
|
|
83
|
+
@field_serializer("node_reference", when_used="always")
|
|
84
|
+
def serialize_node_reference(self, node_reference: NodeId | None) -> dict[str, Any] | None:
|
|
85
|
+
if node_reference:
|
|
86
|
+
return node_reference.dump(include_instance_type=False)
|
|
87
|
+
return None
|
|
131
88
|
|
|
132
|
-
@
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
89
|
+
@field_serializer("view_reference", when_used="always")
|
|
90
|
+
def serialize_view_reference(self, view_reference: ViewId | None) -> dict[str, Any] | None:
|
|
91
|
+
if view_reference:
|
|
92
|
+
return view_reference.dump(include_type=False)
|
|
93
|
+
return None
|
|
94
|
+
|
|
95
|
+
@field_validator("node_reference", mode="before")
|
|
96
|
+
@classmethod
|
|
97
|
+
def validate_node_reference(cls, value: Any) -> NodeId | None:
|
|
98
|
+
if value is None or isinstance(value, NodeId):
|
|
99
|
+
return value
|
|
100
|
+
return NodeId.load(value)
|
|
101
|
+
|
|
102
|
+
@field_validator("view_reference", mode="before")
|
|
103
|
+
@classmethod
|
|
104
|
+
def validate_view_reference(cls, value: Any) -> ViewId | None:
|
|
105
|
+
if value is None or isinstance(value, ViewId):
|
|
106
|
+
return value
|
|
107
|
+
return ViewId.load(value)
|
|
137
108
|
|
|
138
109
|
|
|
139
|
-
|
|
140
|
-
|
|
110
|
+
class ChartTimeseries(ChartElement):
|
|
111
|
+
color: str | None = None
|
|
112
|
+
created_at: int | None = None
|
|
113
|
+
enabled: bool | None = None
|
|
114
|
+
interpolation: str | None = None
|
|
115
|
+
line_style: str | None = None
|
|
116
|
+
line_weight: float | None = None
|
|
117
|
+
name: str | None = None
|
|
118
|
+
preferred_unit: str | None = None
|
|
119
|
+
range: list[float | None] | None = None
|
|
120
|
+
unit: str | None = None
|
|
141
121
|
ts_id: int | None = None
|
|
142
122
|
ts_external_id: str | None = None
|
|
143
123
|
display_mode: str | None = None
|
|
144
124
|
original_unit: str | None = None
|
|
125
|
+
description: str | None = None
|
|
145
126
|
|
|
146
127
|
|
|
147
|
-
|
|
148
|
-
class ChartWorkflow(BaseChartElement):
|
|
128
|
+
class ChartWorkflow(ChartElement):
|
|
149
129
|
version: str | None = None
|
|
130
|
+
name: str | None = None
|
|
131
|
+
color: str | None = None
|
|
132
|
+
enabled: bool | None = None
|
|
133
|
+
line_weight: float | None = None
|
|
134
|
+
line_style: str | None = None
|
|
135
|
+
interpolation: str | None = None
|
|
136
|
+
unit: str | None = None
|
|
137
|
+
preferred_unit: str | None = None
|
|
138
|
+
range: list[float | None] | None = None
|
|
139
|
+
created_at: int | None = None
|
|
150
140
|
settings: SubSetting | None = None
|
|
151
141
|
flow: Flow | None = None
|
|
152
142
|
calls: list[ChartCall] | None = None
|
|
153
143
|
|
|
154
|
-
def dump(self, camel_case: bool = True) -> dict[str, Any]:
|
|
155
|
-
data = super().dump(camel_case=camel_case)
|
|
156
|
-
if self.settings:
|
|
157
|
-
data["settings"] = self.settings.dump(camel_case=camel_case)
|
|
158
|
-
if self.flow:
|
|
159
|
-
data["flow"] = self.flow.dump(camel_case=camel_case)
|
|
160
|
-
if self.calls:
|
|
161
|
-
data["calls"] = [c.dump(camel_case=camel_case) for c in self.calls]
|
|
162
|
-
return data
|
|
163
144
|
|
|
164
|
-
|
|
165
|
-
def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self:
|
|
166
|
-
"""Load a ChartWorkflow object from a dictionary."""
|
|
167
|
-
instance = super()._load(resource, cognite_client=cognite_client)
|
|
168
|
-
if "settings" in resource:
|
|
169
|
-
instance.settings = SubSetting._load(resource["settings"], cognite_client=cognite_client)
|
|
170
|
-
if "flow" in resource:
|
|
171
|
-
instance.flow = Flow._load(resource["flow"], cognite_client=cognite_client)
|
|
172
|
-
if "calls" in resource:
|
|
173
|
-
instance.calls = [ChartCall._load(call, cognite_client=cognite_client) for call in resource["calls"]]
|
|
174
|
-
return instance
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
@dataclass
|
|
178
|
-
class ChartThreshold(BaseChartElement):
|
|
145
|
+
class ChartThreshold(ChartElement):
|
|
179
146
|
visible: bool | None = None
|
|
147
|
+
name: str | None = None
|
|
180
148
|
source_id: str | None = None
|
|
181
149
|
upper_limit: float | None = None
|
|
182
150
|
filter: ThresholdFilter | None = None
|
|
183
151
|
calls: list[ChartCall] | None = None
|
|
184
152
|
|
|
185
|
-
def dump(self, camel_case: bool = True) -> dict[str, Any]:
|
|
186
|
-
data = super().dump(camel_case=camel_case)
|
|
187
|
-
if self.filter:
|
|
188
|
-
data["filter"] = self.filter.dump(camel_case=camel_case)
|
|
189
|
-
if self.calls:
|
|
190
|
-
data["calls"] = [c.dump(camel_case=camel_case) for c in self.calls]
|
|
191
|
-
return data
|
|
192
153
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
class ChartScheduledCalculation(BaseChartElement):
|
|
154
|
+
class ChartScheduledCalculation(ChartElement):
|
|
155
|
+
color: str | None = None
|
|
156
|
+
created_at: int | None = None
|
|
157
|
+
description: str | None = None
|
|
158
|
+
enabled: bool | None = None
|
|
159
|
+
interpolation: str | None = None
|
|
160
|
+
line_style: str | None = None
|
|
161
|
+
line_weight: float | None = None
|
|
162
|
+
name: str | None = None
|
|
163
|
+
preferred_unit: str | None = None
|
|
164
|
+
range: list[float | None] | None = None
|
|
165
|
+
unit: str | None = None
|
|
206
166
|
version: str | None = None
|
|
207
167
|
settings: SubSetting | None = None
|
|
208
168
|
flow: Flow | None = None
|
|
209
169
|
|
|
210
|
-
def dump(self, camel_case: bool = True) -> dict[str, Any]:
|
|
211
|
-
data = super().dump(camel_case=camel_case)
|
|
212
|
-
if self.settings:
|
|
213
|
-
data["settings"] = self.settings.dump(camel_case=camel_case)
|
|
214
|
-
if self.flow:
|
|
215
|
-
data["flow"] = self.flow.dump(camel_case=camel_case)
|
|
216
|
-
return data
|
|
217
170
|
|
|
218
|
-
|
|
219
|
-
def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self:
|
|
220
|
-
"""Load a ChartScheduledCalculation object from a dictionary."""
|
|
221
|
-
instance = super()._load(resource, cognite_client=cognite_client)
|
|
222
|
-
if "settings" in resource:
|
|
223
|
-
instance.settings = SubSetting._load(resource["settings"], cognite_client=cognite_client)
|
|
224
|
-
if "flow" in resource:
|
|
225
|
-
instance.flow = Flow._load(resource["flow"], cognite_client=cognite_client)
|
|
226
|
-
return instance
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
@dataclass
|
|
230
|
-
class ChartData(ChartObject):
|
|
171
|
+
class ChartData(BaseModelObject):
|
|
231
172
|
version: int | None = None
|
|
232
173
|
name: str | None = None
|
|
233
174
|
date_from: str | None = None
|
|
@@ -241,62 +182,3 @@ class ChartData(ChartObject):
|
|
|
241
182
|
threshold_collection: list[ChartThreshold] | None = None
|
|
242
183
|
scheduled_calculation_collection: list[ChartScheduledCalculation] | None = None
|
|
243
184
|
settings: ChartSettings | None = None
|
|
244
|
-
|
|
245
|
-
def dump(self, camel_case: bool = True) -> dict[str, Any]:
|
|
246
|
-
"""Dump the ChartData object to a dictionary."""
|
|
247
|
-
data = super().dump(camel_case=camel_case)
|
|
248
|
-
list_attrs = [
|
|
249
|
-
"time_series_collection",
|
|
250
|
-
"core_timeseries_collection",
|
|
251
|
-
"workflow_collection",
|
|
252
|
-
"source_collection",
|
|
253
|
-
"threshold_collection",
|
|
254
|
-
"scheduled_calculation_collection",
|
|
255
|
-
]
|
|
256
|
-
for attr_name in list_attrs:
|
|
257
|
-
if collection := getattr(self, attr_name):
|
|
258
|
-
key = to_camel_case(attr_name) if camel_case else attr_name
|
|
259
|
-
data[key] = [item.dump(camel_case=camel_case) for item in collection]
|
|
260
|
-
|
|
261
|
-
single_attrs_map = {
|
|
262
|
-
"user_info": "userInfo",
|
|
263
|
-
"settings": "settings",
|
|
264
|
-
}
|
|
265
|
-
for attr_name, camel_key in single_attrs_map.items():
|
|
266
|
-
if item := getattr(self, attr_name):
|
|
267
|
-
key = camel_key if camel_case else attr_name
|
|
268
|
-
data[key] = item.dump(camel_case=camel_case)
|
|
269
|
-
return data
|
|
270
|
-
|
|
271
|
-
@classmethod
|
|
272
|
-
def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self:
|
|
273
|
-
"""Load a ChartData object from a dictionary."""
|
|
274
|
-
instance = super()._load(resource, cognite_client=cognite_client)
|
|
275
|
-
collections_map = [
|
|
276
|
-
("timeSeriesCollection", "time_series_collection", ChartTimeseries),
|
|
277
|
-
("coreTimeseriesCollection", "core_timeseries_collection", ChartCoreTimeseries),
|
|
278
|
-
("workflowCollection", "workflow_collection", ChartWorkflow),
|
|
279
|
-
("sourceCollection", "source_collection", ChartSource),
|
|
280
|
-
("thresholdCollection", "threshold_collection", ChartThreshold),
|
|
281
|
-
("scheduledCalculationCollection", "scheduled_calculation_collection", ChartScheduledCalculation),
|
|
282
|
-
]
|
|
283
|
-
for resource_key, attr_name, subclass in collections_map:
|
|
284
|
-
if resource_key in resource:
|
|
285
|
-
setattr(
|
|
286
|
-
instance,
|
|
287
|
-
attr_name,
|
|
288
|
-
[subclass._load(item, cognite_client=cognite_client) for item in resource[resource_key]], # type: ignore[attr-defined]
|
|
289
|
-
)
|
|
290
|
-
attribute_map = [
|
|
291
|
-
("userInfo", "user_info", UserInfo),
|
|
292
|
-
("settings", "settings", ChartSettings),
|
|
293
|
-
]
|
|
294
|
-
for resource_key, attr_name, subclass in attribute_map:
|
|
295
|
-
if resource_key in resource:
|
|
296
|
-
setattr(
|
|
297
|
-
instance,
|
|
298
|
-
attr_name,
|
|
299
|
-
subclass._load(resource[resource_key], cognite_client=cognite_client), # type: ignore[attr-defined]
|
|
300
|
-
)
|
|
301
|
-
|
|
302
|
-
return instance
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import sys
|
|
2
|
-
from collections import UserList
|
|
3
2
|
from typing import Any, ClassVar, Literal
|
|
4
3
|
|
|
5
|
-
from cognite.client import CogniteClient
|
|
6
4
|
from pydantic import JsonValue, field_validator
|
|
7
5
|
from pydantic_core.core_schema import ValidationInfo
|
|
8
6
|
|
|
9
|
-
from cognite_toolkit._cdf_tk.protocols import
|
|
7
|
+
from cognite_toolkit._cdf_tk.protocols import (
|
|
8
|
+
ResourceRequestListProtocol,
|
|
9
|
+
ResourceResponseListProtocol,
|
|
10
|
+
)
|
|
10
11
|
from cognite_toolkit._cdf_tk.utils.text import sanitize_instance_external_id
|
|
11
12
|
|
|
12
|
-
from .base import ResponseResource
|
|
13
|
+
from .base import BaseResourceList, ResponseResource
|
|
13
14
|
from .instance_api import InstanceRequestResource, ViewReference
|
|
14
15
|
|
|
15
16
|
if sys.version_info >= (3, 11):
|
|
@@ -18,6 +19,9 @@ else:
|
|
|
18
19
|
from typing_extensions import Self
|
|
19
20
|
|
|
20
21
|
INFIELD_LOCATION_CONFIG_VIEW_ID = ViewReference(space="cdf_infield", external_id="InFieldLocationConfig", version="v1")
|
|
22
|
+
INFIELD_CDM_LOCATION_CONFIG_VIEW_ID = ViewReference(
|
|
23
|
+
space="infield_cdm_source_desc_sche_asset_file_ts", external_id="InFieldCDMLocationConfig", version="v1"
|
|
24
|
+
)
|
|
21
25
|
DATA_EXPLORATION_CONFIG_VIEW_ID = ViewReference(space="cdf_infield", external_id="DataExplorationConfig", version="v1")
|
|
22
26
|
|
|
23
27
|
|
|
@@ -74,29 +78,39 @@ class InfieldLocationConfig(
|
|
|
74
78
|
|
|
75
79
|
|
|
76
80
|
class InfieldLocationConfigList(
|
|
77
|
-
|
|
81
|
+
BaseResourceList[InfieldLocationConfig],
|
|
78
82
|
ResourceResponseListProtocol,
|
|
79
83
|
ResourceRequestListProtocol,
|
|
80
84
|
):
|
|
81
85
|
"""A list of InfieldLocationConfig objects."""
|
|
82
86
|
|
|
83
87
|
_RESOURCE = InfieldLocationConfig
|
|
84
|
-
data: list[InfieldLocationConfig]
|
|
85
88
|
|
|
86
|
-
def
|
|
87
|
-
|
|
89
|
+
def as_write(self) -> Self:
|
|
90
|
+
return self
|
|
91
|
+
|
|
88
92
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return [item.dump(camel_case) for item in self.data]
|
|
93
|
+
class InFieldCDMLocationConfig(ResponseResource["InFieldCDMLocationConfig"], InstanceRequestResource):
|
|
94
|
+
"""InField CDM Location Configuration resource class.
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
This class is used for both the response and request resource for InField CDM Location Configuration nodes.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
VIEW_ID: ClassVar[ViewReference] = INFIELD_CDM_LOCATION_CONFIG_VIEW_ID
|
|
100
|
+
instance_type: Literal["node"] = "node"
|
|
101
|
+
|
|
102
|
+
name: str | None = None
|
|
103
|
+
description: str | None = None
|
|
104
|
+
feature_toggles: dict[str, JsonValue] | None = None
|
|
105
|
+
access_management: dict[str, JsonValue] | None = None
|
|
106
|
+
data_filters: dict[str, JsonValue] | None = None
|
|
107
|
+
data_storage: dict[str, JsonValue] | None = None
|
|
108
|
+
view_mappings: dict[str, JsonValue] | None = None
|
|
109
|
+
disciplines: list[dict[str, JsonValue]] | None = None
|
|
110
|
+
data_exploration_config: dict[str, JsonValue] | None = None
|
|
111
|
+
|
|
112
|
+
def as_request_resource(self) -> "InFieldCDMLocationConfig":
|
|
113
|
+
return self
|
|
100
114
|
|
|
101
115
|
def as_write(self) -> Self:
|
|
102
116
|
return self
|
|
@@ -7,7 +7,7 @@ from .base import BaseModelObject, Identifier, RequestResource
|
|
|
7
7
|
InstanceType: TypeAlias = Literal["node", "edge"]
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
class
|
|
10
|
+
class TypedInstanceIdentifier(Identifier):
|
|
11
11
|
"""Identifier for an Instance instance."""
|
|
12
12
|
|
|
13
13
|
instance_type: InstanceType
|
|
@@ -15,14 +15,19 @@ class InstanceIdentifier(Identifier):
|
|
|
15
15
|
external_id: str
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
class
|
|
18
|
+
class TypedNodeIdentifier(TypedInstanceIdentifier):
|
|
19
19
|
instance_type: Literal["node"] = "node"
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
class
|
|
22
|
+
class TypedEdgeIdentifier(TypedInstanceIdentifier):
|
|
23
23
|
instance_type: Literal["edge"] = "edge"
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
class InstanceIdentifier(Identifier):
|
|
27
|
+
space: str
|
|
28
|
+
external_id: str
|
|
29
|
+
|
|
30
|
+
|
|
26
31
|
class InstanceResult(BaseModelObject):
|
|
27
32
|
instance_type: InstanceType
|
|
28
33
|
version: int
|
|
@@ -32,8 +37,8 @@ class InstanceResult(BaseModelObject):
|
|
|
32
37
|
created_time: int
|
|
33
38
|
last_updated_time: int
|
|
34
39
|
|
|
35
|
-
def as_id(self) ->
|
|
36
|
-
return
|
|
40
|
+
def as_id(self) -> TypedInstanceIdentifier:
|
|
41
|
+
return TypedInstanceIdentifier(
|
|
37
42
|
instance_type=self.instance_type,
|
|
38
43
|
space=self.space,
|
|
39
44
|
external_id=self.external_id,
|
|
@@ -62,8 +67,8 @@ class InstanceRequestResource(RequestResource):
|
|
|
62
67
|
space: str
|
|
63
68
|
external_id: str
|
|
64
69
|
|
|
65
|
-
def as_id(self) ->
|
|
66
|
-
return
|
|
70
|
+
def as_id(self) -> TypedInstanceIdentifier:
|
|
71
|
+
return TypedInstanceIdentifier(
|
|
67
72
|
instance_type=self.instance_type,
|
|
68
73
|
space=self.space,
|
|
69
74
|
external_id=self.external_id,
|
|
@@ -107,7 +112,7 @@ class InstanceSource(BaseModelObject):
|
|
|
107
112
|
return value
|
|
108
113
|
|
|
109
114
|
|
|
110
|
-
class InstanceRequestItem(
|
|
115
|
+
class InstanceRequestItem(RequestResource):
|
|
111
116
|
model_config = ConfigDict(populate_by_name=True)
|
|
112
117
|
instance_type: InstanceType
|
|
113
118
|
space: str
|
|
@@ -115,8 +120,8 @@ class InstanceRequestItem(BaseModelObject):
|
|
|
115
120
|
existing_version: int | None = None
|
|
116
121
|
sources: list[InstanceSource] | None = None
|
|
117
122
|
|
|
118
|
-
def as_id(self) ->
|
|
119
|
-
return
|
|
123
|
+
def as_id(self) -> TypedInstanceIdentifier:
|
|
124
|
+
return TypedInstanceIdentifier(
|
|
120
125
|
instance_type=self.instance_type,
|
|
121
126
|
space=self.space,
|
|
122
127
|
external_id=self.external_id,
|
|
@@ -128,7 +133,7 @@ class InstanceResponseItem(BaseModelObject):
|
|
|
128
133
|
space: str
|
|
129
134
|
external_id: str
|
|
130
135
|
version: int
|
|
131
|
-
type:
|
|
136
|
+
type: TypedInstanceIdentifier | None = None
|
|
132
137
|
created_time: int
|
|
133
138
|
last_updated_time: int
|
|
134
139
|
deleted_time: int | None = None
|
|
@@ -149,8 +154,8 @@ class InstanceResponseItem(BaseModelObject):
|
|
|
149
154
|
output.update(space_properties.get(view_version, {}))
|
|
150
155
|
return output
|
|
151
156
|
|
|
152
|
-
def as_id(self) ->
|
|
153
|
-
return
|
|
157
|
+
def as_id(self) -> TypedInstanceIdentifier:
|
|
158
|
+
return TypedInstanceIdentifier(
|
|
154
159
|
instance_type=self.instance_type,
|
|
155
160
|
space=self.space,
|
|
156
161
|
external_id=self.external_id,
|
|
File without changes
|
|
@@ -2,7 +2,7 @@ import sys
|
|
|
2
2
|
from abc import ABC
|
|
3
3
|
from collections.abc import Sequence
|
|
4
4
|
from datetime import datetime, timezone
|
|
5
|
-
from typing import Any
|
|
5
|
+
from typing import Any, TypeVar
|
|
6
6
|
from uuid import uuid4
|
|
7
7
|
|
|
8
8
|
from cognite.client import CogniteClient
|
|
@@ -30,7 +30,8 @@ from cognite.client.data_classes.data_modeling.instances import (
|
|
|
30
30
|
TypedNodeApply,
|
|
31
31
|
)
|
|
32
32
|
|
|
33
|
-
from cognite_toolkit._cdf_tk.client.data_classes.migration import AssetCentricId
|
|
33
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.migration import AssetCentricId
|
|
34
|
+
from cognite_toolkit._cdf_tk.utils.useful_types import JsonVal
|
|
34
35
|
|
|
35
36
|
if sys.version_info >= (3, 11):
|
|
36
37
|
from typing import Self
|
|
@@ -68,6 +69,9 @@ class ExtendedTypedNodeApply(TypedNodeApply, ABC):
|
|
|
68
69
|
return output
|
|
69
70
|
|
|
70
71
|
|
|
72
|
+
T_ExtendedTypedNodeApply = TypeVar("T_ExtendedTypedNodeApply", bound=ExtendedTypedNodeApply)
|
|
73
|
+
|
|
74
|
+
|
|
71
75
|
class _CanvasProperties:
|
|
72
76
|
created_by = PropertyOptions("createdBy")
|
|
73
77
|
updated_at = PropertyOptions("updatedAt")
|
|
@@ -901,7 +905,7 @@ class IndustrialCanvasApply(CogniteResource):
|
|
|
901
905
|
raise TypeError(f"Unexpected instance type: {type(instance)}")
|
|
902
906
|
return ids
|
|
903
907
|
|
|
904
|
-
def dump(self, keep_existing_version: bool = True) -> dict[str,
|
|
908
|
+
def dump(self, keep_existing_version: bool = True) -> dict[str, JsonVal]:
|
|
905
909
|
"""Dump the IndustrialCanvasApply to a dictionary."""
|
|
906
910
|
return {
|
|
907
911
|
"canvas": self.canvas.dump(keep_existing_version=keep_existing_version),
|
|
@@ -953,7 +957,46 @@ class IndustrialCanvasApply(CogniteResource):
|
|
|
953
957
|
@classmethod
|
|
954
958
|
def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self:
|
|
955
959
|
"""Load an IndustrialCanvasApply instance from a resource dictionary."""
|
|
956
|
-
|
|
960
|
+
if "canvas" not in resource:
|
|
961
|
+
raise ValueError("Resource does not contain a canvas node.")
|
|
962
|
+
canvas_resource = resource["canvas"]
|
|
963
|
+
if isinstance(canvas_resource, dict):
|
|
964
|
+
canvas = CanvasApply._load(canvas_resource)
|
|
965
|
+
elif isinstance(canvas_resource, CanvasApply):
|
|
966
|
+
canvas = canvas_resource
|
|
967
|
+
elif isinstance(canvas_resource, NodeApply):
|
|
968
|
+
canvas = CanvasApply._load(canvas_resource.dump())
|
|
969
|
+
else:
|
|
970
|
+
raise TypeError(f"Canvas resource {type(canvas_resource)} is not supported.")
|
|
971
|
+
return cls(
|
|
972
|
+
canvas=canvas,
|
|
973
|
+
annotations=cls._load_apply_items(resource.get("annotations"), CanvasAnnotationApply),
|
|
974
|
+
container_references=cls._load_apply_items(resource.get("containerReferences"), ContainerReferenceApply),
|
|
975
|
+
fdm_instance_container_references=cls._load_apply_items(
|
|
976
|
+
resource.get("fdmInstanceContainerReferences"), FdmInstanceContainerReferenceApply
|
|
977
|
+
),
|
|
978
|
+
solution_tags=cls._load_apply_items(resource.get("solutionTags"), CogniteSolutionTagApply),
|
|
979
|
+
)
|
|
980
|
+
|
|
981
|
+
@classmethod
|
|
982
|
+
def _load_apply_items(
|
|
983
|
+
cls, items: object | None, node_cls: type[T_ExtendedTypedNodeApply]
|
|
984
|
+
) -> list[T_ExtendedTypedNodeApply]:
|
|
985
|
+
if items is None:
|
|
986
|
+
return []
|
|
987
|
+
elif isinstance(items, Sequence):
|
|
988
|
+
nodes: list[T_ExtendedTypedNodeApply] = []
|
|
989
|
+
for node in items:
|
|
990
|
+
if isinstance(node, dict):
|
|
991
|
+
nodes.append(node_cls._load(node))
|
|
992
|
+
elif isinstance(node, node_cls):
|
|
993
|
+
nodes.append(node)
|
|
994
|
+
elif isinstance(node, NodeApply):
|
|
995
|
+
nodes.append(node_cls._load(node.dump()))
|
|
996
|
+
else:
|
|
997
|
+
raise TypeError(f"Expected a sequence of {node_cls.__name__}, got {type(node).__name__}")
|
|
998
|
+
return nodes
|
|
999
|
+
raise TypeError(f"Expected a sequence of {node_cls.__name__}, got {type(items).__name__}")
|
|
957
1000
|
|
|
958
1001
|
|
|
959
1002
|
class IndustrialCanvas(WriteableCogniteResource[IndustrialCanvasApply]):
|
|
@@ -36,7 +36,7 @@ class ChartCore(WriteableCogniteResource["ChartWrite"], ABC):
|
|
|
36
36
|
def dump(self, camel_case: bool = True) -> dict[str, Any]:
|
|
37
37
|
"""Convert the chart to a dictionary representation."""
|
|
38
38
|
output = super().dump(camel_case=camel_case)
|
|
39
|
-
output["data"] = self.data.
|
|
39
|
+
output["data"] = self.data.model_dump(mode="json", by_alias=camel_case, exclude_unset=True)
|
|
40
40
|
return output
|
|
41
41
|
|
|
42
42
|
|
|
@@ -58,7 +58,7 @@ class ChartWrite(ChartCore):
|
|
|
58
58
|
return cls(
|
|
59
59
|
external_id=resource["externalId"],
|
|
60
60
|
visibility=resource["visibility"],
|
|
61
|
-
data=ChartData._load(resource["data"]
|
|
61
|
+
data=ChartData._load(resource["data"]),
|
|
62
62
|
)
|
|
63
63
|
|
|
64
64
|
|
|
@@ -98,7 +98,7 @@ class Chart(ChartCore):
|
|
|
98
98
|
created_time=resource["createdTime"],
|
|
99
99
|
last_updated_time=resource["lastUpdatedTime"],
|
|
100
100
|
visibility=resource["visibility"],
|
|
101
|
-
data=ChartData._load(resource["data"]
|
|
101
|
+
data=ChartData._load(resource["data"]),
|
|
102
102
|
owner_id=resource["ownerId"],
|
|
103
103
|
)
|
|
104
104
|
|