TrendDetectionMixin#
- class TrendDetectionMixin#
Bases:
object
Methods Summary
delete_trenddetection
(project_id, ...)Delete a particular Trend Detection Entity.
get_trenddetection
(project_id, trenddetection_id)Get details for a particular trend detection entity.
get_trenddetection_result
(project_id, ...[, ...])DEPRECATED.
get_trenddetections
(project_id)Get details of all the trend detections on a particular project.
modify_trenddetection
(project_id, ...)Modifies a Trend detection Entity.
new_trenddetection
(project_id, name, query, ...)Create a new trend detection.
Methods Documentation
- delete_trenddetection(project_id, trenddetection_id)#
Delete a particular Trend Detection Entity.
- Parameters:
project_id – Id of the project.
trenddetection_id – Trend detection identifier.
Example:
>>> client.delete_trenddetection( ... project_id='2sic33jZTi-ifflvQAVcfw', ... trenddetection_id='fd5x9NIqQbyBmF4Yph9MMw')
- get_trenddetection(project_id, trenddetection_id, include_trend_detection_entity=None, include_thresholds=None, include_anomalies=None, include_predictions=None, result_before=None, result_after=None)#
Get details for a particular trend detection entity.
- Parameters:
project_id – Id of the project.
trenddetection_id – Trend Detection identifier.
include_trend_detection_entity – Boolean flag to include the trend detection entity parameters in the response. Defaults to True if not specified.
include_thresholds – Boolean flag to include the thresholds corresponding of the trend detection entity in the response. Defaults to False if not specified.
include_anomalies – Boolean flag to include the detected anomalies of the trend detection entity in the response. Defaults to False if not specified.
include_predictions – Boolean flag to include the predictions and the corresponding threholds of the trend detection entity. Defaults to False if not specified.
result_before – A Datetime type string to limit the time series data returned to be strictly before the result_before timestamp. If not specified, defaults to no end date restrictions for the returned data.
result_after – A Datetime type string to limit the time series data returned to be strictly after the result_after timestamp. If not specified, defaults to no start date restrictions for the returned data.
- Returns:
A dictionary with the requested Trend Detection Entity and various data-attributes based on the boolean flags.
Example:
>>> client.get_trenddetection( ... project_id='oFFPR28pTUOkmUF8pZO0cA', ... trenddetection_id='nwBnJ5tkQVGMjKFUBZ1Cbw', ... include_trend_detection_entity=True, ... include_thresholds=False, ... include_anomalies=False, ... include_predictions=False) { 'trend_detection_entity': { u'created_at': u'2016-02-09T08:34:17', u'id': u'nwBnJ5tkQVGMjKFUBZ1Cbw', u'modified_at': u'2016-02-09T08:34:19', u'trends_healthy': True, u'name': u'test name', u'project_id': u'oFFPR28pTUOkmUF8pZO0cA', u'query': u'test_query', u'aggregation_interval': u'1w', u'aggregation_field': u'votes', u'aggregation_method': u'avg', u'aggregation_time_field': u'my_datetime_facet' } }
- get_trenddetection_result(project_id, trenddetection_id, result_before=None, result_after=None, include_thresholds=True, include_anomalies=True, include_historical_data=True, include_trend_detection_entity=True, include_predictions=False)#
DEPRECATED. Please use the get_trenddetection method instead.
Mostly a wrapper around get_trenddetection method to maintain backwards compatibility. Will be deprecated with the next release. Please use the get_trenddetection method. Returns predictions, anomalies, thresholds and the underlying data values of a trend detection entity.
- Parameters:
project_id – Id of the project
trenddetection_id – Id of the trend detection entity
result_before – Timestamp to determine the last time bucket to be fetched for trend-results
result_after – Timestamp to determine the first time bucket to be fetched for trend-results
include_thresholds – Flag to determine whether to include thresholds or not, defaults to True
include_anomalies – Flag to determine whether to include anomalies or not, defaults to True
include_historical_data – Flag to determine whether to include historical data or not, defaults to True
include_trend_detection_entity – Flag to determine whether to include the trend-detection entity or not, defaults to True
include_predictions – Flag to determine whether to include predictions or not, defaults to False
- Returns:
A dict of the trend detection entity, its underlying data values, its calculated threshold, anomalies and predictions.
Example:
>>> client.get_trenddetection_result( ... project_id='2sic33jZTi-ifflvQAVcfw', ... trenddetection_id='fd5x9NIqQbyBmF4Yph9MMw', ... include_predictions=True) { 'thresholds': [ {u'count': 18.709624304, u'timestamp': u'2016-01-25T00:00:00'}, {u'count': 17.6339240561, u'timestamp': u'2016-02-01T00:00:00'}, {u'count': 16.6033921677, u'timestamp': u'2016-02-08T00:00:00'}, {u'count': 17.5181532055, u'timestamp': u'2016-02-15T00:00:00'} ], 'historical_values': { u'values': [ {u'value': 18, u'key': u'2016-01-25T00:00:00'}, {u'value': 5, u'key': u'2016-02-01T00:00:00'}, {u'value': 7, u'key': u'2016-02-08T00:00:00'}, {u'value': 4, u'key': u'2016-02-15T00:00:00'}], u'interval_seconds': 604800.0, u'interval_logical': False}, 'trend_detection_entity': { u'aggregation_time_field': u'$item_created_at', u'aggregation_field': None, u'name': u'test_client', u'created_at': u'2016-05-04T09:03:55', u'modified_at': u'2016-05-04T09:03:58', u'aggregation_interval': u'1w', u'aggregation_method': None, u'query': u'', u'project_id': u'ZjI9KK3zRTaMkYSzUL6Ehw', u'id': u'lsXDwwErQkq7dGKDaRopQQ' }, 'anomalies': [u'2016-01-25T00:00:00'], 'predictions': [ { u'timestamp': u'2016-02-22T00:00:00', u'prediction_value': 8.3735121811, u'prediction_threshold': 11.5988725339 }, { u'timestamp': u'2016-02-29T00:00:00', u'prediction_value': 11.8071893366, u'prediction_threshold': 13.011517576 }, { u'timestamp': u'2016-03-07T00:00:00', u'prediction_value': 6.4798976922, u'prediction_threshold': 11.8167726387 } ] }
- get_trenddetections(project_id)#
Get details of all the trend detections on a particular project.
- Parameters:
project_id – Id of the project.
- Returns:
A dictionary with all the Trend Detection Entities.
Example:
>>> client.get_trenddetections(project_id='2sic33jZTi-ifflvQAVcfw') { u'trend_detection_entities': [ { u'created_at': '2016-02-09T08:34:17', u'id': 'nwBnJ5tkQVGMjKFUBZ1Cbw', u'modified_at': '2016-02-09T08:34:19', u'name': 'test_tde', u'project_id': 'oFFPR28pTUOkmUF8pZO0cA', u'query': '', u'aggregation_interval': u'1w', u'aggregation_field': u'votes', u'aggregation_method': u'avg', u'aggregation_time_field': u'my_datetime_facet' } ] }
- modify_trenddetection(project_id, trenddetection_id, **kwargs)#
Modifies a Trend detection Entity.
- Parameters:
project_id – Id of the project.
trenddetection_id – Id of the trend detection entity.
kwargs – Attributes of the tde to be updated. Update of only name and email_user attributes is supported.
Example:
>>> client.modify_trenddetection( project_id='2sic33jZTi-ifflvQAVcfw', tde_id='F3k1dEJEQzmLRaIlN71AsA', name='test_name', email_user='[email protected]')
- new_trenddetection(project_id, name, query, email_user, aggregation_interval, aggregation_field=None, aggregation_method=None, aggregation_time_field=None)#
Create a new trend detection.
- Parameters:
project_id – Id of the project.
query – Trend Detection query.
name – The name of the new Trend Detection Entity.
email_user – Email address for alert emails.
aggregation_interval –
Time aggregation interval for items. aggregation_interval is {offset}{unit} where offset is a number and unit is one of m (minutes), h (hours), d (days), w (weeks). Examples: 5m for five minutes or 1d for one day.
This parameter defines the discretization level of the time series data for Trend Detection Analysis. As an example, setting this parameter to one week will result in the aggregation of data into one week windows for Trend Detection Analysis.
aggregation_field – A numerical keyword field name to use as the base for trend detection
aggregation_method – An aggregation method. Current options are ‘sum’, ‘avg’, ‘max’ and ‘min’. Defaults to ‘avg’. Only used if aggregation_field is set too.
aggregation_time_field – A datetime keyword field that is used as the timestamp for setting up trend detection instead. Defaults to $item_created_at.
Example:
>>> client.new_trenddetection( project_id='2sic33jZTi-ifflvQAVcfw', query='hello world', name='test name', email_user='[email protected]', aggregation_interval='1w', aggregation_field='votes', aggregation_method='avg', aggregation_time_field='my_datetime_facet' ) { 'trend_detection_entity': { u'id': u'iR81vxDnShu5di4snCu6Jg', u'created_at': u'2016-02-23T16:28:00', u'modified_at': u'2016-02-23T16:28:00', u'name': u'test name', u'project_id': u'2sic33jZTi-ifflvQAVcfw', u'query': u'hello world' u'aggregation_interval': u'1w', u'aggregation_field': u'votes', u'aggregation_method': u'avg', u'aggregation_time_field': u'my_datetime_facet', u'email_user': u'[email protected]', u'last_alert_timestamp': None, u'last_seen_timestamp': None, u'trends_healthy': None } }