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

Side by Side Diff: appengine/findit/waterfall/suspected_cl_util.py

Issue 2439553002: [Findit] Reduce redundant ndb reads by querying necessary entities ahead of time and share them amo… (Closed)
Patch Set: fix a bug on confidence score. Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from google.appengine.ext import ndb 5 from google.appengine.ext import ndb
6 6
7 from common import time_util 7 from common import time_util
8 from common.waterfall import failure_type 8 from common.waterfall import failure_type
9 from model import analysis_approach_type 9 from model import analysis_approach_type
10 from model.wf_suspected_cl import WfSuspectedCL 10 from model.wf_suspected_cl import WfSuspectedCL
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 'status': _GetsStatusFromSameFailure(suspected_cl.builds, failures), 53 'status': _GetsStatusFromSameFailure(suspected_cl.builds, failures),
54 'top_score': top_score 54 'top_score': top_score
55 } 55 }
56 else: 56 else:
57 build = suspected_cl.builds[build_key] 57 build = suspected_cl.builds[build_key]
58 if approach not in build['approaches']: 58 if approach not in build['approaches']:
59 build['approaches'].append(approach) 59 build['approaches'].append(approach)
60 60
61 suspected_cl.put() 61 suspected_cl.put()
62 62
63
63 def _RoundConfidentToInteger(confidence): 64 def _RoundConfidentToInteger(confidence):
64 return round(confidence * 100) 65 return int(round(confidence * 100))
65 66
66 67
67 def GetSuspectedCLConfidenceScore(confidences, cl_build): 68 def GetSuspectedCLConfidenceScore(confidences, cl_build):
68
69 if not confidences or not cl_build: 69 if not confidences or not cl_build:
70 return None 70 return None
71 71
72 if cl_build['failure_type'] == failure_type.COMPILE: 72 if cl_build['failure_type'] == failure_type.COMPILE:
73 if cl_build['approaches'] == [ 73 if sorted(cl_build['approaches']) == sorted([
74 analysis_approach_type.HEURISTIC, analysis_approach_type.TRY_JOB]: 74 analysis_approach_type.HEURISTIC, analysis_approach_type.TRY_JOB]):
75 return _RoundConfidentToInteger( 75 return _RoundConfidentToInteger(
76 confidences.compile_heuristic_try_job.confidence) 76 confidences.compile_heuristic_try_job.confidence)
77 elif cl_build['approaches'] == [analysis_approach_type.TRY_JOB]: 77 elif cl_build['approaches'] == [analysis_approach_type.TRY_JOB]:
78 return _RoundConfidentToInteger( 78 return _RoundConfidentToInteger(
79 confidences.compile_try_job.confidence) 79 confidences.compile_try_job.confidence)
80 elif (cl_build['approaches'] == [analysis_approach_type.HEURISTIC] and 80 elif (cl_build['approaches'] == [analysis_approach_type.HEURISTIC] and
81 cl_build['top_score']): 81 cl_build['top_score']):
82 for confidences_info in confidences.compile_heuristic: 82 for confidences_info in confidences.compile_heuristic:
83 if confidences_info.score == cl_build['top_score']: 83 if confidences_info.score == cl_build['top_score']:
84 return _RoundConfidentToInteger(confidences_info.confidence) 84 return _RoundConfidentToInteger(confidences_info.confidence)
85 return None 85 return None
86 else: 86 else:
87 if cl_build['approaches'] == [ 87 if sorted(cl_build['approaches']) == sorted([
88 analysis_approach_type.HEURISTIC, analysis_approach_type.TRY_JOB]: 88 analysis_approach_type.HEURISTIC, analysis_approach_type.TRY_JOB]):
89 return _RoundConfidentToInteger( 89 return _RoundConfidentToInteger(
90 confidences.test_heuristic_try_job.confidence) 90 confidences.test_heuristic_try_job.confidence)
91 elif cl_build['approaches'] == [analysis_approach_type.TRY_JOB]: 91 elif cl_build['approaches'] == [analysis_approach_type.TRY_JOB]:
92 return _RoundConfidentToInteger(confidences.test_try_job.confidence) 92 return _RoundConfidentToInteger(confidences.test_try_job.confidence)
93 elif (cl_build['approaches'] == [analysis_approach_type.HEURISTIC] and 93 elif (cl_build['approaches'] == [analysis_approach_type.HEURISTIC] and
94 cl_build['top_score']): 94 cl_build['top_score']):
95 for confidences_info in confidences.test_heuristic: 95 for confidences_info in confidences.test_heuristic:
96 if confidences_info.score == cl_build['top_score']: 96 if confidences_info.score == cl_build['top_score']:
97 return _RoundConfidentToInteger(confidences_info.confidence) 97 return _RoundConfidentToInteger(confidences_info.confidence)
98 return None 98 return None
99
100
101 def _HasNewFailures(current_failures, new_failures):
102 """Checks if there are any new failures in the current build."""
103 if current_failures == new_failures:
104 return False
105
106 for step, tests in current_failures.iteritems():
107 if not new_failures.get(step): # New step.
108 return True
109
110 for test in tests:
111 if not test in new_failures[step]: # New test.
112 return True
113
114 return False
115
116
117 def GetSuspectedCLConfidenceScoreAndApproach(
118 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.
119 if not confidences or not cl_build:
120 return None, None
121
122 if (cl_first_build and not _HasNewFailures(
123 cl_build.get('failures'), cl_first_build.get('failures'))):
124 # For non-first-time failures, the try job result is not recorded.
125 # If there is no new failures in current build, use first failed build to
126 # make sure the confidence score is correct.
127 cl_build = cl_first_build
128
129 confidence = GetSuspectedCLConfidenceScore(confidences, cl_build)
130 approach = (
131 analysis_approach_type.TRY_JOB if analysis_approach_type.TRY_JOB in
132 cl_build['approaches'] else analysis_approach_type.HEURISTIC)
133
134 return confidence, approach
OLDNEW
« no previous file with comments | « appengine/findit/test/findit_api_test.py ('k') | appengine/findit/waterfall/test/suspected_cl_util_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698