trendminer.sdk.search.search module

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

class trendminer.sdk.search.search.LogicalOperators(value)

Bases: Enum

Enum representing Join Operators for multiple queries.

AND = 'AND'

AND: Represents “AND” join operator

OR = 'OR'

OR: Represents “OR” join operator

class trendminer.sdk.search.search.SearchAPI

Bases: ABC

A class that provides user-friendly functions for interacting with all search types.

abstract all() list[trendminer.sdk.search.search.ValueBasedSearch]

Retrieve all instances of search types from the appliance.

Returns:

List of all instances retrieved from the appliance (includes all search types)

Return type:

list

Example

# Retrive all the instance of search
client.search.all()
abstract get_by_identifier(ref: str) ValueBasedSearch

Load a search (Value Based) instance directly from its unique identifier.

Parameters:

ref (str) – Unique identifier to the search object on the appliance

Returns:

The appliance search object with the given unique identifier

Return type:

ValueBasedSearch

Example

# Retriving value based search from an uuid
client.search.get_by_identifier('69e7aca4-b07f-475a-8fcf-0e3dc16adfbc')
abstract get_by_name(ref: str) ValueBasedSearch

Retrieve a search (Value Based) instance directly from its name.

Parameters:

ref (str) – Search query

Returns:

Returns value based search

Return type:

ValueBasedSearch

Example

# Retriving value based search from a name
client.search.get_by_name('sdk_vbs_tmp2')
abstract get_by_path(ref: str) ValueBasedSearch

Retrieve search object by its full path.

Parameters:

ref (str) – Path string, e.g. my_folder/my_subfolder/my_object

Returns:

Returns value based search

Return type:

ValueBasedSearch

Example

# Retriving value based search by it's path
client.search.get_by_path('sdk/sdk_vbs_tmp2')
abstract property value: ValueBasedSearchAPI

API class for value-based searches.

Return type:

ValueBasedSearchAPI

class trendminer.sdk.search.search.SearchCalculation(tag: Tag, operation: SearchCalculationOptions, key: str | None = None, units: str | None = None)

Bases: ABC

Calculation on search results.

operation

Operations to perform on the Search Calculations operation can be of type SearchCalculationOptions

Type:

SearchCalculationOptions

key

Calculation reference key

Type:

str

tag

The tag for which we are doing calculation search

Type:

Tag

units

Calculation units

Type:

str, optional

class trendminer.sdk.search.search.SearchCalculationOptions(value)

Bases: Enum

Enum representing Search Calculation Options.

DELTA = 'DELTA'

DELTA: Represents “DELTA” operations for calculations

END = 'END'

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 = 'START'

START: Represents “START” operations for calculations

STDEV = 'STDEV'

STDEV: Represents “STDEV” operations for calculations

class trendminer.sdk.search.search.SearchQuery(tag: Tag, condition: ValueBasedSearchOperators, value: str | float | int)

Bases: ABC

Query on value based search.

tag

The tag we are searching

Type:

Tag

condition

Operators to use for condition can be of type ValueBasedSearchOperators

Type:

ValueBasedSearchOperators

values

value to assign for the tag

Type:

str or float or int

abstract property values: list[float] | list[str] | list[int]

Checks if value provided tag.is_numeric is present, then converts it into list of float and returns. If not, then checks if the value belongs to Tags.states and returns it after validating it in list format.

Returns:

list of values

Return type:

list

abstract property values_numeric: list[float]

Checks if value provided tag.is_numeric. If yes, then converts it into list of float and returns. If not, then returns the value.

Returns:

List of values

Return type:

list

class trendminer.sdk.search.search.ValueBasedSearch(queries: list[trendminer.sdk.search.search.SearchQuery], duration: timedelta | str, identifier: str | None = None, identifier_complex: str | None = None, name: str | None = None, description: str | None = None, folder: Folder | str | None = None, owner: User | str | None = None, last_modified: datetime | None = None, calculations: list[trendminer.sdk.search.search.SearchCalculation] | None = None, operator: LogicalOperators | None = None)

Bases: ABC

The value based search feature empowers to define numerical values or states for one or multiple process parameters. This functionality facilitates the swift identification of periods aligning with your specified search criteria.

identifier

Unique identifier to the object on the appliance

Type:

str, optional

identifier_complex

UUID that is used for retrieving a monitor

Type:

str, optional

name

Name of the search

Type:

str, optional

description

Description of the search

Type:

str, optional

folder

Folder to save the search in

Type:

Folder or str, optional

owner

The user that owns the object

Type:

User or str, optional

last_modified

The date at which the object was last modified

Type:

datetime, optional

queries

Value search queries. List of queries can be of tuples. Query can contain operator of type ValueBasedSearchOperators

Type:

list of SearchQuery

calculations

Calculations to perform on the search Calculation operation can be of type SearchCalculationOptions

Type:

SearchCalculationOptions, optional

duration

time duration needs to be defined for the search

Type:

timdelta or str

operator

The joining operator type when more than one query is provided by the user

Type:

LogicalOperators, optional

Example

# Example 1
# Simple Value Based Search Operation
from trendminer.sdk.search import ValueBasedSearchOperators,LogicalOperators, SearchCalculationOptions

level = client.tag.get_by_name("TM-BP2-LEVEL.1")
vbs = client.search.value(queries=[
    (level, ValueBasedSearchOperators.GREATER_THAN, 35),
    ("TM-BP2-PRODUCT.1",ValueBasedSearchOperators.EQUAL_TO ,"ALPHA"),
],
operator=LogicalOperators.AND,
duration="2m"
)

#Example 2:
digital_tag = "TM-GRA-TI2030"
level = client.tag.get_by_name(digital_tag)
calculations = {
        "Max": ("TM-GRA-product", SearchCalculationOptions.MAXIMUM,'m3/h'),
        "Avg": ("TM-GRA-product", SearchCalculationOptions.MEAN),
}

