industrial-model 0.1.29__py3-none-any.whl → 0.1.31__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.
- industrial_model/cognite_adapters/query_result_mapper.py +34 -8
- industrial_model/cognite_adapters/upsert_mapper.py +15 -9
- {industrial_model-0.1.29.dist-info → industrial_model-0.1.31.dist-info}/METADATA +1 -1
- {industrial_model-0.1.29.dist-info → industrial_model-0.1.31.dist-info}/RECORD +5 -5
- {industrial_model-0.1.29.dist-info → industrial_model-0.1.31.dist-info}/WHEEL +0 -0
|
@@ -10,6 +10,10 @@ from cognite.client.data_classes.data_modeling import (
|
|
|
10
10
|
NodeList,
|
|
11
11
|
View,
|
|
12
12
|
)
|
|
13
|
+
from cognite.client.data_classes.data_modeling.data_types import (
|
|
14
|
+
ListablePropertyType,
|
|
15
|
+
)
|
|
16
|
+
from cognite.client.data_classes.data_modeling.instances import PropertyValue
|
|
13
17
|
from cognite.client.data_classes.data_modeling.views import (
|
|
14
18
|
MultiReverseDirectRelation,
|
|
15
19
|
SingleReverseDirectRelation,
|
|
@@ -112,13 +116,13 @@ class QueryResultMapper:
|
|
|
112
116
|
):
|
|
113
117
|
continue
|
|
114
118
|
|
|
115
|
-
|
|
116
|
-
(element.get("space", ""), element.get("externalId", ""))
|
|
117
|
-
if isinstance(element, dict)
|
|
118
|
-
else (node.space, node.external_id)
|
|
119
|
-
)
|
|
119
|
+
element_keys = self._get_element_keys(node, element)
|
|
120
120
|
|
|
121
|
-
node_entries =
|
|
121
|
+
node_entries = [
|
|
122
|
+
item
|
|
123
|
+
for element_key in element_keys
|
|
124
|
+
for item in mapping_nodes.get(element_key, [])
|
|
125
|
+
]
|
|
122
126
|
if not node_entries:
|
|
123
127
|
if mapping_key in properties:
|
|
124
128
|
properties.pop(mapping_key)
|
|
@@ -126,7 +130,11 @@ class QueryResultMapper:
|
|
|
126
130
|
|
|
127
131
|
entry_data = self.nodes_to_dict(node_entries)
|
|
128
132
|
properties[mapping_key] = entry_data if is_list else entry_data[0]
|
|
129
|
-
edge_entries =
|
|
133
|
+
edge_entries = [
|
|
134
|
+
item
|
|
135
|
+
for element_key in element_keys
|
|
136
|
+
for item in mapping_edges.get(element_key, [])
|
|
137
|
+
]
|
|
130
138
|
if edge_entries:
|
|
131
139
|
edges_mapping[mapping_key] = self._edges_to_model(edge_entries)
|
|
132
140
|
properties["_edges"] = edges_mapping
|
|
@@ -137,6 +145,21 @@ class QueryResultMapper:
|
|
|
137
145
|
|
|
138
146
|
return dict(result)
|
|
139
147
|
|
|
148
|
+
def _get_element_keys(
|
|
149
|
+
self, node: Node, element: PropertyValue | None
|
|
150
|
+
) -> list[tuple[str, str]]:
|
|
151
|
+
if isinstance(element, dict):
|
|
152
|
+
return [(element.get("space", ""), element.get("externalId", ""))]
|
|
153
|
+
|
|
154
|
+
if isinstance(element, list):
|
|
155
|
+
return [
|
|
156
|
+
(item.get("space", ""), item.get("externalId", ""))
|
|
157
|
+
for item in element
|
|
158
|
+
if isinstance(item, dict)
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
return [(node.space, node.external_id)]
|
|
162
|
+
|
|
140
163
|
def _get_property_mappings(
|
|
141
164
|
self,
|
|
142
165
|
key: str,
|
|
@@ -159,7 +182,10 @@ class QueryResultMapper:
|
|
|
159
182
|
self._view_mapper.get_view(property.source.external_id),
|
|
160
183
|
query_result,
|
|
161
184
|
)
|
|
162
|
-
is_list =
|
|
185
|
+
is_list = (
|
|
186
|
+
isinstance(property.type, ListablePropertyType)
|
|
187
|
+
and property.type.is_list
|
|
188
|
+
)
|
|
163
189
|
connection_type = ConnectionTypeEnum.DIRECT_RELATION
|
|
164
190
|
elif isinstance(property, SingleReverseDirectRelation) and property.source:
|
|
165
191
|
nodes = self._map_node_property(
|
|
@@ -62,15 +62,7 @@ class UpsertMapper:
|
|
|
62
62
|
entry = instance.__getattribute__(property_key)
|
|
63
63
|
|
|
64
64
|
if isinstance(property, MappedProperty):
|
|
65
|
-
properties[property_name] = (
|
|
66
|
-
DirectRelationReference(
|
|
67
|
-
space=entry.space, external_id=entry.external_id
|
|
68
|
-
)
|
|
69
|
-
if isinstance(entry, InstanceId)
|
|
70
|
-
else datetime_to_ms_iso_timestamp(entry)
|
|
71
|
-
if isinstance(entry, datetime.datetime)
|
|
72
|
-
else entry
|
|
73
|
-
)
|
|
65
|
+
properties[property_name] = self._get_mapped_property_value(entry)
|
|
74
66
|
elif isinstance(property, EdgeConnection) and isinstance(entry, list):
|
|
75
67
|
possible_entries = self._map_edges(instance, property, entry)
|
|
76
68
|
|
|
@@ -102,6 +94,20 @@ class UpsertMapper:
|
|
|
102
94
|
|
|
103
95
|
return node, edges, edges_to_delete
|
|
104
96
|
|
|
97
|
+
def _get_mapped_property_value(self, entry: Any) -> Any:
|
|
98
|
+
if isinstance(entry, list):
|
|
99
|
+
return [self._get_mapped_property_value(item) for item in entry]
|
|
100
|
+
|
|
101
|
+
if isinstance(entry, InstanceId):
|
|
102
|
+
return DirectRelationReference(
|
|
103
|
+
space=entry.space, external_id=entry.external_id
|
|
104
|
+
)
|
|
105
|
+
if isinstance(entry, datetime.date):
|
|
106
|
+
return entry.strftime("%Y-%m-%d")
|
|
107
|
+
if isinstance(entry, datetime.datetime):
|
|
108
|
+
return datetime_to_ms_iso_timestamp(entry)
|
|
109
|
+
return entry
|
|
110
|
+
|
|
105
111
|
def _map_edges(
|
|
106
112
|
self,
|
|
107
113
|
instance: TWritableViewInstance,
|
|
@@ -9,10 +9,10 @@ industrial_model/cognite_adapters/filter_mapper.py,sha256=R_OX8JOM33vzBVFvfo0iDm
|
|
|
9
9
|
industrial_model/cognite_adapters/models.py,sha256=2j2IS01uPkQEp9WdVk8seYzEqGcDdWFnpzXhusHB2zk,945
|
|
10
10
|
industrial_model/cognite_adapters/optimizer.py,sha256=EQfCe-4mSeXhYa2kcqJerPXYsCRgMJPA1AIf1o1KNH0,2415
|
|
11
11
|
industrial_model/cognite_adapters/query_mapper.py,sha256=QdFVkfmL4tWcCy_oypOluT0Fo68obPk2RjBPvVA9mUs,5950
|
|
12
|
-
industrial_model/cognite_adapters/query_result_mapper.py,sha256=
|
|
12
|
+
industrial_model/cognite_adapters/query_result_mapper.py,sha256=KaBqYr5l1t8sQMxEoX_F3J2prypKIPaDJxSzGF_fMB8,10203
|
|
13
13
|
industrial_model/cognite_adapters/search_mapper.py,sha256=dh69Te8oiDIRPbEMTcof-ZJ4XD-xB5iiBHUR0UETzho,1504
|
|
14
14
|
industrial_model/cognite_adapters/sort_mapper.py,sha256=RJUAYlZGXoYzK0PwX63cibRF_L-MUq9g2ZsC2EeNIF4,696
|
|
15
|
-
industrial_model/cognite_adapters/upsert_mapper.py,sha256=
|
|
15
|
+
industrial_model/cognite_adapters/upsert_mapper.py,sha256=fIz2WLnn0YpsgotGH2MXAa9QYWjQehpWsX3MAKhvRkw,4951
|
|
16
16
|
industrial_model/cognite_adapters/utils.py,sha256=-9NUG84r49cKvmmzoUinxNF1zhHIlmoWFypUCD_WTeM,4800
|
|
17
17
|
industrial_model/cognite_adapters/view_mapper.py,sha256=fihoxyLKvq8xa1oArdCCkukqVpOexFcBDnEyMACpHF8,1430
|
|
18
18
|
industrial_model/engines/__init__.py,sha256=7aGHrUm2MxIq39vR8h0xu3i1zNOuT9H9U-q4lV3nErQ,102
|
|
@@ -28,6 +28,6 @@ industrial_model/queries/params.py,sha256=50qY5BO5onLsXorhcv-7qCKhJaMO94UzhKLCmZ
|
|
|
28
28
|
industrial_model/queries/utils.py,sha256=uP6PLh9IVHDK6J8x444zHWPmyV4PkxdLO-PMc6qWItc,1505
|
|
29
29
|
industrial_model/statements/__init__.py,sha256=rjLRo2KoazHQaOpmPkxbI3_Nm8NCkJxjpuqow6IZVSc,4221
|
|
30
30
|
industrial_model/statements/expressions.py,sha256=4ZZOcZroI5-4xRw4PXIRlufi0ARndE5zSbbxLDpR2Ec,4816
|
|
31
|
-
industrial_model-0.1.
|
|
32
|
-
industrial_model-0.1.
|
|
33
|
-
industrial_model-0.1.
|
|
31
|
+
industrial_model-0.1.31.dist-info/METADATA,sha256=BZq-MwEpDSndxkVUf5A6odc9ENMiUuOa_MnKjLTjcSo,6858
|
|
32
|
+
industrial_model-0.1.31.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
33
|
+
industrial_model-0.1.31.dist-info/RECORD,,
|
|
File without changes
|