sift_py.calculated_channels.config

  1from __future__ import annotations
  2
  3from typing import List, Optional, Union
  4
  5from pydantic import BaseModel, ConfigDict, field_validator, model_validator
  6from typing_extensions import NotRequired, TypedDict
  7
  8from sift_py.rule.config import (
  9    ExpressionChannelReference,
 10    ExpressionChannelReferenceChannelConfig,
 11    _channel_references_from_dicts,
 12)
 13
 14
 15class CalculatedChannelConfig(BaseModel):
 16    """
 17    Configuration for a calculated channel.
 18
 19    - `name`: Name of the calculated channel.
 20    - `description`: Description of the calculated channel.
 21    - `expression`: The expression to calculate the value of the calculated channel.
 22    - `channel_references`: A list of channel references that are used in the expression. Each reference can either
 23      be an `ExpressionChannelReference` or `ExpressionChannelReferenceChannelConfig`.
 24    - `units`: Units of the calculated channel.
 25    - `client_key`: A user defined string that uniquely identifies the calculated channel. Name is unique, but may be changed.
 26    - `asset_names`: A list of asset names to make the calculation available for.
 27    - `tags`: A list of tags on assets to make the calculation available for. NOTE: Not yet supported.
 28    - `all_assets`: A flag that, when set to `True`, associates the calculated channel with all assets.
 29    """
 30
 31    model_config = ConfigDict(arbitrary_types_allowed=True)
 32
 33    name: str
 34    description: str = ""
 35    expression: str
 36    channel_references: List[
 37        Union[ExpressionChannelReference, ExpressionChannelReferenceChannelConfig]
 38    ]
 39    units: Optional[str] = None
 40    calculated_channel_id: Optional[str] = None
 41    client_key: Optional[str] = None
 42    asset_names: Optional[List[str]] = None
 43    tag_names: Optional[List[str]] = None
 44    all_assets: bool = False
 45
 46    @field_validator("tag_names", mode="before")
 47    @classmethod
 48    def check_for_unsupported_tags(cls, v):
 49        if v:
 50            raise ValueError("`tag_names` is not yet supported.")
 51        return v
 52
 53    @field_validator("channel_references", mode="before")
 54    @classmethod
 55    def convert_channel_references(
 56        cls, raw: List[Union[ExpressionChannelReference, ExpressionChannelReferenceChannelConfig]]
 57    ) -> List[ExpressionChannelReference]:
 58        if not isinstance(raw, list):
 59            raise ValueError("`channel_references` must be a list.")
 60
 61        for ref in raw:
 62            if not isinstance(ref, dict) or (
 63                "channel_identifier" not in ref and "channel_config" not in ref
 64            ):
 65                raise ValueError(
 66                    "`channel_references` must be a list of `ExpressionChannelReference` or `ExpressionChannelReferenceChannelConfig`."
 67                )
 68
 69        return _channel_references_from_dicts(raw)
 70
 71    @model_validator(mode="after")
 72    def validate_assets(self):
 73        if not self.asset_names and not self.tag_names and not self.all_assets:
 74            raise ValueError(
 75                "At least one of `asset_names`, `tag_names` must be specified or `all_assets` must be set to `True`."
 76            )
 77        if self.all_assets and (self.asset_names or self.tag_names):
 78            raise ValueError(
 79                "`all_assets` cannot be `True` if `asset_names` or `tag_names` are specified."
 80            )
 81        return self
 82
 83
 84class CalculatedChannelUpdate(TypedDict):
 85    """
 86    Represents a dictionary for updating properties of a calculated channel. All fields are optional
 87    and only the provided fields will be updated.
 88
 89    - `name`: Updated name of the calculated channel.
 90    - `description`: Updated description of the calculated channel.
 91    - `units`: String representing the units for the calculated channel.
 92    - `expression`: Updated expression used to calculate channel values.
 93    - `channel_references`: A list of channel references which can either be `ExpressionChannelReference`
 94       or `ExpressionChannelReferenceChannelConfig` used in the expression.
 95    - `asset_names`: List of assets associated with the calculation.
 96    - `tags`: List of tags for associating the calculated channel to assets.
 97    - `all_assets`: Boolean flag indicating if the calculated channel applies to all assets.
 98    - `archived`: Boolean flag indicating if the calculated channel is archived.
 99    """
