Chromium Code Reviews| Index: appengine/findit/waterfall/suspected_cl_util.py |
| diff --git a/appengine/findit/waterfall/suspected_cl_util.py b/appengine/findit/waterfall/suspected_cl_util.py |
| index 28b2786d10d19910c27d430667cd58f96c8e5864..d191b567dca7e625e6de8f0210e6d907a19fc98a 100644 |
| --- a/appengine/findit/waterfall/suspected_cl_util.py |
| +++ b/appengine/findit/waterfall/suspected_cl_util.py |
| @@ -60,18 +60,18 @@ def UpdateSuspectedCL( |
| suspected_cl.put() |
| + |
| def _RoundConfidentToInteger(confidence): |
| - return round(confidence * 100) |
| + return int(round(confidence * 100)) |
| def GetSuspectedCLConfidenceScore(confidences, cl_build): |
| - |
| if not confidences or not cl_build: |
| return None |
| if cl_build['failure_type'] == failure_type.COMPILE: |
| - if cl_build['approaches'] == [ |
| - analysis_approach_type.HEURISTIC, analysis_approach_type.TRY_JOB]: |
| + if sorted(cl_build['approaches']) == sorted([ |
| + analysis_approach_type.HEURISTIC, analysis_approach_type.TRY_JOB]): |
| return _RoundConfidentToInteger( |
| confidences.compile_heuristic_try_job.confidence) |
| elif cl_build['approaches'] == [analysis_approach_type.TRY_JOB]: |
| @@ -84,8 +84,8 @@ def GetSuspectedCLConfidenceScore(confidences, cl_build): |
| return _RoundConfidentToInteger(confidences_info.confidence) |
| return None |
| else: |
| - if cl_build['approaches'] == [ |
| - analysis_approach_type.HEURISTIC, analysis_approach_type.TRY_JOB]: |
| + if sorted(cl_build['approaches']) == sorted([ |
| + analysis_approach_type.HEURISTIC, analysis_approach_type.TRY_JOB]): |
| return _RoundConfidentToInteger( |
| confidences.test_heuristic_try_job.confidence) |
| elif cl_build['approaches'] == [analysis_approach_type.TRY_JOB]: |
| @@ -96,3 +96,39 @@ def GetSuspectedCLConfidenceScore(confidences, cl_build): |
| if confidences_info.score == cl_build['top_score']: |
| return _RoundConfidentToInteger(confidences_info.confidence) |
| return None |
| + |
| + |
| +def _HasNewFailures(current_failures, new_failures): |
| + """Checks if there are any new failures in the current build.""" |
| + if current_failures == new_failures: |
| + return False |
| + |
| + for step, tests in current_failures.iteritems(): |
| + if not new_failures.get(step): # New step. |
| + return True |
| + |
| + for test in tests: |
| + if not test in new_failures[step]: # New test. |
| + return True |
| + |
| + return False |
| + |
| + |
| +def GetSuspectedCLConfidenceScoreAndApproach( |
| + confidences, cl_build, cl_first_build): |
|
lijeffrey
2016/10/28 02:32:32
nit: rename these cl_from_analyzed_build and cl_f
chanli
2016/10/28 02:41:46
Done.
|
| + if not confidences or not cl_build: |
| + return None, None |
| + |
| + if (cl_first_build and not _HasNewFailures( |
| + cl_build.get('failures'), cl_first_build.get('failures'))): |
| + # For non-first-time failures, the try job result is not recorded. |
| + # If there is no new failures in current build, use first failed build to |
| + # make sure the confidence score is correct. |
| + cl_build = cl_first_build |
| + |
| + confidence = GetSuspectedCLConfidenceScore(confidences, cl_build) |
| + approach = ( |
| + analysis_approach_type.TRY_JOB if analysis_approach_type.TRY_JOB in |
| + cl_build['approaches'] else analysis_approach_type.HEURISTIC) |
| + |
| + return confidence, approach |