industrial-model 0.1.34__tar.gz → 0.1.36__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.34 → industrial_model-0.1.36}/PKG-INFO +1 -1
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/engines/engine.py +2 -16
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/models/__init__.py +2 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/models/base.py +11 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/models/entities.py +27 -2
- industrial_model-0.1.36/industrial_model/models/utils.py +58 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/pyproject.toml +1 -1
- {industrial_model-0.1.34 → industrial_model-0.1.36}/.gitignore +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/README.md +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/__init__.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/__init__.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/aggregation_mapper.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/filter_mapper.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/models.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/optimizer.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/query_mapper.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/query_result_mapper.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/search_mapper.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/sort_mapper.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/upsert_mapper.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/utils.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/view_mapper.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/config.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/constants.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/engines/__init__.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/engines/async_engine.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/models/schemas.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/py.typed +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/queries/__init__.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/queries/models.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/queries/params.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/queries/utils.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/statements/__init__.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/statements/expressions.py +0 -0
- {industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/utils.py +0 -0
|
@@ -5,12 +5,12 @@ from cognite.client import CogniteClient
|
|
|
5
5
|
from industrial_model.cognite_adapters import CogniteAdapter
|
|
6
6
|
from industrial_model.config import DataModelId
|
|
7
7
|
from industrial_model.models import (
|
|
8
|
-
EdgeContainer,
|
|
9
8
|
PaginatedResult,
|
|
10
9
|
TAggregatedViewInstance,
|
|
11
10
|
TViewInstance,
|
|
12
11
|
TWritableViewInstance,
|
|
13
12
|
ValidationMode,
|
|
13
|
+
include_edges,
|
|
14
14
|
)
|
|
15
15
|
from industrial_model.statements import (
|
|
16
16
|
AggregationStatement,
|
|
@@ -96,24 +96,10 @@ class Engine:
|
|
|
96
96
|
for item in data:
|
|
97
97
|
try:
|
|
98
98
|
validated_item = entity.model_validate(item)
|
|
99
|
-
|
|
99
|
+
include_edges(item, validated_item)
|
|
100
100
|
result.append(validated_item)
|
|
101
101
|
except Exception:
|
|
102
102
|
if validation_mode == "ignoreOnError":
|
|
103
103
|
continue
|
|
104
104
|
raise
|
|
105
105
|
return result
|
|
106
|
-
|
|
107
|
-
def _include_edges(
|
|
108
|
-
self, item: dict[str, Any], validated_item: TViewInstance
|
|
109
|
-
) -> None:
|
|
110
|
-
if "_edges" not in item or not isinstance(item["_edges"], dict):
|
|
111
|
-
return
|
|
112
|
-
entries: dict[str, list[EdgeContainer]] = {}
|
|
113
|
-
for property_, edges in item["_edges"].items():
|
|
114
|
-
if not edges or not isinstance(edges, list):
|
|
115
|
-
continue
|
|
116
|
-
|
|
117
|
-
assert isinstance(edges[0], EdgeContainer)
|
|
118
|
-
entries[property_] = edges
|
|
119
|
-
validated_item._edges = entries
|
|
@@ -13,12 +13,14 @@ from .entities import (
|
|
|
13
13
|
WritableViewInstance,
|
|
14
14
|
)
|
|
15
15
|
from .schemas import get_parent_and_children_nodes, get_schema_properties
|
|
16
|
+
from .utils import include_edges
|
|
16
17
|
|
|
17
18
|
__all__ = [
|
|
18
19
|
"AggregatedViewInstance",
|
|
19
20
|
"RootModel",
|
|
20
21
|
"EdgeContainer",
|
|
21
22
|
"InstanceId",
|
|
23
|
+
"include_edges",
|
|
22
24
|
"TAggregatedViewInstance",
|
|
23
25
|
"TViewInstance",
|
|
24
26
|
"TWritableViewInstance",
|
|
@@ -55,3 +55,14 @@ class RootModel(BaseModel):
|
|
|
55
55
|
return key
|
|
56
56
|
|
|
57
57
|
return None
|
|
58
|
+
|
|
59
|
+
def get_field_alias(self, field_name_or_alias: str) -> str | None:
|
|
60
|
+
entry = self.__class__.model_fields.get(field_name_or_alias)
|
|
61
|
+
if entry:
|
|
62
|
+
return entry.alias
|
|
63
|
+
|
|
64
|
+
for _, field_info in self.__class__.model_fields.items():
|
|
65
|
+
if field_info.alias == field_name_or_alias:
|
|
66
|
+
return field_info.alias
|
|
67
|
+
|
|
68
|
+
return None
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from abc import abstractmethod
|
|
2
|
-
from datetime import date, datetime
|
|
2
|
+
from datetime import UTC, date, datetime
|
|
3
3
|
from typing import (
|
|
4
4
|
Any,
|
|
5
5
|
ClassVar,
|
|
@@ -9,7 +9,7 @@ from typing import (
|
|
|
9
9
|
TypeVar,
|
|
10
10
|
)
|
|
11
11
|
|
|
12
|
-
from pydantic import PrivateAttr
|
|
12
|
+
from pydantic import PrivateAttr, computed_field
|
|
13
13
|
|
|
14
14
|
from industrial_model.statements import Column
|
|
15
15
|
|
|
@@ -39,6 +39,18 @@ class EdgeContainer(InstanceId):
|
|
|
39
39
|
type: InstanceId
|
|
40
40
|
start_node: InstanceId
|
|
41
41
|
end_node: InstanceId
|
|
42
|
+
last_updated_time: int
|
|
43
|
+
created_time: int
|
|
44
|
+
|
|
45
|
+
@computed_field # type: ignore[prop-decorator]
|
|
46
|
+
@property
|
|
47
|
+
def created_time_as_datetime(self) -> datetime:
|
|
48
|
+
return datetime.fromtimestamp(self.created_time / 1000, tz=UTC)
|
|
49
|
+
|
|
50
|
+
@computed_field # type: ignore[prop-decorator]
|
|
51
|
+
@property
|
|
52
|
+
def last_updated_time_as_datetime(self) -> datetime:
|
|
53
|
+
return datetime.fromtimestamp(self.last_updated_time / 1000, tz=UTC)
|
|
42
54
|
|
|
43
55
|
|
|
44
56
|
TInstanceId = TypeVar("TInstanceId", bound=InstanceId)
|
|
@@ -60,6 +72,19 @@ class ViewInstance(InstanceId):
|
|
|
60
72
|
def get_view_external_id(cls) -> str:
|
|
61
73
|
return cls.view_config.get("view_external_id") or cls.__name__
|
|
62
74
|
|
|
75
|
+
def get_edge_metadata(self, property: Column | str | Any) -> list[EdgeContainer]:
|
|
76
|
+
assert isinstance(property, Column | str), (
|
|
77
|
+
f"Expected property to be Column, or str, got {type(property).__name__}"
|
|
78
|
+
)
|
|
79
|
+
identifier = property.property if isinstance(property, Column) else property
|
|
80
|
+
|
|
81
|
+
edge_map_key = self.get_field_alias(identifier) or self.get_field_name(
|
|
82
|
+
identifier
|
|
83
|
+
)
|
|
84
|
+
if not edge_map_key:
|
|
85
|
+
return []
|
|
86
|
+
return self._edges.get(edge_map_key, [])
|
|
87
|
+
|
|
63
88
|
def generate_model_id(
|
|
64
89
|
self,
|
|
65
90
|
fields: list[str] | list[Column] | list[Any],
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from .entities import EdgeContainer, TViewInstance, ViewInstance
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def include_edges(
|
|
7
|
+
root_item: dict[str, Any], validated_root_item: TViewInstance
|
|
8
|
+
) -> None:
|
|
9
|
+
if not isinstance(root_item, dict) or not isinstance(
|
|
10
|
+
validated_root_item, ViewInstance
|
|
11
|
+
):
|
|
12
|
+
return
|
|
13
|
+
|
|
14
|
+
for property_, value in root_item.items():
|
|
15
|
+
field_key = validated_root_item.get_field_name(property_)
|
|
16
|
+
if not field_key:
|
|
17
|
+
continue
|
|
18
|
+
_handle_edge_property(validated_root_item, value, field_key)
|
|
19
|
+
_include_edges(root_item, validated_root_item)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _handle_edge_property(
|
|
23
|
+
validated_root_item: TViewInstance, value: Any, field_key: str
|
|
24
|
+
) -> None:
|
|
25
|
+
attr_value = getattr(validated_root_item, field_key, None)
|
|
26
|
+
|
|
27
|
+
if isinstance(value, dict):
|
|
28
|
+
_handle_dict_property(value, attr_value)
|
|
29
|
+
return
|
|
30
|
+
|
|
31
|
+
if (
|
|
32
|
+
not isinstance(value, list)
|
|
33
|
+
or not isinstance(attr_value, list)
|
|
34
|
+
or len(value) != len(attr_value)
|
|
35
|
+
):
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
for index, value_item in enumerate(value):
|
|
39
|
+
entry = attr_value[index]
|
|
40
|
+
_handle_dict_property(value_item, entry)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _handle_dict_property(value: Any, attr_value: Any) -> None:
|
|
44
|
+
if isinstance(value, dict) and isinstance(attr_value, ViewInstance):
|
|
45
|
+
include_edges(value, attr_value)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _include_edges(item: dict[str, Any], validated_item: TViewInstance) -> None:
|
|
49
|
+
if "_edges" not in item or not isinstance(item["_edges"], dict):
|
|
50
|
+
return
|
|
51
|
+
entries: dict[str, list[EdgeContainer]] = {}
|
|
52
|
+
for property_, edges in item["_edges"].items():
|
|
53
|
+
if not edges or not isinstance(edges, list):
|
|
54
|
+
continue
|
|
55
|
+
|
|
56
|
+
assert isinstance(edges[0], EdgeContainer)
|
|
57
|
+
entries[property_] = edges
|
|
58
|
+
validated_item._edges = entries
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/models.py
RENAMED
|
File without changes
|
{industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/optimizer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/sort_mapper.py
RENAMED
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/utils.py
RENAMED
|
File without changes
|
{industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/cognite_adapters/view_mapper.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{industrial_model-0.1.34 → industrial_model-0.1.36}/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
|
{industrial_model-0.1.34 → industrial_model-0.1.36}/industrial_model/statements/expressions.py
RENAMED
|
File without changes
|
|
File without changes
|