Chromium Code Reviews| Index: appengine/findit/crash/scorers/min_distance.py |
| diff --git a/appengine/findit/crash/scorers/min_distance.py b/appengine/findit/crash/scorers/min_distance.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..45865984a179aa54cf3aa8e22410d9dc8e04c1b0 |
| --- /dev/null |
| +++ b/appengine/findit/crash/scorers/min_distance.py |
| @@ -0,0 +1,43 @@ |
| +# 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. |
| + |
| +"""MinDistance scorer applies to MatchResult objects. |
| + |
| +It represents a heuristic rule: |
| + 1. Highest score if the result changed the crashed lines. |
| + 2. 0 score if changed lines are too far away from crashed lines. |
| +""" |
| + |
| +import logging |
| + |
| +from crash.scorers.scorer import Scorer |
| + |
| +_MAX_DISTANCE = 50 |
| + |
| + |
| +class MinDistance(Scorer): |
| + def __init__(self, max_distance=_MAX_DISTANCE): |
| + self.max_distance = max_distance |
| + |
| + def GetMetric(self, result): |
| + if not hasattr(result, 'min_distance'): |
|
Martin Barbella
2016/04/15 06:05:24
What would cause this to happen, other than an inc
Sharu
2016/04/15 22:59:47
I add this because I thought later I may add Blame
|
| + logging.warning('Scorer %s only applies to MatchResult' % self.name) |
| + return None |
| + |
| + return result.min_distance |
| + |
| + def Score(self, min_distance): |
| + if min_distance > self.max_distance: |
| + return 0 |
| + |
| + if min_distance == 0: |
| + return 1 |
| + |
| + return 0.8 |
|
stgao
2016/04/15 18:35:19
Where are these numbers from? Some comments in the
Sharu
2016/04/15 22:59:47
Added TODO, Done.
|
| + |
| + def Reason(self, min_distance, score): |
| + if score == 0: |
| + return '' |
| + |
| + return 'Minimum distance to crashed line is %d' % min_distance |