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

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