def _analyze_root_causes(self): """ Conduct root cause analysis. The first metric of the list is taken as the root cause right now. """ causes = {} for a in self.anomalies: try: causes[a] = self.correlations[a][0] except IndexError: raise exceptions.InvalidDataFormat('luminol.luminol: dict correlations contains empty list.') self.causes = causes
def read_csv(csv_name): """ Read data from a csv file into a dictionary. :param str csv_name: path to a csv file. :return dict: a dictionary represents the data in file. """ data = {} if not isinstance(csv_name, (str, unicode)): raise exceptions.InvalidDataFormat('luminol.utils: csv_name has to be a string!') with open(csv_name, 'r') as csv_data: reader = csv.reader(csv_data, delimiter=',', quotechar='|') for row in reader: try: key = to_epoch(row[0]) value = float(row[1]) data[key] = value except ValueError: pass return data
def _get_algorithm_and_params(self, algorithm_name, algorithm_params): """ Get the specific algorithm and merge the algorithm params. :param str algorithm: name of the algorithm to use. :param dict algorithm_params: additional params for the specific algorithm. """ algorithm_name = algorithm_name or CORRELATOR_ALGORITHM try: self.algorithm = correlator_algorithms[algorithm_name] except KeyError: raise exceptions.AlgorithmNotFound('luminol.Correlator: ' + str(algorithm_name) + ' not found.') # Merge parameters. if algorithm_params: if not isinstance(algorithm_params, dict): raise exceptions.InvalidDataFormat( 'luminol.Correlator: algorithm_params passed is not a dictionary.' ) else: self.algorithm_params = dict(algorithm_params.items() + self.algorithm_params.items())