Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Unified Diff: appengine/findit/crash/scorers/scorer.py

Issue 1861373003: [Findit] Initial code of findit for crash. Add scorers to apply heuristic rules. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Fix nits and rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/findit/crash/scorers/min_distance.py ('k') | appengine/findit/crash/scorers/test/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/crash/scorers/scorer.py
diff --git a/appengine/findit/crash/scorers/scorer.py b/appengine/findit/crash/scorers/scorer.py
new file mode 100644
index 0000000000000000000000000000000000000000..20056036bbfbfd873200970d6bcd9b8b38c635d3
--- /dev/null
+++ b/appengine/findit/crash/scorers/scorer.py
@@ -0,0 +1,40 @@
+# 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.
+
+"""Interface of scorers to score and reason Result.
+
+A Scorer represents a heuristic rule to score a culprit cl result.
+"""
+
+import logging
+
+
+class Scorer(object): # pragma: no cover.
+
+ def GetMetric(self, result):
+ raise NotImplementedError()
+
+ def Score(self, metric):
+ """Score the result based on extracted metric."""
+ raise NotImplementedError()
+
+ def Reason(self, metric, score):
+ """Given the reason of this score."""
+ raise NotImplementedError()
+
+ def __call__(self, result):
+ """Returns score and reason of this result."""
+ metric = self.GetMetric(result)
+ if metric is None:
+ logging.warning('Cannot get needed metric of result %s for scorer %s',
+ repr(result.ToDict()), self.name)
+ return 0, ''
+
+ score = self.Score(metric)
+ reason = self.Reason(metric, score)
+ return score, reason
+
+ @property
+ def name(self):
+ return self.__class__.__name__
« no previous file with comments | « appengine/findit/crash/scorers/min_distance.py ('k') | appengine/findit/crash/scorers/test/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698