| 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 """Interface of scorers to score and reason Result. | 5 """Interface of scorers to score and reason Result. |
| 6 | 6 |
| 7 A Scorer represents a heuristic rule to score a culprit cl result. | 7 A Scorer represents a heuristic rule to score a culprit cl result. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import logging | 10 import logging |
| 11 | 11 |
| 12 | 12 |
| 13 class Scorer(object): # pragma: no cover. | 13 class Scorer(object): # pragma: no cover. |
| 14 | 14 |
| 15 def GetMetric(self, result): | 15 def GetMetric(self, result): |
| 16 raise NotImplementedError() | 16 raise NotImplementedError() |
| 17 | 17 |
| 18 def Score(self, metric): | 18 def Score(self, metric): |
| 19 """Score the result based on extracted metric.""" | 19 """Scores the result based on extracted metric.""" |
| 20 raise NotImplementedError() | 20 raise NotImplementedError() |
| 21 | 21 |
| 22 def Reason(self, metric, score): | 22 def Reason(self, metric, score): |
| 23 """Given the reason of this score.""" | 23 """Gives the reason of this score.""" |
| 24 raise NotImplementedError() |
| 25 |
| 26 def ChangedFiles(self, result): |
| 27 """Returns the changed files info dict.""" |
| 24 raise NotImplementedError() | 28 raise NotImplementedError() |
| 25 | 29 |
| 26 def __call__(self, result): | 30 def __call__(self, result): |
| 27 """Returns score and reason of this result.""" | 31 """Returns score and reason of this result.""" |
| 28 metric = self.GetMetric(result) | 32 metric = self.GetMetric(result) |
| 29 if metric is None: | 33 if metric is None: |
| 30 logging.warning('Cannot get needed metric of result %s for scorer %s', | 34 logging.warning('Cannot get needed metric of result %s for scorer %s', |
| 31 repr(result.ToDict()), self.name) | 35 repr(result.ToDict()), self.name) |
| 32 return 0, '' | 36 return 0, '' |
| 33 | 37 |
| 34 score = self.Score(metric) | 38 score = self.Score(metric) |
| 35 reason = self.Reason(metric, score) | 39 reason = self.Reason(metric, score) |
| 36 return score, reason | 40 changed_files = self.ChangedFiles(result) |
| 41 return score, reason, changed_files |
| 37 | 42 |
| 38 @property | 43 @property |
| 39 def name(self): | 44 def name(self): |
| 40 return self.__class__.__name__ | 45 return self.__class__.__name__ |
| OLD | NEW |