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