Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Uses aggregators to aggregator results from different scorers.""" | |
| 6 | |
| 7 from crash.scorer import aggregators | |
| 8 | |
| 9 | |
| 10 class AggregatedScorer(object): | |
| 11 | |
| 12 def __init__(self, scorers, | |
| 13 score_aggregator=aggregators.Multiplier(), | |
| 14 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.
| |
| 15 changed_files_aggregator=aggregators.ChangedFilesAggregator()): | |
| 16 self.scorers = scorers | |
| 17 self.score_aggregator = score_aggregator | |
| 18 self.reasons_aggregator = reasons_aggregator | |
| 19 self.changed_files_aggregator = changed_files_aggregator | |
| 20 | |
| 21 def Score(self, result, | |
| 22 score_aggregator=None, | |
| 23 reasons_aggregator=None, | |
| 24 changed_files_aggregator=None): | |
| 25 """Aggregates score, reasons and changed_files from all the scorers. | |
| 26 | |
| 27 Note: This method sets confidence, reasons and changed_files of results. | |
| 28 """ | |
| 29 if score_aggregator is None: | |
| 30 score_aggregator = self.score_aggregator | |
| 31 | |
| 32 if reasons_aggregator is None: | |
| 33 reasons_aggregator = self.reasons_aggregator | |
| 34 | |
| 35 if changed_files_aggregator is None: | |
| 36 changed_files_aggregator = self.changed_files_aggregator | |
| 37 | |
| 38 # Transforms array of [(score1, reason1, changed_files1), (score2, reason2, | |
| 39 # changed_files2)] to [(score1, score2), (reason1, reason2), | |
| 40 # (changed_files1, changed_files2)] for aggregators to aggregate. | |
| 41 scores, reasons, changed_files = zip(*[ | |
| 42 scorer(result) for scorer in self.scorers]) | |
| 43 | |
| 44 # Only keep the first 2 digits after decimal point. | |
| 45 result.confidence = score_aggregator(list(scores)) | |
| 46 result.reasons = reasons_aggregator(list(reasons)) | |
| 47 result.changed_files = changed_files_aggregator(list(changed_files)) | |
| 48 | |
| 49 return result.confidence, result.reasons, result.changed_files | |
| OLD | NEW |