Chromium Code Reviews| Index: appengine/findit/crash/scorers/aggregated_scorer.py |
| diff --git a/appengine/findit/crash/scorers/aggregated_scorer.py b/appengine/findit/crash/scorers/aggregated_scorer.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b49c974971934c123f4b01f008b0712cb81e283e |
| --- /dev/null |
| +++ b/appengine/findit/crash/scorers/aggregated_scorer.py |
| @@ -0,0 +1,49 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Uses aggregators to aggregator results from different scorers.""" |
| + |
| +from crash.scorer import aggregators |
| + |
| + |
| +class AggregatedScorer(object): |
| + |
| + def __init__(self, scorers, |
| + score_aggregator=aggregators.Multiplier(), |
| + reasons_aggregator=aggregators.IdentityAggregator(), |
|
stgao
2016/07/15 23:25:28
Can we move this default value to function ``Score
Sharu Jiang
2016/07/18 00:31:58
Done.
|
| + changed_files_aggregator=aggregators.ChangedFilesAggregator()): |
| + self.scorers = scorers |
| + self.score_aggregator = score_aggregator |
| + self.reasons_aggregator = reasons_aggregator |
| + self.changed_files_aggregator = changed_files_aggregator |
| + |
| + def Score(self, result, |
| + score_aggregator=None, |
| + reasons_aggregator=None, |
| + changed_files_aggregator=None): |
| + """Aggregates score, reasons and changed_files from all the scorers. |
| + |
| + Note: This method sets confidence, reasons and changed_files of results. |
| + """ |
| + if score_aggregator is None: |
| + score_aggregator = self.score_aggregator |
| + |
| + if reasons_aggregator is None: |
| + reasons_aggregator = self.reasons_aggregator |
| + |
| + if changed_files_aggregator is None: |
| + changed_files_aggregator = self.changed_files_aggregator |
| + |
| + # Transforms array of [(score1, reason1, changed_files1), (score2, reason2, |
| + # changed_files2)] to [(score1, score2), (reason1, reason2), |
| + # (changed_files1, changed_files2)] for aggregators to aggregate. |
| + scores, reasons, changed_files = zip(*[ |
| + scorer(result) for scorer in self.scorers]) |
| + |
| + # Only keep the first 2 digits after decimal point. |
| + result.confidence = score_aggregator(list(scores)) |
| + result.reasons = reasons_aggregator(list(reasons)) |
| + result.changed_files = changed_files_aggregator(list(changed_files)) |
| + |
| + return result.confidence, result.reasons, result.changed_files |