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

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: Address comments 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
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..132552e0cfeb260afb71f1fd143668f7faa2a816
--- /dev/null
+++ b/appengine/findit/crash/scorers/scorer.py
@@ -0,0 +1,38 @@
+# 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__

Powered by Google App Engine
This is Rietveld 408576698