industrial-model 0.1.23__py3-none-any.whl → 0.1.25__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/filter_mapper.py +14 -4
- industrial_model/queries/models.py +5 -5
- industrial_model/queries/params.py +16 -4
- {industrial_model-0.1.23.dist-info → industrial_model-0.1.25.dist-info}/METADATA +1 -1
- {industrial_model-0.1.23.dist-info → industrial_model-0.1.25.dist-info}/RECORD +6 -6
- {industrial_model-0.1.23.dist-info → industrial_model-0.1.25.dist-info}/WHEEL +0 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
from datetime import date, datetime
|
|
2
|
+
from typing import Any
|
|
2
3
|
|
|
3
4
|
import cognite.client.data_classes.filters as cdf_filters
|
|
4
5
|
from cognite.client.data_classes.data_modeling import MappedProperty, View
|
|
5
6
|
|
|
6
7
|
from industrial_model.cognite_adapters.utils import get_property_ref
|
|
8
|
+
from industrial_model.models.entities import InstanceId
|
|
7
9
|
from industrial_model.statements import (
|
|
8
10
|
BoolExpression,
|
|
9
11
|
Expression,
|
|
@@ -54,11 +56,8 @@ class FilterMapper:
|
|
|
54
56
|
property_ref = get_property_ref(expression.property, root_view)
|
|
55
57
|
|
|
56
58
|
value_ = expression.value
|
|
57
|
-
if isinstance(value_, datetime):
|
|
58
|
-
value_ = datetime_to_ms_iso_timestamp(value_)
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
value_ = value_.strftime("%Y-%m-%d")
|
|
60
|
+
value_ = self._handle_type_value_convertion(value_)
|
|
62
61
|
|
|
63
62
|
if expression.operator == "==":
|
|
64
63
|
return cdf_filters.Equals(property_ref, value_)
|
|
@@ -96,3 +95,14 @@ class FilterMapper:
|
|
|
96
95
|
assert isinstance(view_definiton, MappedProperty)
|
|
97
96
|
assert view_definiton.source
|
|
98
97
|
return self._view_mapper.get_view(view_definiton.source.external_id)
|
|
98
|
+
|
|
99
|
+
def _handle_type_value_convertion(self, value_: Any) -> Any:
|
|
100
|
+
if isinstance(value_, datetime):
|
|
101
|
+
return datetime_to_ms_iso_timestamp(value_)
|
|
102
|
+
elif isinstance(value_, date):
|
|
103
|
+
return value_.strftime("%Y-%m-%d")
|
|
104
|
+
elif isinstance(value_, InstanceId):
|
|
105
|
+
return value_.model_dump(mode="json", by_alias=True)
|
|
106
|
+
elif isinstance(value_, list):
|
|
107
|
+
return [self._handle_type_value_convertion(v) for v in value_]
|
|
108
|
+
return value_
|
|
@@ -18,7 +18,7 @@ class BaseQuery(RootModel):
|
|
|
18
18
|
|
|
19
19
|
for key, item in self.__class__.model_fields.items():
|
|
20
20
|
values = getattr(self, key)
|
|
21
|
-
if
|
|
21
|
+
if values is None:
|
|
22
22
|
continue
|
|
23
23
|
for metadata_item in item.metadata:
|
|
24
24
|
if isinstance(metadata_item, SortParam):
|
|
@@ -43,7 +43,7 @@ class BasePaginatedQuery(BaseQuery):
|
|
|
43
43
|
|
|
44
44
|
class BaseSearchQuery(RootModel):
|
|
45
45
|
query: str | None = None
|
|
46
|
-
query_properties: list[
|
|
46
|
+
query_properties: list[Any] | None = None
|
|
47
47
|
limit: int = 1000
|
|
48
48
|
|
|
49
49
|
def to_statement(
|
|
@@ -53,7 +53,7 @@ class BaseSearchQuery(RootModel):
|
|
|
53
53
|
|
|
54
54
|
for key, item in self.__class__.model_fields.items():
|
|
55
55
|
values = getattr(self, key)
|
|
56
|
-
if
|
|
56
|
+
if values is None:
|
|
57
57
|
continue
|
|
58
58
|
for metadata_item in item.metadata:
|
|
59
59
|
if isinstance(metadata_item, SortParam):
|
|
@@ -69,7 +69,7 @@ class BaseSearchQuery(RootModel):
|
|
|
69
69
|
|
|
70
70
|
class BaseAggregationQuery(RootModel):
|
|
71
71
|
aggregate: AggregateTypes | None = None
|
|
72
|
-
group_by_properties: list[
|
|
72
|
+
group_by_properties: list[Any] | None = None
|
|
73
73
|
aggregation_property: str | None = None
|
|
74
74
|
limit: int | None = None
|
|
75
75
|
|
|
@@ -80,7 +80,7 @@ class BaseAggregationQuery(RootModel):
|
|
|
80
80
|
|
|
81
81
|
for key, item in self.__class__.model_fields.items():
|
|
82
82
|
values = getattr(self, key)
|
|
83
|
-
if
|
|
83
|
+
if values is None:
|
|
84
84
|
continue
|
|
85
85
|
for metadata_item in item.metadata:
|
|
86
86
|
if isinstance(metadata_item, QueryParam | NestedQueryParam):
|
|
@@ -5,7 +5,7 @@ from industrial_model.constants import (
|
|
|
5
5
|
LEAF_EXPRESSION_OPERATORS,
|
|
6
6
|
SORT_DIRECTION,
|
|
7
7
|
)
|
|
8
|
-
from industrial_model.statements import LeafExpression
|
|
8
|
+
from industrial_model.statements import BoolExpression, Expression, LeafExpression
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
@dataclass
|
|
@@ -13,9 +13,21 @@ class QueryParam:
|
|
|
13
13
|
property: str
|
|
14
14
|
operator: LEAF_EXPRESSION_OPERATORS
|
|
15
15
|
|
|
16
|
-
def to_expression(self, value: Any) ->
|
|
16
|
+
def to_expression(self, value: Any) -> Expression:
|
|
17
17
|
if self.operator == "nested":
|
|
18
|
-
raise ValueError(
|
|
18
|
+
raise ValueError(
|
|
19
|
+
"Nested operator not allowed in QueryParam - use NestedQueryParam"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
if self.operator == "exists" and isinstance(value, bool) and not value:
|
|
23
|
+
return BoolExpression(
|
|
24
|
+
operator="not",
|
|
25
|
+
filters=[
|
|
26
|
+
LeafExpression(
|
|
27
|
+
property=self.property, operator=self.operator, value=True
|
|
28
|
+
)
|
|
29
|
+
],
|
|
30
|
+
)
|
|
19
31
|
|
|
20
32
|
return LeafExpression(
|
|
21
33
|
property=self.property,
|
|
@@ -29,7 +41,7 @@ class NestedQueryParam:
|
|
|
29
41
|
property: str
|
|
30
42
|
value: QueryParam
|
|
31
43
|
|
|
32
|
-
def to_expression(self, value: Any) ->
|
|
44
|
+
def to_expression(self, value: Any) -> Expression:
|
|
33
45
|
return LeafExpression(
|
|
34
46
|
property=self.property,
|
|
35
47
|
operator="nested",
|
|
@@ -5,7 +5,7 @@ industrial_model/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
5
5
|
industrial_model/utils.py,sha256=oh4AxwxXaWgIC2uolkCbvkgo0ququHB6yAPVIXy45Ts,663
|
|
6
6
|
industrial_model/cognite_adapters/__init__.py,sha256=cKPW5y-wWiyWYLPDaNjhqc5zdsgdLc40vunIlz2Debg,6246
|
|
7
7
|
industrial_model/cognite_adapters/aggregation_mapper.py,sha256=qglWUnyhgSPG005HzIRyjYkt9V2WKsab5y4ruwuKLcA,2503
|
|
8
|
-
industrial_model/cognite_adapters/filter_mapper.py,sha256=
|
|
8
|
+
industrial_model/cognite_adapters/filter_mapper.py,sha256=R_OX8JOM33vzBVFvfo0iDmSJl5rhGjsTBLyKDoesHO0,4349
|
|
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
|
|
@@ -23,10 +23,10 @@ industrial_model/models/base.py,sha256=iGhDjXqA5ULEQIFHtkMi7WYJl0nQq1wi8_zqOr-Ep
|
|
|
23
23
|
industrial_model/models/entities.py,sha256=tHOFjS-9XsaXVrZ-x0tZR1DWL2Cc8MHe82qsIazqmnM,2811
|
|
24
24
|
industrial_model/models/schemas.py,sha256=EoLK9GYdS-0DQ98myTP3wOU9YpWIJOfDSLOYZUy3xEY,4559
|
|
25
25
|
industrial_model/queries/__init__.py,sha256=0cF-KTTGHLhdFKe3T_5cEVHsTN95iAV7R6FUutvuoaU,317
|
|
26
|
-
industrial_model/queries/models.py,sha256=
|
|
27
|
-
industrial_model/queries/params.py,sha256=
|
|
26
|
+
industrial_model/queries/models.py,sha256=XS-50Ja11fVM5G7XTvrFf4OSUD3QO58rAKkkFBQ3Xbg,3255
|
|
27
|
+
industrial_model/queries/params.py,sha256=U2LCdmDs_jrROvJIsWdopAmZAhXrK2gDr4kuDlVK7Ug,1384
|
|
28
28
|
industrial_model/statements/__init__.py,sha256=rjLRo2KoazHQaOpmPkxbI3_Nm8NCkJxjpuqow6IZVSc,4221
|
|
29
29
|
industrial_model/statements/expressions.py,sha256=4ZZOcZroI5-4xRw4PXIRlufi0ARndE5zSbbxLDpR2Ec,4816
|
|
30
|
-
industrial_model-0.1.
|
|
31
|
-
industrial_model-0.1.
|
|
32
|
-
industrial_model-0.1.
|
|
30
|
+
industrial_model-0.1.25.dist-info/METADATA,sha256=derKswE0QRuEHyTTA3oq3wD2jxq06-NnkJYiDiHqNQY,6858
|
|
31
|
+
industrial_model-0.1.25.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
32
|
+
industrial_model-0.1.25.dist-info/RECORD,,
|
|
File without changes
|