Equipment

Module: thinkiq.model.equipment

The ThinkIQ entity type Equipment is a virtual representation of factory equipment.

Summary

Equipment can contain other equipment or attributes that connect to historical data. Any equipment’s part_of_id points to the parent object that contains it. Most equipment hold attributes which link process data.

Class listings

Equipment:

Concrete class that retrieves information on ThinkIQ equipment given a unique identifier.

Equipment

class thinkiq.model.equipment.Equipment(**kwargs)

An equipment in the ThinkIQ system.

The equipment entity contains properties and logic that represent the actual physical entities in the plant. Equipment can be owned by other equipment and places. Equipment can contain other equipment, but primarily contain attributes that link plant data.

The initialization of an equipment 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
attributes

A list of ThinkIQ attributes that are children of the Equipment object.

Type:

List[thinkiq.model.Attribute]

Value:

None

Attributes

pgsql_table_schema = 'model'

The schema in the PostgreSQL database where equipment data resides.

pgsql_table_name = 'equipment'

The name of the table in the PostgreSQL database for equipment.

Methods

__init__(**kwargs)

Construct an Equipment object using keyword arguments that will become properties of the returned object.

Constructs an Equipment object and loads its attributes.

_load_attributes()

Load attributes (together with Tag and MeasurementUnit) via a single query and build self.attributes (ChildNodes).

Return type:

None

Loads attribute data (including tag and measurement unit) from the database and attaches it to the Equipment instance.

_set_attributes()

Copy attributes from self.attributes.list to self.<relative_name> for convenience.

Return type:

None

Sets Python-accessible attributes for each model attribute found in the database.

load_node_details(row)

Create a Python attribute for each of the columns returned and optionally load additional information.

Parameters:

row (OrderedDict) – Equipment database table row as a dictionary with keys as column names.

Return type:

None

Placeholder for loading extra details from a database row.

get_attribute(name)

Get the attribute with the relative or display name specified.

Parameters:

name (str) – The relative_name or display_name of the desired attribute.

Return type:

Attribute

Raises:

ValueError – Raised when the name provided is not an attribute contained within the equipment.

Notes

Attempts to find attribute by relative_name first, then display_name.

Examples

Using the Peeler example from initialization, we can now access the get attributes contained by the equipment using the get_attribute method.

>>> speed_sp = peeler_eq.get_attribute('Speed Setpoint')
>>> print(speed_sp.display_name)
Speed Setpoint

Retrieves an attribute by relative or display name.

create_attribute(relative_name, data_type, init=True, **attr_props)

Create an attribute programmatically.

Best practice

This is appropriate for data-science workflows. Use composite equipment for non-essential attributes.

type relative_name:

str

param relative_name:

Attribute name, lowercase with underscores. No special characters; must be a valid Python identifier.

type relative_name:

str

type data_type:

str

param data_type:

Data type of the attribute.

type data_type:

{“float”, “int”, “bool”, “string”}

type init:

bool

param init:

If True (default), creates a tag (necessary for calculations) and initializes a blank ValueStream.

type init:

bool, optional

type attr_props:

Any

param attr_props:

Additional attribute properties as key–value pairs.

  • display_name (optional) – If not provided, it is generated from relative_name by replacing underscores with spaces and title-casing.

  • measurement_unit (optional) – A valid measurement unit name from the model editor; will be resolved to IDs automatically.

All other attribute fields (e.g., description) are supported but optional.

type attr_props:

dict, optional

rtype:

Attribute

returns:
  • Newly created attribute.

  • Errors

  • ——-

  • All errors come from the database schema - see the stack trace message

Programmatically creates an attribute for the equipment in the database.

Examples

Lets work with an example piece of plant equipment, Peeler.

  1. Get by fqn:

Locate the fully qualified name(fqn) of an equipment in ThinkIQ. For example, equipment with the name Peeler may have a fqn of plant_1,site_1,area_1,peeler.

To retrieve the Peeler into an object, pass the fqn as a string to the Equipment class method get_from_fqn.

peeler_eq = Equipment.get_from_fqn('plant_1,site_1,area_1,peeler')

The Equipment class method get_from_fqn can also handle the fqn being passed as a list object.

>>> from thinkiq.model.equipment import Equipment
>>> peeler_eq = Equipment.get_from_fqn(['plant_1', 'site_1', 'area_1', 'peeler'])
>>> print(peeler_eq.display_name)
Peeler

Note

The fqn str or list of strings requires the relative_name of the ThinkIQ object. Display names are not currently supported.

  1. Get by id:

Locate the id of an equipment in ThinkIQ. The Peeler equipment before could have an id of 233.

To retrieve the Peeler into an object, pass the id as an integer to the Equipment class method get_from_id.

>>> from thinkiq.model.equipment import Equipment
>>> peeler_eq = Equipment.get_from_id(233)
>>> print(peeler_eq.display_name)
Peeler
  1. List the equipments attributes

Using the Peeler example from earlier, we can now access the attributes directly using the attributes property.

>>> print(peeler_eq.attributes.list)
[ 'Attribute object, name: Speed Setpoint, id: 456', ... ]