industrial-model 0.1.15__tar.gz → 0.1.17__tar.gz
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-0.1.15 → industrial_model-0.1.17}/PKG-INFO +1 -1
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/query_result_mapper.py +35 -6
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/models/schemas.py +14 -7
- {industrial_model-0.1.15 → industrial_model-0.1.17}/pyproject.toml +1 -1
- {industrial_model-0.1.15 → industrial_model-0.1.17}/uv.lock +1 -1
- {industrial_model-0.1.15 → industrial_model-0.1.17}/.gitignore +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/.python-version +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/README.md +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/__init__.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/__init__.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/aggregation_mapper.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/filter_mapper.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/models.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/optimizer.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/query_mapper.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/sort_mapper.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/upsert_mapper.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/utils.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/view_mapper.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/config.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/constants.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/engines/__init__.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/engines/async_engine.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/engines/engine.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/models/__init__.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/models/base.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/models/entities.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/py.typed +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/queries/__init__.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/queries/models.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/queries/params.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/statements/__init__.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/statements/expressions.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/utils.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/scripts/build.sh +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/scripts/format.sh +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/scripts/lint.sh +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/tests/__init__.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/tests/cognite-sdk-config.yaml +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/tests/hubs.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/tests/models.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/tests/test_upsert_mapper.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/tests/tests_adapter.py +0 -0
- {industrial_model-0.1.15 → industrial_model-0.1.17}/tests/tests_aggregate.py +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from collections import defaultdict
|
|
2
|
-
from
|
|
2
|
+
from enum import StrEnum
|
|
3
|
+
from typing import Any, Literal, TypedDict
|
|
3
4
|
|
|
4
5
|
from cognite.client.data_classes.data_modeling import (
|
|
5
6
|
Edge,
|
|
@@ -19,8 +20,15 @@ from industrial_model.models import EdgeContainer
|
|
|
19
20
|
from .view_mapper import ViewMapper
|
|
20
21
|
|
|
21
22
|
|
|
23
|
+
class ConnectionTypeEnum(StrEnum):
|
|
24
|
+
DIRECT_RELATION = "DirectRelation"
|
|
25
|
+
REVERSE_DIRECT_RELATION = "ReverseDirectRelation"
|
|
26
|
+
EDGE = "Edge"
|
|
27
|
+
|
|
28
|
+
|
|
22
29
|
class _PropertyMapping(TypedDict):
|
|
23
30
|
is_list: bool
|
|
31
|
+
connection_type: ConnectionTypeEnum
|
|
24
32
|
nodes: dict[tuple[str, str], list[Node]]
|
|
25
33
|
edges: dict[tuple[str, str], list[Edge]]
|
|
26
34
|
|
|
@@ -92,16 +100,26 @@ class QueryResultMapper:
|
|
|
92
100
|
for mapping_key, mapping_value in mappings.items():
|
|
93
101
|
element = properties.get(mapping_key)
|
|
94
102
|
|
|
103
|
+
mapping_nodes = mapping_value.get("nodes", {})
|
|
104
|
+
mapping_edges = mapping_value.get("edges", {})
|
|
105
|
+
is_list = mapping_value.get("is_list", False)
|
|
106
|
+
connection_type = mapping_value.get(
|
|
107
|
+
"connection_type",
|
|
108
|
+
ConnectionTypeEnum.DIRECT_RELATION,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
if (
|
|
112
|
+
element is None
|
|
113
|
+
and connection_type == ConnectionTypeEnum.DIRECT_RELATION
|
|
114
|
+
):
|
|
115
|
+
continue
|
|
116
|
+
|
|
95
117
|
element_key: tuple[str, str] = (
|
|
96
118
|
(element.get("space", ""), element.get("externalId", ""))
|
|
97
119
|
if isinstance(element, dict)
|
|
98
120
|
else (node.space, node.external_id)
|
|
99
121
|
)
|
|
100
122
|
|
|
101
|
-
mapping_nodes = mapping_value.get("nodes", {})
|
|
102
|
-
mapping_edges = mapping_value.get("edges", {})
|
|
103
|
-
is_list = mapping_value.get("is_list", False)
|
|
104
|
-
|
|
105
123
|
node_entries = mapping_nodes.get(element_key)
|
|
106
124
|
if not node_entries:
|
|
107
125
|
continue
|
|
@@ -116,6 +134,7 @@ class QueryResultMapper:
|
|
|
116
134
|
edge_entries
|
|
117
135
|
)
|
|
118
136
|
properties["_edges"] = edges_mapping
|
|
137
|
+
|
|
119
138
|
node.properties[view_id] = properties
|
|
120
139
|
|
|
121
140
|
result[node_id].append(node)
|
|
@@ -136,6 +155,9 @@ class QueryResultMapper:
|
|
|
136
155
|
nodes: dict[tuple[str, str], list[Node]] | None = None
|
|
137
156
|
edges: dict[tuple[str, str], list[Edge]] | None = None
|
|
138
157
|
is_list = False
|
|
158
|
+
connection_type: ConnectionTypeEnum = (
|
|
159
|
+
ConnectionTypeEnum.DIRECT_RELATION
|
|
160
|
+
)
|
|
139
161
|
|
|
140
162
|
if isinstance(property, MappedProperty) and property.source:
|
|
141
163
|
nodes = self._map_node_property(
|
|
@@ -144,6 +166,7 @@ class QueryResultMapper:
|
|
|
144
166
|
query_result,
|
|
145
167
|
)
|
|
146
168
|
is_list = False
|
|
169
|
+
connection_type = ConnectionTypeEnum.DIRECT_RELATION
|
|
147
170
|
elif (
|
|
148
171
|
isinstance(property, SingleReverseDirectRelation)
|
|
149
172
|
and property.source
|
|
@@ -155,6 +178,7 @@ class QueryResultMapper:
|
|
|
155
178
|
property.through.property,
|
|
156
179
|
)
|
|
157
180
|
is_list = False
|
|
181
|
+
connection_type = ConnectionTypeEnum.REVERSE_DIRECT_RELATION
|
|
158
182
|
elif (
|
|
159
183
|
isinstance(property, MultiReverseDirectRelation)
|
|
160
184
|
and property.source
|
|
@@ -166,6 +190,7 @@ class QueryResultMapper:
|
|
|
166
190
|
property.through.property,
|
|
167
191
|
)
|
|
168
192
|
is_list = True
|
|
193
|
+
connection_type = ConnectionTypeEnum.REVERSE_DIRECT_RELATION
|
|
169
194
|
|
|
170
195
|
elif isinstance(property, EdgeConnection) and property.source:
|
|
171
196
|
nodes, edges = self._map_edge_property(
|
|
@@ -175,10 +200,14 @@ class QueryResultMapper:
|
|
|
175
200
|
property.direction,
|
|
176
201
|
)
|
|
177
202
|
is_list = True
|
|
203
|
+
connection_type = ConnectionTypeEnum.EDGE
|
|
178
204
|
|
|
179
205
|
if nodes:
|
|
180
206
|
mappings[property_name] = _PropertyMapping(
|
|
181
|
-
is_list=is_list,
|
|
207
|
+
is_list=is_list,
|
|
208
|
+
connection_type=connection_type,
|
|
209
|
+
nodes=nodes,
|
|
210
|
+
edges=edges or {},
|
|
182
211
|
)
|
|
183
212
|
|
|
184
213
|
return mappings
|
|
@@ -57,17 +57,21 @@ def get_parent_and_children_nodes(
|
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
def _get_type_properties(
|
|
60
|
-
cls: type[BaseModel],
|
|
60
|
+
cls: type[BaseModel],
|
|
61
|
+
parent_type: type[BaseModel] | None = None,
|
|
62
|
+
visited_count: defaultdict[type, int] | None = None,
|
|
61
63
|
) -> dict[str, Any] | None:
|
|
62
64
|
if visited_count is not None:
|
|
63
|
-
if visited_count[cls] >
|
|
65
|
+
if visited_count[cls] > 1:
|
|
64
66
|
return None
|
|
65
|
-
|
|
67
|
+
elif parent_type == cls:
|
|
68
|
+
visited_count[cls] += 1
|
|
66
69
|
|
|
67
70
|
hints = get_type_hints(cls)
|
|
68
71
|
origins = {
|
|
69
72
|
key: _get_field_type(
|
|
70
73
|
type_hint,
|
|
74
|
+
cls,
|
|
71
75
|
visited_count or defaultdict(lambda: 0),
|
|
72
76
|
)
|
|
73
77
|
for key, type_hint in hints.items()
|
|
@@ -81,13 +85,15 @@ def _get_type_properties(
|
|
|
81
85
|
|
|
82
86
|
|
|
83
87
|
def _get_field_type(
|
|
84
|
-
type_hint: type,
|
|
88
|
+
type_hint: type,
|
|
89
|
+
parent_type: type[BaseModel],
|
|
90
|
+
visited_count: defaultdict[type, int],
|
|
85
91
|
) -> tuple[bool, dict[str, Any] | None]:
|
|
86
92
|
should_iter = _type_is_list_or_union(type_hint)
|
|
87
93
|
|
|
88
94
|
if not should_iter:
|
|
89
95
|
return _get_field_relations(
|
|
90
|
-
[_cast_base_model(type_hint)], visited_count
|
|
96
|
+
[_cast_base_model(type_hint)], parent_type, visited_count
|
|
91
97
|
)
|
|
92
98
|
|
|
93
99
|
entries: list[type[BaseModel] | None] = []
|
|
@@ -96,11 +102,12 @@ def _get_field_type(
|
|
|
96
102
|
return _get_field_type(arg, visited_count)
|
|
97
103
|
entries.append(_cast_base_model(arg))
|
|
98
104
|
|
|
99
|
-
return _get_field_relations(entries, visited_count)
|
|
105
|
+
return _get_field_relations(entries, parent_type, visited_count)
|
|
100
106
|
|
|
101
107
|
|
|
102
108
|
def _get_field_relations(
|
|
103
109
|
entries: list[type[TBaseModel] | None],
|
|
110
|
+
parent_type: type[BaseModel],
|
|
104
111
|
visited_count: defaultdict[type, int],
|
|
105
112
|
) -> tuple[bool, dict[str, Any] | None]:
|
|
106
113
|
entry_type = next((type_ for type_ in entries if type_ is not None), None)
|
|
@@ -108,7 +115,7 @@ def _get_field_relations(
|
|
|
108
115
|
if not entry_type:
|
|
109
116
|
return False, None
|
|
110
117
|
|
|
111
|
-
properties = _get_type_properties(entry_type, visited_count)
|
|
118
|
+
properties = _get_type_properties(entry_type, parent_type, visited_count)
|
|
112
119
|
|
|
113
120
|
return True, properties
|
|
114
121
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/models.py
RENAMED
|
File without changes
|
{industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/optimizer.py
RENAMED
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/sort_mapper.py
RENAMED
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/utils.py
RENAMED
|
File without changes
|
{industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/cognite_adapters/view_mapper.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/engines/async_engine.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.15 → industrial_model-0.1.17}/industrial_model/statements/expressions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|