def _GetTopProject(projects, rank_function=None): """Gets the highest ranking class among projects.""" projects = RankByOccurrence(projects, 1, rank_function=rank_function) if projects: return projects[0] logging.warning('ProjectClassifier.Classify: no projects found.') return None
def Classify(self, results, crash_stack): top_n_frames = 4 if results: classes = map(self.GetClassFromSuspect, results[:top_n_frames]) else: classes = map(self.GetClassFromStackFrame, crash_stack.frames[:top_n_frames]) class_list = RankByOccurrence(classes, 1) if class_list: return class_list[0] return ''
def ClassifyCallStack(self, stack, top_n_components=2): """Classifies component of a crash. Args: stack (CallStack): The callstack that caused the crash. top_n_components (int): The number of top components for the stack, defaults to 2. Returns: List of top n components. """ components = map(self.ClassifyStackFrame, stack.frames[:self.top_n_frames]) return RankByOccurrence(components, top_n_components)
def ClassifySuspects(self, suspects, top_n_components=2): """Classifies component of a list of suspects. Args: suspects (list of Suspect): Culprit suspects. top_n_components (int): The number of top components for the stack, defaults to 2. Returns: List of top 2 components. """ components = [] for suspect in suspects: components.extend(self.ClassifySuspect(suspect)) return RankByOccurrence(components, top_n_components, rank_function=lambda x: -len(x))
def ClassifySuspect(self, suspect, top_n_components=2): """ Classifies components of a suspect. Args: suspect (Suspect): a change log top_n_components (int): number of components assigned to this suspect, defaults to 2. Returns: List of components """ if not suspect or not suspect.changelog: return None classify_touched_file_func = functools.partial(self.ClassifyTouchedFile, suspect.dep_path) components = map(classify_touched_file_func, suspect.changelog.touched_files) return RankByOccurrence(components, top_n_components, rank_function=lambda x: -len(x))