go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/bisection/model/heuristic_analysis_result.go (about)

     1  // Copyright 2022 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package model
    16  
    17  import "sort"
    18  
    19  type HeuristicAnalysisResult struct {
    20  	// A slice of possible culprit, sorted by score descendingly
    21  	Items []*HeuristicAnalysisResultItem
    22  }
    23  
    24  type HeuristicAnalysisResultItem struct {
    25  	Commit        string
    26  	ReviewUrl     string
    27  	ReviewTitle   string
    28  	Justification *SuspectJustification
    29  }
    30  
    31  // AddItem adds a suspect to HeuristicAnalysisResult.
    32  func (r *HeuristicAnalysisResult) AddItem(commit string, reviewUrl string, reviewTitle string, justification *SuspectJustification) {
    33  	item := &HeuristicAnalysisResultItem{
    34  		Commit:        commit,
    35  		ReviewUrl:     reviewUrl,
    36  		ReviewTitle:   reviewTitle,
    37  		Justification: justification,
    38  	}
    39  	r.Items = append(r.Items, item)
    40  }
    41  
    42  // Sort items descendingly based on score (CLs with higher possibility to be
    43  // culprit will come first).
    44  func (r *HeuristicAnalysisResult) Sort() {
    45  	sort.Slice(r.Items, func(i, j int) bool {
    46  		return r.Items[i].Justification.GetScore() > r.Items[j].Justification.GetScore()
    47  	})
    48  }