| 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 """MinDistance scorer applies to MatchResult objects. |
| 6 |
| 7 It represents a heuristic rule: |
| 8 1. Highest score if the result changed the crashed lines. |
| 9 2. 0 score if changed lines are too far away from crashed lines. |
| 10 """ |
| 11 |
| 12 import logging |
| 13 |
| 14 from crash.scorers.scorer import Scorer |
| 15 |
| 16 _MAX_DISTANCE = 50 |
| 17 |
| 18 |
| 19 class MinDistance(Scorer): |
| 20 |
| 21 def __init__(self, max_distance=_MAX_DISTANCE): |
| 22 self.max_distance = max_distance |
| 23 |
| 24 def GetMetric(self, result): |
| 25 if not hasattr(result, 'min_distance'): |
| 26 logging.warning('Scorer %s only applies to MatchResult', self.name) |
| 27 return None |
| 28 |
| 29 return result.min_distance |
| 30 |
| 31 def Score(self, min_distance): |
| 32 if min_distance > self.max_distance: |
| 33 return 0 |
| 34 |
| 35 if min_distance == 0: |
| 36 return 1 |
| 37 |
| 38 # TODO(katesonia): This number is randomly picked from a reasonable range, |
| 39 # best value to use still needs be experimented out. |
| 40 return 0.8 |
| 41 |
| 42 def Reason(self, min_distance, score): |
| 43 if score == 0: |
| 44 return '' |
| 45 |
| 46 return 'Minimum distance to crashed line is %d' % min_distance |
| OLD | NEW |