trendminer.sdk.context.item module¶
This module provides user-facing API’s for interacting with Context Item.
- class trendminer.sdk.context.item.ContextItem(key: str, context_type: ContextType | str, components: list[Union[trendminer.sdk.tag.tag.Tag, trendminer.sdk.asset.asset.Asset, trendminer.sdk.asset.asset.Attribute, str]], description: str, fields: dict | None = None, identifier: str | None = None, created_by: User | None = None, search_fields: dict | None = None, sync_time: datetime | None = None)¶
Bases:
ABC
Context item containing contextual information.
- key¶
Context item unique short-key
- Type:
str
- context_type¶
Context type of the context item
- Type:
ContextType or str
- components¶
Components (tags, assets, attributes) to which the context item is attached. Adding more than a single component is not recommended. The input list may contain reference to the following item
tag : tag identifier or tag name
asset : asset identifier, asset path or asset hex path
- fields¶
Context item data fields, default None
- Type:
dict, optional
- description¶
Context item description
- Type:
str
- identifier¶
Context item uuid generated by TrendMiner, default None
- Type:
str, optional
- search_fields¶
Metadata from when the context item was created from a monitor, default None Contains the keys ‘tm_monitor_id’,’tm_search_id’ and ‘tm_search_type’
- Type:
dict, optional
- sync_time¶
Time the context item was synced to Trendminer, default None
- Type:
datetime, optional
Note
Each reference passed in componenets will be checked in the order tag identifier, tag name, asset identifier,asset path,asset hex path. The first matching result in the order mentioned will be retrieved
- abstract approve() None ¶
Add user approval to this context item. Approval functionality in context item types should be enabled in order to approve a user.
Example
# Approve a context item context_item = client.context.item.get_by_identifier('7fee6b2a-a3c9-4f0d-8b90-c6941ad52ae0') context_item.approve()
- abstract property events: list[trendminer.sdk.context.item.Event]¶
Contex item events.
- Returns:
Context item events corresponding to the context type workflow
- Return type:
list
- abstract history() dict ¶
Return context item history. Keeping history must be configured for the context item in Trendminer. History should be turned on in context item types configuration, in order to retrieve the context item history.
- Returns:
Context item history
- Return type:
dict
Example
# Retriving context item by uuid context_item = client.context.item.get_by_identifier('7fee6b2a-a3c9-4f0d-8b90-c6941ad52ae0') context_item.history(context_item)
- abstract property interval: Interval¶
Time interval covered by the context item
The interval is determined by the start and end event. If the end event has not occurred yet the end of the interval will be the current time. If there is no workflow associated with the context type, the context item only has a single timestamp, so the length of the returned interval is 0.
- Returns:
The time interval covered by the context item
- Return type:
- abstract remove_approval() None ¶
Remove user approval from this context item. Approval functionality in context item types should be enabled in order to remove approval of a user.
Example
# Remove approval of a context item context_item = client.context.item.get_by_identifier('7fee6b2a-a3c9-4f0d-8b90-c6941ad52ae0') context_item.remove_approval(context_item)
- class trendminer.sdk.context.item.ContextItemAPI¶
Bases:
ABC
ContextItemAPI class for creating and retrieving context items.
- abstract get(ref: str) ContextItem ¶
Retrieves a context item from Trendminer using different retrieval methods, these methods encompass querying by context item identifier.
- Parameters:
ref (str) – Context item identifier
- Returns:
The context item pointed by the given reference. Returns the provided input directly if it’s the correct type, None, or a LazyAttribute
- Return type:
Example
# Retrieving context item using identifier context_item = client.context.type.get('7fee6b2a-a3c9-4f0d-8b90-c6941ad52ae0')
- abstract get_by_identifier(ref: str) ContextItem ¶
Retrieve a context item by its identifier.
- Parameters:
ref (str) – Context item identifier
- Returns:
The corresponding context item
- Return type:
Example
# Retriving context item by uuid client.context.item.get_by_identifier('7fee6b2a-a3c9-4f0d-8b90-c6941ad52ae0')
- abstract list(refs: list[str]) list[trendminer.sdk.context.item.ContextItem] ¶
Retrieves a list of context item from Trendminer using different retrieval methods, these methods encompass querying by context item identifier.
- Parameters:
refs (list[str]) –
Trendminer (List of context item identifiers representing unique instances on) –
- Returns:
List of context items retrieved from given references
- Return type:
list
Example
# Retrieving list of context items context_items = client.context.item.list(['7fee6b2a-a3c9-4f0d-8b90-c6941ad52ae0', '6a612ae0-d589-4690-9926-05c08567c160'])
- class trendminer.sdk.context.item.Event(state: str, timestamp: datetime, identifier: str | None = None)¶
Bases:
ABC
A context item event
An event is defined by a timestamp and a state. A context item event is assigned a unique identifier (uuid) by TrendMiner.
- state¶
The context event state
- Type:
str
- timestamp¶
The event timestamp
- Type:
datetime
- identifier¶
Unique identifier for an event generated by TrendMiner, default None
- Type:
str, optional