industrial-model 0.1.28__py3-none-any.whl → 0.1.30__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/upsert_mapper.py +15 -9
- industrial_model/models/entities.py +52 -0
- {industrial_model-0.1.28.dist-info → industrial_model-0.1.30.dist-info}/METADATA +1 -1
- {industrial_model-0.1.28.dist-info → industrial_model-0.1.30.dist-info}/RECORD +5 -5
- {industrial_model-0.1.28.dist-info → industrial_model-0.1.30.dist-info}/WHEEL +0 -0
|
@@ -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,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from abc import abstractmethod
|
|
2
|
+
from datetime import date, datetime
|
|
2
3
|
from typing import (
|
|
3
4
|
Any,
|
|
4
5
|
ClassVar,
|
|
@@ -10,6 +11,8 @@ from typing import (
|
|
|
10
11
|
|
|
11
12
|
from pydantic import PrivateAttr
|
|
12
13
|
|
|
14
|
+
from industrial_model.statements import Column
|
|
15
|
+
|
|
13
16
|
from .base import DBModelMetaclass, RootModel
|
|
14
17
|
|
|
15
18
|
|
|
@@ -45,6 +48,7 @@ class ViewInstanceConfig(TypedDict, total=False):
|
|
|
45
48
|
view_external_id: str | None
|
|
46
49
|
instance_spaces: list[str] | None
|
|
47
50
|
instance_spaces_prefix: str | None
|
|
51
|
+
view_code: str | None
|
|
48
52
|
|
|
49
53
|
|
|
50
54
|
class ViewInstance(InstanceId, metaclass=DBModelMetaclass):
|
|
@@ -56,6 +60,54 @@ class ViewInstance(InstanceId, metaclass=DBModelMetaclass):
|
|
|
56
60
|
def get_view_external_id(cls) -> str:
|
|
57
61
|
return cls.view_config.get("view_external_id") or cls.__name__
|
|
58
62
|
|
|
63
|
+
def generate_model_id(
|
|
64
|
+
self,
|
|
65
|
+
fields: list[str] | list[Column] | list[Any],
|
|
66
|
+
view_code_as_prefix: bool = True,
|
|
67
|
+
separator: str = "-",
|
|
68
|
+
) -> str:
|
|
69
|
+
if not fields:
|
|
70
|
+
raise ValueError("Fields list cannot be empty")
|
|
71
|
+
field_values = self._get_field_values(fields)
|
|
72
|
+
|
|
73
|
+
view_code = self.view_config.get("view_code")
|
|
74
|
+
|
|
75
|
+
result = separator.join(field_values)
|
|
76
|
+
return (
|
|
77
|
+
f"{view_code}{separator}{result}"
|
|
78
|
+
if view_code_as_prefix and view_code
|
|
79
|
+
else result
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
def _get_field_values(
|
|
83
|
+
self, fields: list[str] | list[Column] | list[Any]
|
|
84
|
+
) -> list[str]:
|
|
85
|
+
field_values: list[str] = []
|
|
86
|
+
for field in fields:
|
|
87
|
+
if not isinstance(field, str | Column):
|
|
88
|
+
field_type = type(field).__name__
|
|
89
|
+
raise TypeError(
|
|
90
|
+
f"Expected field to be a string or Column, got {field_type}"
|
|
91
|
+
)
|
|
92
|
+
field_name = self.get_field_name(
|
|
93
|
+
field.property if isinstance(field, Column) else field
|
|
94
|
+
)
|
|
95
|
+
if field_name is None:
|
|
96
|
+
raise ValueError(f"Field {field} not found in the model")
|
|
97
|
+
field_entry = getattr(self, field_name)
|
|
98
|
+
|
|
99
|
+
field_entry_str = ""
|
|
100
|
+
if isinstance(field_entry, str):
|
|
101
|
+
field_entry_str = field_entry
|
|
102
|
+
elif isinstance(field_entry, date | datetime):
|
|
103
|
+
field_entry_str = field_entry.isoformat()
|
|
104
|
+
elif isinstance(field_entry, InstanceId):
|
|
105
|
+
field_entry_str = field_entry.external_id
|
|
106
|
+
else:
|
|
107
|
+
field_entry_str = str(field_entry)
|
|
108
|
+
field_values.append(field_entry_str.replace(" ", ""))
|
|
109
|
+
return field_values
|
|
110
|
+
|
|
59
111
|
|
|
60
112
|
class WritableViewInstance(ViewInstance):
|
|
61
113
|
@abstractmethod
|
|
@@ -12,7 +12,7 @@ industrial_model/cognite_adapters/query_mapper.py,sha256=QdFVkfmL4tWcCy_oypOluT0
|
|
|
12
12
|
industrial_model/cognite_adapters/query_result_mapper.py,sha256=iCcTb0AUg5rtw8nhK7D4d_x6Z53zgNMpvWrVRM0R2pY,9315
|
|
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
|
|
@@ -20,7 +20,7 @@ industrial_model/engines/async_engine.py,sha256=-sQv2vn93bBmTZOxY_C1r40YP7IMl1ND
|
|
|
20
20
|
industrial_model/engines/engine.py,sha256=lECOpjN6fGvKt28b441isT_u4UNF3LeLiJH-zwHmkYw,3798
|
|
21
21
|
industrial_model/models/__init__.py,sha256=AzJ0CyPK5PvUCX45FFtybl13tkukUvk2UAF_90s_LQ8,742
|
|
22
22
|
industrial_model/models/base.py,sha256=iGhDjXqA5ULEQIFHtkMi7WYJl0nQq1wi8_zqOr-Ep78,1649
|
|
23
|
-
industrial_model/models/entities.py,sha256=
|
|
23
|
+
industrial_model/models/entities.py,sha256=BC85P8THwvVmcNpYq2spJuFJtlK8Oegkmd0kx3CI_wU,4704
|
|
24
24
|
industrial_model/models/schemas.py,sha256=EoLK9GYdS-0DQ98myTP3wOU9YpWIJOfDSLOYZUy3xEY,4559
|
|
25
25
|
industrial_model/queries/__init__.py,sha256=lA83zOxMRgBgkseWJgK9kCr1vD8D8iSWs9NGGRnoYKk,355
|
|
26
26
|
industrial_model/queries/models.py,sha256=VK69c4L0b0miPrKvOQBB8A01SPxZXYThrquv6gw5OGY,2544
|
|
@@ -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.30.dist-info/METADATA,sha256=r4KKWy2zg_TDqDCvkMTSJ8TyrsT105tRKASNb3XyxMM,6858
|
|
32
|
+
industrial_model-0.1.30.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
33
|
+
industrial_model-0.1.30.dist-info/RECORD,,
|
|
File without changes
|