trendminer.sdk.tag.tag module

This module provides user-facing API’s for interacting with Tags.

class trendminer.sdk.tag.tag.InterpolationTypeOptions(value)

Bases: Enum

Enum representing interpolation types.

LINEAR = 'LINEAR'

LINEAR: Represents “LINEAR” interpolation type

STEPPED = 'STEPPED'

STEPPED: Represents “STEPPED” interpolation type

STEP_AFTER = 'STEPPED'

STEP_AFTER: Represents “STEPPED” interpolation type

class trendminer.sdk.tag.tag.Tag(identifier: str, name: str, description: str, units: str, tag_type: TagTypeOptions, interpolation_type: InterpolationTypeOptions, states: list[str], color: Color | str, scale: list[float], shift: timedelta, visible: bool)

Bases: ABC

A tag is a named stream of timeseries data used as the basis for all timeseries operations in TrendMiner. Tags are referenced by many other classes and are typically retrieved from the appliance.

name

Tag name, must be unique

Type:

str

description

Provides additional info on the tag

Type:

str

tag_type

Represents type of a tag

Type:

TagTypeOptions Enum

interpolation_type

Interpolation type of tag

Type:

InterpolationTypeOptions Enum

units

Measurement physical units. Can be blank. Units are purely informative, they are not interpreted by the appliance

Type:

str

states

Possible states for a digital or string tag. This data can be heavy to load for string tags, as they can have a very large number of ‘states’. The index of a state in the list is the index that the state has in the appliance. In case a state no longer exists at a given index (i.e., the state of a digital tag has been removed from the historian), None is returned at that position

Type:

list of str

color

Chart display color. If no color is chosen, a random color is selected from a list of distinguishable colors. Supports the standard format of representation defined in color library.for string input provide 3 or 6 hex digit color code. For example, ‘#f0a3ff’ for Amethyst

Type:

Color or str, optional

scale

[min, max] scale on the chart if scale is set, default None

Type:

list of float, optional

shift

Object shift, impacts all data operations, default None

Type:

timedelta, optional

visible

Whether object visible on the chart or hidden, default True

Type:

bool, optional

abstract calculate(intervals: list[trendminer.sdk.commons.interval.Interval], operation: TagCalculationOptions, key: str | None = None, inplace: bool = False, fun: Any | None = None) list[trendminer.sdk.commons.interval.Interval] | None

Perform a calculation on the given tag. A calculation in this context is an aggregation yielding a single value per given interval.

Parameters:
  • intervals (list of Interval) – Intervals on which to perform the aggregation

  • operation (TagCalculationOptions) – Operations to perform on the tag. Calculate operation can be of type TagCalculationOptions

  • key (str, optional) – Key under which the calculation result needs to be stored on the interval. Defaults to the given operation

  • inplace (bool, default False) – When True, no value is returned, but the calculation results are added to the input values under the given key. Otherwise, copies of the intervals are returned on which the calculations results have been added

  • fun (function, optional) – Function to be applied to calculation results, e.g: lambda x: x*24 to correct integral calculation units (from days to hours)

Returns:

Returns intervals when inplace=False, no output if inplace=True

Return type:

list or None

Example

temp=client.tag.get_by_name( "TM-BP2-TEMP.1")

# Add the average temperature
weeks = client.time.interval.range(
start="2019-01-01 00:00:00",
end=client.time.now(),
freq="W-MON")

weeks_w_temp = temp.calculate(intervals=weeks, operation=TagCalculationOptions.MEAN, key="temp")
abstract get_data(interval: Interval | tuple[str, str] | str, resolution: str) Series

Retrieve time series data for the tag.

Parameters:
  • interval (Interval or tuple or str) – Interval for which the data needs to be retrieved

  • resolution (str) – Setting the resolution is more natural when requesting interpolated data. For example: resolution=60 results in 1 point every minute for interpolated data, while it would request 1 interval per minute for chart/index data

Return type:

Series

Example

# Fetching interpolated data from tag
tag = client.tag.get("custom_tag")
interval = ("2019-03-25", "2019-03-26")
data = tag.get_data(interval, resolution="1m")
abstract get_index_data(interval: Interval | tuple[str, str] | str) Series

Retrieve time series index data for the tag.

Parameters:

interval (Interval or tuple or str) – Interval for which the data needs to be retrieved

Example

# Fetching index data from tag
tag = client.tag.get("custom_tag")
interval = ("2019-03-25", "2019-03-26")
data = tag.get_index_data(interval)
Return type:

Series

abstract get_plot_data(interval: Interval | tuple[str, str] | str, n_intervals: int) Series

Retrieve time series chart data for the tag.

Parameters:
  • interval (Interval or tuple or str) – Interval for which the data needs to be retrieved

  • n_intervals (int) – Splits the interval in this number of sub-intervals for which to retrieve data. Every sub-interval will contain up to 4 points: min, max, start and end datapoints from the interval

Note

The sub-interval can return less points if the key points overlap (e.g. start value is also the min value), or there could even be no real datapoints stored in a given subinterval. When requesting interpolated data, 1 point is returned per interval

Return type:

Series

Example

