trendminer.sdk.context.view module¶
This module provides user-facing API’s for interacting with Context View.
- class trendminer.sdk.context.view.ContextHubView(name: str, description: str, filters: list[any], view_type: str, folder: Folder | str, identifier: str | None = None, owner: User | str | None = None, last_modified: datetime | str | None = None, grid_settings: dict | None = None, gantt_settings: dict | None = None, scatter_settings: dict | None = None)¶
Bases:
ABC
ContextHub view that can retrieve context items matching its associated context filters.
- name¶
The Contexthub view name
- Type:
str
- description¶
The Contexthub view description
- Type:
str
- filters¶
Any type of Context filters associated with the view. These filters will determine the context items that are retrieved
- Type:
list of any
- view_type¶
Visual representation of the view in Trendminer: “gantt” or “grid”
- Type:
str
- identifier¶
Unique identifier for contexthub view generated by TrendMiner, default None
- Type:
str, optional
- owner¶
The view owners User instance or username generated by TrendMiner, default None
- Type:
User or str, optional
- last_modified¶
View last modified time generated by TrendMiner, default None
- Type:
datetime or str, optional
- grid_settings¶
Configuration of the columns of the table view in json format. Not intended to be edited via the sdk, default None
- Type:
dict, optional
- gantt_settings¶
Configuration of the gantt chart view in json format. Not intended to be edited via the sdk, default None
- Type:
dict, optional
- scatter_settings¶
Settings for the sorting of context items in the table view, in json format. Not intended to be edited via the sdk, default None
- Type:
dict, optional
Note
In the below example values and mode attributes are mutual exclusive for filter description, similarly states and mode attributes for filter states. Provide only one of the parameteried attributes
Example
# Creating a Context View Instance # Example1: from trendminer.sdk.context import ContextOperators context_view = client.context.view( filters=[ client.context.filter.interval(("2019-01-01 12:00:00", "2019-05-31 23:59:00")), client.context.filter.field(field = "context_field", values=["danger"]) client.context.filter.description(values=["extreme high temp", "risky"]), client.context.filter.states(states=['Ended']), client.context.filter.duration(conditions=[{'value': '5h', 'operator': ContextOperators.EQUAL}]), client.context.filter.created_date(condition = {"value" : "2024-01-01 12:00:00", "operator" : ContextDateOperators.GREATER_THAN}) ], name="context_view_name", folder="folder_name", description="view consisting of filters with values" ) # Example2: from trendminer.sdk.context import ContextFilterModes, ContextFilterStatesModes context_view = client.context.view( filters=[ client.context.filter.interval(("2019-01-01 12:00:00", "2019-05-31 23:59:00")), client.context.filter.field(field = "context_field_name", mode=ContextFilterModes.EMPTY), client.context.filter.keywords( mode=ContextFilterModes.NON_EMPTY), client.context.filter.description( mode=ContextFilterModes.NON_EMPTY), client.context.filter.states( mode=ContextFilterStatesModes.CLOSED_ONLY), client.context.filter.components(mode=ContextFilterModes.EMPTY) ], name="context_view_name", folder="folder_name", description="view consisting of filters with modes" ) #Loading a Context View data context_view = client.context.view.get_by_name("context_view_name") items = context_view.search_items() df = pd.DataFrame( [{ **item, "start_date": item.interval.start, "end_date": item.interval.end, "total_duration": item.interval.duration, "type": item.context_type, "last_state": item.events[-1].state, } for item in items] )
- abstract property folder: Folder¶
The folder in which the Contexthub view is saved.
- Returns:
Returns the folder in which Contexthub view is saved
- Return type:
folder
- abstract classmethod is_folder() bool ¶
Validated whether the instance is of type Folder.
- Returns:
True if the object is a folder
- Return type:
bool
- abstract search_items() list[trendminer.sdk.context.item.ContextItem] ¶
Retrieve all context items matching the view filters.
- Returns:
List of ContextItem
- Return type:
list
Example
# Example1: #Search for Context items from user created Contexthub view locally from trendminer.sdk.context import ContextOperators context_view = client.context.view( filters=[ client.context.filter.interval(("2019-01-01 12:00:00", "2019-05-31 23:59:00")), client.context.filter.field(field = "context_field", values=["danger"]) client.context.filter.description(values=["extreme high temp", "risky"]), client.context.filter.states(states=['Ended']), client.context.filter.duration(conditions=[{'value': '5h', 'operator': ContextOperators.EQUAL}]), client.context.filter.created_date(condition = {"value" : "2024-01-01 12:00:00", "operator" : ContextDateOperators.GREATER_THAN}) ] ) context_items = context_view.search_items() # Example2: #Search for Context items using Contexthub view available in Trendminer context_view = client.context.view.get_by_name("context_view_name") items = context_view.search_items()
- class trendminer.sdk.context.view.ContextHubViewAPI¶
Bases:
ABC
ContextHubView APIs for creating and retrieving ContextHub views.
- abstract all() list[trendminer.sdk.context.view.ContextHubView] ¶
Retrieve all Contexthub views.
- Returns:
List of contexthub views
- Return type:
list
Example
context_views = client.context.view.all()
- abstract get(ref: str) ContextHubView ¶
Retrieves a Contexthub view from Trendminer using different retrieval methods, these methods encompass querying by contexthub view using identifier, path and name.
Note
The value of ‘ref’ will be checked with identifier, path, and then name. The first matching result will be returned based on this order
- Parameters:
ref (str) –
Reference by which a unique Contexthub view can be retrieved from Trendminer such as:
identifier
name
path
- Returns:
The contexthub view pointed by the given reference. Returns the provided input directly if it’s the correct type, None, or a LazyAttribute.
- Return type:
Example
# Retrieving contexthub view using name contexthub_view = client.context.view.get("context_view_name") # Retrieving contexthub view using path contexthub_view = client.context.view.get("folder_name/context_view_name") # Retrieving contexthub view using identifier contexthub_view = client.context.view.get("d089511b-3ae1-4796-9859-86f95d85c5a1")
- abstract get_by_identifier(ref: str) ContextHubView ¶
Retrieve a Contexthub view by its identifier.
- Parameters:
ref (str) – ContextHubView unique identifier
- Returns:
The corresponding Contexthub view instance
- Return type:
Example
# Retriving contexthub view by uuid cotext_view = client.context.view.get_by_identifier("d089511b-3ae1-4796-9859-86f95d85c5a1")
- abstract get_by_name(ref: str) ContextHubView ¶
Retrieve a Contexthub view by its name. If there are multiple items with the given name (of the same type), an error is thrown.
- Parameters:
ref (str) – Contexthub view name
- Returns:
The corresponding Contexthub view instance
- Return type:
Example
#can be used to fetch trendhub views, value based search, folder, contexthub views #Retriving contexthub view by name cotext_view = client.view.get_by_name("view_name")
- abstract get_by_path(ref: str) ContextHubView ¶
Retrieve a Context View by its full path in the work organizer structure.
- Parameters:
ref (str) – Contexthub View Path string in work organizer, e.g. my_folder/my_subfolder/my_view
- Returns:
The corresponding Contexthub view instance
- Return type:
Example
# Retriving contexthub view by path cotext_view = client.context.view.get_by_path("context_view_path")
- abstract list(refs: list[str]) list[trendminer.sdk.context.view.ContextHubView] ¶
Retrieves a list of Contexthub view from Trendminer using different retrieval methods, these methods encompass querying by contexthub view identifier, path and name.
Note
The value of ‘ref’ will be checked with identifier, path, and then name. The first matching result will be returned based on this order
- Parameters:
refs (list[str]) –
List of references representing unique instances on Trendminer. References by which a unique context type can be retrieved from Trendminer such as:
identifier
path
name
- Returns:
List of contexthub view retrieved from given references
- Return type:
list
Example
# Retrieving list of contexthub views contexthub_view = client.context.view.list(["context_view_name", "folder_name/context_view2_name", "f029712e-3ae1-4796-9859-86f95d85c5a1"])
- abstract search(*args, **kwargs) list[trendminer.sdk.context.view.ContextHubView] ¶
Search Contexthub view instances by any possible keywords type. Can execute search methods for multiple keywords described below, and return the collection of all results (without duplicates when multiple methods return overlapping instances). The wildcard character (*) can be used for flexible search queries.
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) – Name as referance for the contexthub view
- Returns:
List of contexthub view instances meeting the search criteria
- Return type:
list
Example
# Can be used to search trendhub views # Search is performed using key for contexthub view client.context.view.search(name="contexthub_view_name")