| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from collections import defaultdict | 5 from collections import defaultdict |
| 6 import logging | 6 import logging |
| 7 import math | |
| 8 | 7 |
| 9 from common.chrome_dependency_fetcher import ChromeDependencyFetcher | 8 from common.chrome_dependency_fetcher import ChromeDependencyFetcher |
| 10 from crash import changelist_classifier | 9 from crash import changelist_classifier |
| 10 from crash.changelist_classifier import StackInfo |
| 11 from crash.crash_report_with_dependencies import CrashReportWithDependencies | 11 from crash.crash_report_with_dependencies import CrashReportWithDependencies |
| 12 from crash.loglinear.changelist_features.min_distance import MinDistanceFeature | |
| 13 from crash.loglinear.changelist_features.top_frame_index import ( | |
| 14 TopFrameIndexFeature) | |
| 15 from crash.loglinear.feature import WrapperMetaFeature | |
| 16 from crash.loglinear.model import UnnormalizedLogLinearModel | 12 from crash.loglinear.model import UnnormalizedLogLinearModel |
| 17 from crash.stacktrace import CallStack | |
| 18 from crash.stacktrace import Stacktrace | |
| 19 from crash.suspect import StackInfo | |
| 20 | 13 |
| 21 | 14 |
| 22 class LogLinearChangelistClassifier(object): | 15 class LogLinearChangelistClassifier(object): |
| 23 """A ``LogLinearModel``-based implementation of CL classification.""" | 16 """A ``LogLinearModel``-based implementation of CL classification.""" |
| 24 | 17 |
| 25 def __init__(self, get_repository, meta_feature, meta_weight, | 18 def __init__(self, get_repository, meta_feature, meta_weight, |
| 26 top_n_frames=7, top_n_suspects=3): | 19 top_n_frames=7, top_n_suspects=3): |
| 27 """Args: | 20 """ |
| 21 Args: |
| 28 get_repository (callable): a function from DEP urls to ``Repository`` | 22 get_repository (callable): a function from DEP urls to ``Repository`` |
| 29 objects, so we can get changelogs and blame for each dep. Notably, | 23 objects, so we can get changelogs and blame for each dep. Notably, |
| 30 to keep the code here generic, we make no assumptions about | 24 to keep the code here generic, we make no assumptions about |
| 31 which subclass of ``Repository`` this function returns. Thus, | 25 which subclass of ``Repository`` this function returns. Thus, |
| 32 it is up to the caller to decide what class to return and handle | 26 it is up to the caller to decide what class to return and handle |
| 33 any other arguments that class may require (e.g., an http client | 27 any other arguments that class may require (e.g., an http client |
| 34 for ``GitilesRepository``). | 28 for ``GitilesRepository``). |
| 35 meta_feature (MetaFeature): All features. | 29 meta_feature (MetaFeature): All features. |
| 36 meta_weight (MetaWeight): All weights. the weights for the features. | 30 meta_weight (MetaWeight): All weights. the weights for the features. |
| 37 The keys of the dictionary are the names of the feature that weight is | 31 The keys of the dictionary are the names of the feature that weight is |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 suspect.confidence = score | 133 suspect.confidence = score |
| 140 # features is ``MetaFeatureValue`` object containing all feature values. | 134 # features is ``MetaFeatureValue`` object containing all feature values. |
| 141 features = features_given_report(suspect) | 135 features = features_given_report(suspect) |
| 142 suspect.reasons = features.reason | 136 suspect.reasons = features.reason |
| 143 suspect.changed_files = [changed_file.ToDict() | 137 suspect.changed_files = [changed_file.ToDict() |
| 144 for changed_file in features.changed_files] | 138 for changed_file in features.changed_files] |
| 145 scored_suspects.append(suspect) | 139 scored_suspects.append(suspect) |
| 146 | 140 |
| 147 scored_suspects.sort(key=lambda suspect: suspect.confidence) | 141 scored_suspects.sort(key=lambda suspect: suspect.confidence) |
| 148 return scored_suspects[:self._top_n_suspects] | 142 return scored_suspects[:self._top_n_suspects] |
| OLD | NEW |