# Fetching plot data from tag
tag = client.tag.get("custom_tag")

interval = ("2019-03-25", "2019-03-26")
data = tag.get_plot_data(interval, n_intervals=300)
abstract isnumeric() bool

Check if tag is numeric.

Returns:

Whether the tag is numeric (i.e., ANALOG or DISCRETE)

Return type:

bool

class trendminer.sdk.tag.tag.TagAPI

Bases: ABC

API class for retrieving Tags.

abstract all(datasources=None) list[trendminer.sdk.tag.tag.Tag]

Retrieve all tags

Parameters:

datasources (list, optional) – List of datasources to which to limit retrieval. By default, tags are retrieved from all accessible datasources

Returns:

List of all Tag in the given datasources

Return type:

list

Example

client.tag.all()
abstract get(ref: str) Tag

Retrieves a tag instance from the appliance using different retrieval methods. These methods encompass querying by identifier, name or attribute.

Note

The value of ‘ref’ will be checked with identifier, name or attribute. The first matching result will be returned based on this order

Parameters:

ref (Any) –

Reference by which a unique instance can be retrieved from the appliance such as:

  • identifier

  • name

  • attribute

Returns:

The instance pointed by the given reference

Return type:

Tag

Example

# Retriving tag from it's identifier
client.tag.get("497a6f1f-b8a0-49a5-b14c-89e088815fae")
abstract get_by_attribute(ref: str) Tag

Retrieve tag from an attribute. An attribute maps to a single tag.

Parameters:

ref (Attribute or str) – Attribute or reference to an Attribute

Returns:

Retrieved tag

Return type:

Tag

Example

# Retriving tag from an attribute
tag_attribute=client.tag.get_by_attribute("attribute")
abstract get_by_identifier(ref: str) Tag

Retrieve tag from its universally unique identifier (uuid).

Parameters:

ref (str) – Tag uuid

Returns:

Retrieved tag

Return type:

Tag

Example

# Retriving tag by uuid
tag_identifier=client.tag.get_by_identifier("497a6f1f-b8a0-49a5-b14c-89e088815fae")
abstract get_by_name(ref: str) Tag

Retrieve tag from its name.

Parameters:

ref (str) – Tag name

Returns:

Retrieved tag

Return type:

Tag

Example

# Retriving tag by using name
tag_name=client.tag.get_by_name("custom_tag")
abstract list(refs: list) list[trendminer.sdk.tag.tag.Tag]

Retrieves a list of instances from the appliance using different retrieval methods, these methods encompass querying by identifier, name or attribute.

Note

Each value of input list will be checked with identifier, name and then attribute. The first matching result will be returned based on this order

Parameters:

refs (list[Any]) –

List of references representing unique instances on the appliance. Reference by which a unique instance can be retrieved from the appliance such as:

  • identifier

  • name

  • attribute

Returns:

List of Tag instances retrieved from given references

Return type:

list

Example

# Retriving tags
client.tag.list(['MyTagName112', 'MyTagName'])
abstract search(*args, **kwargs) list[trendminer.sdk.tag.tag.Tag]

Search instances using various search keywords. It executes search methods based on the provided keywords and returns a collection of unique results. Duplicate instances are filtered out when multiple methods return overlapping instances.

Note

Atleast one of the below mentioned Keyword Arguments should be provided. Otherwise, an empty list will be returned. If multiple keywords are provided, they will be combined using an AND operation.

Keyword Arguments:
  • name (str (optional)) – Name as referance for the tag

  • description (str (optional)) – Full description of description substring

  • rsql (str (optional)) – RSQL query, e.g. “name==my_tag”

Returns:

List of instances meeting the search criteria

Return type:

list

Example

# Search is performed using name for multiple tags
client.tag.search(name="TM-BP2*.1")

# Search is performed using description
client.tag.search(description="my_custom_tag")
class trendminer.sdk.tag.tag.TagCalculationOptions(value)

Bases: Enum

Enum representing Tag Calculation options.

DELTA = 'delta'

DELTA: Represents “DELTA” operations for calculations

END = 'endValue'

END: Represents “END” operations for calculations

INTEGRAL = 'integral'

INTEGRAL: Represents “INTEGRAL” operations for calculations

MAXIMUM = 'max'

MAXIMUM: Represents “MAX” operations for calculations

MEAN = 'mean'

MEAN: Represents “MEAN” operations for calculations

MINIMUM = 'min'

MINIMUM: Represents “MIN” operations for calculations

RANGE = 'range'

RANGE: Represents “RANGE” operations for calculations

START = 'startValue'

START: Represents “START” operations for calculations

STDEV = 'stdev'

STDEV: Represents “STDEV” operations for calculations

class trendminer.sdk.tag.tag.TagTypeOptions(value)

Bases: Enum

Enum representing Tag Type Options.

ANALOG = 'ANALOG'

ANALOG: Represents “ANALOG” tag type

DIGITAL = 'DIGITAL'

DIGITAL: Represents “DIGITAL” tag type

DISCRETE = 'DISCRETE'

DISCRETE: Represents “DISCRETE” tag type

STRING = 'STRING'

STRING: Represents “STRING” asset options