#NEWLINE# def run_selected_algorithm( timeseries , metric_name ) : #NEWLINE# #INDENT# '\n    Filter timeseries and run selected algorithm.\n    ' #NEWLINE# if ( len ( timeseries ) < MIN_TOLERABLE_LENGTH ) : #NEWLINE# #INDENT# raise TooShort ( ) #NEWLINE# #UNINDENT# if ( ( time ( ) - timeseries [ ( - 1 ) ] [ 0 ] ) > STALE_PERIOD ) : #NEWLINE# #INDENT# raise Stale ( ) #NEWLINE# #UNINDENT# if ( len ( set ( ( item [ 1 ] for item in timeseries [ ( - MAX_TOLERABLE_BOREDOM ) : ] ) ) ) == BOREDOM_SET_SIZE ) : #NEWLINE# #INDENT# raise Boring ( ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ensemble = [ globals ( ) [ algorithm ] ( timeseries ) for algorithm in ALGORITHMS ] #NEWLINE# threshold = ( len ( ensemble ) - CONSENSUS ) #NEWLINE# if ( ensemble . count ( False ) <= threshold ) : #NEWLINE# #INDENT# if ENABLE_SECOND_ORDER : #NEWLINE# #INDENT# if is_anomalously_anomalous ( metric_name , ensemble , timeseries [ ( - 1 ) ] [ 1 ] ) : #NEWLINE# #INDENT# return ( True , ensemble , timeseries [ ( - 1 ) ] [ 1 ] ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return ( True , ensemble , timeseries [ ( - 1 ) ] [ 1 ] ) #NEWLINE# #UNINDENT# #UNINDENT# return ( False , ensemble , timeseries [ ( - 1 ) ] [ 1 ] ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logging . error ( ( 'Algorithm error: ' + traceback . format_exc ( ) ) ) #NEWLINE# return ( False , [ ] , 1 )