vbs = client.search.value(queries=[
                                    (level, ValueBasedSearchOperators.CONSTANT),
                                ],
                            duration="120s",
                            calculations=calculations
                            )
abstract get_results(interval: Interval | tuple[str, str] | str = '6M', excluded_intervals: Interval | tuple[str, str] | str | None = None) list[trendminer.sdk.commons.interval.Interval]

Executes search and extracts results.

Parameters:
  • interval (Interval or str or tuple, default '6M') – Interval to search in

  • excluded_intervals (Interval or str or tuple, optional) – Intervals to filter out while searching

Returns:

Search results, including calculations and potentially similarity score (interval[“score”]). Sorted always from oldest to newest

Return type:

list

Example

# Example 1
# Simple Value Based Search Operation
from trendminer.sdk.search import ValueBasedSearchOperators,LogicalOperators,SearchCalculationOptions

level = client.tag.get_by_name("TM-BP2-LEVEL.1")
vbs = client.search.value(queries=[
    (level, ValueBasedSearchOperators.GREATER_THAN, 35),
    ("TM-BP2-PRODUCT.1",ValueBasedSearchOperators.EQUAL_TO ,"ALPHA"),
],
operator=LogicalOperators.AND,
duration="2m"
)

results = vbs.get_results(("2019-01-20", "2019-01-29"))

#Example 2:
digital_tag = "TM-GRA-TI2030"
level = client.tag.get_by_name(digital_tag)
calculations = {
        "Max": ("TM-GRA-product", SearchCalculationOptions.MAXIMUM,'m3/h'),
        "Avg": ("TM-GRA-product", SearchCalculationOptions.MEAN),
}

vbs = client.search.value(queries=[
                                    (level, ValueBasedSearchOperators.CONSTANT),
                                ],
                            duration="120s",
                            calculations=calculations
                            )
results = client.search.value.get_results(vbs,("2018-01-01", "2018-08-01"))
class trendminer.sdk.search.search.ValueBasedSearchAPI

Bases: ABC

ValueBasedSearch API’s for creating and retrieving ValueBasedSearch objects.

abstract all() list[trendminer.sdk.search.search.ValueBasedSearch]

Retrieve all Value based Search objects.

Returns:

List of Value based Search object.

Return type:

list

Example

# for value based search
client.search.value.all()
abstract get(ref: str) ValueBasedSearch

Retrieves Value based Search object instance from the appliance using different retrieval methods. These methods encompass querying by identifier, path or name.

Note

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

Parameters:

ref (str) –

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

  • identifier

  • path

  • name

Returns:

The Value based Search object instance pointed to by the given reference

Return type:

ValueBasedSearch

Example

# Retriving Value based search object from it's identifier
client.search.value.get("497a6f1f-b8a0-49a5-b14c-89e088815fae")
abstract get_by_identifier(ref: str) ValueBasedSearch

Load a Value based Search object instance directly from its unique identifier.

Parameters:

ref (str) – Unique identifier to the object on the appliance

Returns:

The Value based Search object with the given unique identifier

Return type:

ValueBasedSearch

Example

#can be used to fetch value based searches using UUID
client.search.value.get_by_identifier("497a6f1f-b8a0-49a5-b14c-89e088815fae")
abstract get_by_name(ref: str) ValueBasedSearch

Retrieve Value based Search object by its name. If there are multiple items with the given name (of the same type), an error is thrown.

Parameters:

ref (str) – Value based search object name

Returns:

Value based search object with matching name

Return type:

ValueBasedSearch

Example

# for value based search
client.search.value.get_by_name("vbs_name")
abstract get_by_path(ref: str) ValueBasedSearch

Retrieve Value based Search object by its full path.

Parameters:

ref (str) – Path string, e.g. my_folder/my_subfolder/my_object

Returns:

The Value based Search object

Return type:

ValueBasedSearch

Example

client.search.value.get_by_path("tm/my_subfolder/vbs_obj")
abstract list(refs: list) list[trendminer.sdk.search.search.ValueBasedSearch]

Retrieves list of Value based Search object instances from the appliance using different retrieval methods, these methods encompass querying by identifier, path or name.

Note

Each value of input list will be checked with identifier, path and then name. 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

  • path

  • name

Returns:

List of Value based search objects retrieved from given references

Return type:

list

Example

# Retriving VBS
client.search.value.list(['MyVBSName112', 'MyVBSName'])
abstract search(*args, **kwargs) list[trendminer.sdk.search.search.ValueBasedSearch]

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 value based search

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

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

Returns:

List of Value based Search object instances meeting the search criteria

Return type:

list

Example

# for searching value based search
client.search.value.search(name="*")
class trendminer.sdk.search.search.ValueBasedSearchOperators(value)

Bases: Enum

Enum representing Value Based Search Operators.

CONSTANT = 'Constant'

CONSTANT: Represents “CONSTANT” operator for value based search

EQUAL_TO = '='

EQUAL_TO: Represents “=” operator for value based search

GREATER_THAN = '>'

GREATER_THAN: Represents “>” operator for value based search

GREATER_THAN_EQUAL_TO = '>='

GREATER_THAN_EQUAL_TO: Represents “>=” operator for value based search

IN_SET = 'In set'

IN_SET: Represents “IN_SET” operator for value based search

LESS_THAN = '<'

LESS_THAN: Represents “<” operator for value based search

LESS_THAN_EQUAL_TO = '<='

LESS_THAN_EQUAL_TO: Represents “<=” operator for value based search

NOT_EQUAL_TO = '!='

NOT_EQUAL_TO: Represents “!=” operator for value based search