Attribute
Module: thinkiq.model.attribute
ThinkIQ entity that can be a child of equipment and exposes historical data via a tag.
Core Functionalities:
Link to a tag to represent sensor or system data
Read and write historical time series data
Perform time-based analytics like accumulation over a period
Manage configuration attributes and store live values
Usage Example:
>>> attr = Attribute.get_from_id(123)
>>> attr.load_value_stream(datetime.datetime(2025, 1, 1), datetime.datetime(2025, 1, 2))
>>> print(attr.value_stream.pandas.head())
Dependencies:
pandas
psycopg2 or other DB-API compatible PostgreSQL driver
ThinkIQ internal modules: database, common, model
Class Listings
Attribute
Attribute
- class thinkiq.model.attribute.Attribute(**kwargs)
An attribute in the ThinkIQ system.
Attributes are the most basic reference to physical entities in the plant. Attributes are owned by equipment. Each attribute can be linked to one Tag. Once linked, its data mirrors the tag’s data.
The initialization of an attribute has multiple creational methods that allow for an array of arguments. Options included:
- classmethod get_from_id(id)
Retrieve a ThinkIQ object from the database using its id.
- Parameters:
id (int)
- classmethod get_from_fqn(fqn)
Retrieve a ThinkIQ object from the database using its fully qualified name, referred to as its fqn.
- Parameters:
fqn (str, list)
Notes
Supported strings are as follows: ‘plant_1.area_1.eq_1’ ‘plant_1,area_1,eq_1’
Fqn’s supplied as a list should be as follows: [ ‘plant_1’, ‘area_1’, ‘eq_1’ ]
- classmethod get_from_parent_id(part_of_id, relative_name)
Retrieve a ThinkIQ object from the database using its part_of_id (its parents id) and its relative_name.
- Parameters:
part_of_id (int) – The id of the parent object.
relative_name (str) – The requested objects relative_name as stored in the database. Not the display_name as shown in ThinkIQ.
- classmethod get_from_parent(parent, relative_name)
Retrieve a ThinkIQ object from the database using its parent python object and its relative_name.
- Parameters:
parent (thinkiq.model.node.Node) – The parent object
relative_name (str) – The requested objects relative_name as stored in the database. Not the display_name as shown in ThinkIQ.
Properties:
- id: int
- part_of_id: int
- fqn: list
- data_type: str
- measurement_unit
The measurement unit object of the ThinkIQ attribute.
- Type:
- Value:
None
- tag
The tag object of the ThinkIQ attribute.
- Type:
- Value:
None
- value_stream
Return the current value stream for this attribute.
- Type:
thinkiq.model.value_stream.ValueStream
- Getter:
Returns the ValueStream object associated with this attribute.
- Setter:
Assigns a ValueStream object and updates start/end datetimes.
- value
Return the current value of the attribute.
Returns live data if linked to a tag, or the last config value if not. If the attribute is tag-based, setting the value raises an exception.
- Type:
Any
- Getter:
Returns live value from tag or static config value.
- Setter:
Updates config value in DB for non-tag attributes.
Methods
- __init__(**kwargs)
Construct an Attribute object using keyword arguments (become its properties).
- _load_node_details()
Creates Python attributes for columns that map to ThinkIQ model entities. Loads MeasurementUnit and Tag when their _id are present.
- Return type:
None
- _get_history_column_name()
Internal helper: map data type to history column name.
- Return type:
str
- load_value_stream(start_datetime, end_datetime)
Load a ValueStream into this attribute.
- Return type:
- save_value_stream(value_stream=None)
Store the value stream into ThinkIQ history using this attribute’s tag_id.
- Return type:
None
- get_times_to_accumulated_value(input_value_stream, accumulation_target, direction, max_duration=datetime.timedelta(seconds=3600))
- Calculate time-to-accumulate for each timestamp in the given input stream.
Returns a ValueStream of times (seconds).
- Parameters:
input_value_stream (ValueStream) – ValueStream object instance with the timestamps to calculate accumulation target.
accumulation_target (int, float) – Accumulation sum target threshold.
timestamp (datetime.datetime) – The datetime to begin accumulation sum.
max_duration (datetime.timedelta, optional) – Maximum time allowed to sum accumulation, by default datetime.timedelta(hours=1)
- Return type:
- Returns:
ValueStream – Value stream whose values reflect the accumulation times for each datetime that was present in input_value_stream.
IMPORTANT NOTE
————–
A method by the same name is called on value_stream. It may throw an error if there is insufficient
data loaded. Calling the method on the attribute instead will handle the issue by reloading. i
Otherwise, implement similar logic on the client
try – …
except common.InsufficientTimeRangeException as e – self.load_value_stream(e.required_range) …. and retry
- classmethod get_all_children_with_type(parent, child_type)
Retrieve a list of ThinkIQ model objects from the database that have the same parent and type.
- Parameters:
parent (Node) – The parent python object.
child_type (type) – The python class with which to retrieve a list of children.
- Returns:
List of ThinkIQ model objects with type child_type
- Return type:
list
- create_tag_if_not_exists()
Creates a tag and links it to this attribute if missing. Updates attribute.tag with a Tag instance.
- Return type:
None
- get_limits()
Load all limits attached to this Attribute.
- Return type:
list[Limit]
- evaluate_limits()
Evaluate this attribute’s current value against its limits.
Colors:
“Red” if value <= LoLo or >= HiHi
“Yellow” if value <= Lo or >= Hi
“Green” if value between Lo and Hi
- returns:
str
- rtype:
“Red”, “Yellow”, or “Green”
- get_enumeration_type()
Load the EnumerationType if this Attribute is of type ‘enumeration’.
- Return type:
Optional[EnumerationType]
- encode(values)
Encode names using the attached EnumerationType.
- decode(values)
Decode values using the attached EnumerationType.