100
101    name: NotRequired[str]
102    description: NotRequired[str]
103    units: NotRequired[str]
104    expression: NotRequired[str]
105    channel_references: NotRequired[
106        List[Union[ExpressionChannelReference, ExpressionChannelReferenceChannelConfig]]
107    ]
108    asset_names: NotRequired[List[str]]
109    tag_names: NotRequired[List[str]]
110    all_assets: NotRequired[bool]
111    archived: NotRequired[bool]
class CalculatedChannelConfig(pydantic.main.BaseModel):
16class CalculatedChannelConfig(BaseModel):
17    """
18    Configuration for a calculated channel.
19
20    - `name`: Name of the calculated channel.
21    - `description`: Description of the calculated channel.
22    - `expression`: The expression to calculate the value of the calculated channel.
23    - `channel_references`: A list of channel references that are used in the expression. Each reference can either
24      be an `ExpressionChannelReference` or `ExpressionChannelReferenceChannelConfig`.
25    - `units`: Units of the calculated channel.
26    - `client_key`: A user defined string that uniquely identifies the calculated channel. Name is unique, but may be changed.
27    - `asset_names`: A list of asset names to make the calculation available for.
28    - `tags`: A list of tags on assets to make the calculation available for. NOTE: Not yet supported.
29    - `all_assets`: A flag that, when set to `True`, associates the calculated channel with all assets.
30    """
31
32    model_config = ConfigDict(arbitrary_types_allowed=True)
33
34    name: str
35    description: str = ""
36    expression: str
37    channel_references: List[
38        Union[ExpressionChannelReference, ExpressionChannelReferenceChannelConfig]
39    ]
40    units: Optional[str] = None
41    calculated_channel_id: Optional[str] = None
42    client_key: Optional[str] = None
43    asset_names: Optional[List[str]] = None
44    tag_names: Optional[List[str]] = None
45    all_assets: bool = False
46
47    @field_validator("tag_names", mode="before")
48    @classmethod
49    def check_for_unsupported_tags(cls, v):
50        if v:
51            raise ValueError("`tag_names` is not yet supported.")
52        return v
53
54    @field_validator("channel_references", mode="before")
55    @classmethod
56    def convert_channel_references(
57        cls, raw: List[Union[ExpressionChannelReference, ExpressionChannelReferenceChannelConfig]]
58    ) -> List[ExpressionChannelReference]:
59        if not isinstance(raw, list):
60            raise ValueError("`channel_references` must be a list.")
61
62        for ref in raw:
63            if not isinstance(ref, dict) or (
64                "channel_identifier" not in ref and "channel_config" not in ref
65            ):
66                raise ValueError(
67                    "`channel_references` must be a list of `ExpressionChannelReference` or `ExpressionChannelReferenceChannelConfig`."
68                )
69
70        return _channel_references_from_dicts(raw)
71
72    @model_validator(mode="after")
73    def validate_assets(self):
74        if not self.asset_names and not self.tag_names and not self.all_assets:
75            raise ValueError(
76                "At least one of `asset_names`, `tag_names` must be specified or `all_assets` must be set to `True`."
77            )
78        if self.all_assets and (self.asset_names or self.tag_names):
79            raise ValueError(
80                "`all_assets` cannot be `True` if `asset_names` or `tag_names` are specified."
81            )
82        return self

Configuration for a calculated channel.

  • name: Name of the calculated channel.
  • description: Description of the calculated channel.
  • expression: The expression to calculate the value of the calculated channel.
  • channel_references: A list of channel references that are used in the expression. Each reference can either be an ExpressionChannelReference or ExpressionChannelReferenceChannelConfig.
  • units: Units of the calculated channel.
  • client_key: A user defined string that uniquely identifies the calculated channel. Name is unique, but may be changed.
  • asset_names: A list of asset names to make the calculation available for.
  • tags: A list of tags on assets to make the calculation available for. NOTE: Not yet supported.
  • all_assets: A flag that, when set to True, associates the calculated channel with all assets.
model_config = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
description: str
expression: str
units: Union[str, NoneType]
calculated_channel_id: Union[str, NoneType]
client_key: Union[str, NoneType]
asset_names: Union[List[str], NoneType]
tag_names: Union[List[str], NoneType]
all_assets: bool
@field_validator('tag_names', mode='before')
@classmethod
def check_for_unsupported_tags(cls, v):
47    @field_validator("tag_names", mode="before")
48    @classmethod
49    def check_for_unsupported_tags(cls, v):
50        if v:
51            raise ValueError("`tag_names` is not yet supported.")
52        return v
@field_validator('channel_references', mode='before')
@classmethod
def convert_channel_references( cls, raw: List[Union[sift_py.rule.config.ExpressionChannelReference, sift_py.rule.config.ExpressionChannelReferenceChannelConfig]]) -> List[sift_py.rule.config.ExpressionChannelReference]:
54    @field_validator("channel_references", mode="before")
55    @classmethod
56    def convert_channel_references(
57        cls, raw: List[Union[ExpressionChannelReference, ExpressionChannelReferenceChannelConfig]]
58    ) -> List[ExpressionChannelReference]:
59        if not isinstance(raw, list):
60            raise ValueError("`channel_references` must be a list.")
61
62        for ref in raw:
63            if not isinstance(ref, dict) or (
64                "channel_identifier" not in ref and "channel_config" not in ref
65            ):
66                raise ValueError(
67                    "`channel_references` must be a list of `ExpressionChannelReference` or `ExpressionChannelReferenceChannelConfig`."
68                )
69
70        return _channel_references_from_dicts(raw)
@model_validator(mode='after')
def validate_assets(self):
72    @model_validator(mode="after")
73    def validate_assets(self):
74        if not self.asset_names and not self.tag_names and not self.all_assets:
75            raise ValueError(
76                "At least one of `asset_names`, `tag_names` must be specified or `all_assets` must be set to `True`."
77            )
78        if self.all_assets and (self.asset_names or self.tag_names):
79            raise ValueError(
80                "`all_assets` cannot be `True` if `asset_names` or `tag_names` are specified."
81            )
82        return self
model_fields: ClassVar[Dict[str, pydantic.fields.FieldInfo]] = {'name': FieldInfo(annotation=str, required=True), 'description': FieldInfo(annotation=str, required=False, default=''), 'expression': FieldInfo(annotation=str, required=True), 'channel_references': FieldInfo(annotation=List[Union[sift_py.rule.config.ExpressionChannelReference, sift_py.rule.config.ExpressionChannelReferenceChannelConfig]], required=True), 'units': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'calculated_channel_id': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'client_key': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'asset_names': FieldInfo(annotation=Union[List[str], NoneType], required=False, default=None), 'tag_names': FieldInfo(annotation=Union[List[str], NoneType], required=False, default=None), 'all_assets': FieldInfo(annotation=bool, required=False, default=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

model_computed_fields: ClassVar[Dict[str, pydantic.fields.ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

Inherited Members
pydantic.main.BaseModel
BaseModel
model_extra
model_fields_set
model_construct
model_copy
model_dump
model_dump_json
model_json_schema
model_parametrized_name
model_post_init
model_rebuild
model_validate
model_validate_json
model_validate_strings
dict
json
parse_obj
parse_raw
parse_file
from_orm
construct
copy
schema
schema_json
validate
update_forward_refs
class CalculatedChannelUpdate(typing_extensions.TypedDict):
 85class CalculatedChannelUpdate(TypedDict):
 86    """
 87    Represents a dictionary for updating properties of a calculated channel. All fields are optional
 88    and only the provided fields will be updated.
 89
 90    - `name`: Updated name of the calculated channel.
 91    - `description`: Updated description of the calculated channel.
 92    - `units`: String representing the units for the calculated channel.
 93    - `expression`: Updated expression used to calculate channel values.
 94    - `channel_references`: A list of channel references which can either be `ExpressionChannelReference`
 95       or `ExpressionChannelReferenceChannelConfig` used in the expression.
 96    - `asset_names`: List of assets associated with the calculation.
 97    - `tags`: List of tags for associating the calculated channel to assets.
 98    - `all_assets`: Boolean flag indicating if the calculated channel applies to all assets.
 99    - `archived`: Boolean flag indicating if the calculated channel is archived.
100    """
101
102    name: NotRequired[str]
103    description: NotRequired[str]
104    units: NotRequired[str]
105    expression: NotRequired[str]
106    channel_references: NotRequired[
107        List[Union[ExpressionChannelReference, ExpressionChannelReferenceChannelConfig]]
108    ]
109    asset_names: NotRequired[List[str]]
110    tag_names: NotRequired[List[str]]
111    all_assets: NotRequired[bool]
112    archived: NotRequired[bool]

Represents a dictionary for updating properties of a calculated channel. All fields are optional and only the provided fields will be updated.

  • name: Updated name of the calculated channel.
  • description: Updated description of the calculated channel.
  • units: String representing the units for the calculated channel.
  • expression: Updated expression used to calculate channel values.
  • channel_references: A list of channel references which can either be ExpressionChannelReference or ExpressionChannelReferenceChannelConfig used in the expression.
  • asset_names: List of assets associated with the calculation.
  • tags: List of tags for associating the calculated channel to assets.
  • all_assets: Boolean flag indicating if the calculated channel applies to all assets.
  • archived: Boolean flag indicating if the calculated channel is archived.
name: typing_extensions.NotRequired[str]
description: typing_extensions.NotRequired[str]
units: typing_extensions.NotRequired[str]
expression: typing_extensions.NotRequired[str]
channel_references: typing_extensions.NotRequired[typing.List[typing.Union[sift_py.rule.config.ExpressionChannelReference, sift_py.rule.config.ExpressionChannelReferenceChannelConfig]]]
asset_names: typing_extensions.NotRequired[typing.List[str]]
tag_names: typing_extensions.NotRequired[typing.List[str]]
all_assets: typing_extensions.NotRequired[bool]
archived: typing_extensions.NotRequired[bool]