Skip to content

Commit

Permalink
🐛 attempt to fix banded scoring with exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Jul 8, 2024
1 parent 4b001a6 commit ddc8456
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
30 changes: 4 additions & 26 deletions policy/score_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,6 @@ func AddSpecdScore(calculator ScoreCalculator, s *Score, found bool, impact *exp
return
}

// everything else is modify or activate

if impact.Scoring == explorer.ScoringSystem_IGNORE_SCORE {
calculator.Add(&Score{
// We override the type because:
// 1. If it is set to Result, its value will be added to the total
// calculation in most calculators despite its weight.
// 2. We don't want to set it to unscored, because technically we
// just ignore the score.
// Thus we set the score to unknown for the sake of the calculator,
// thus it knows it is handling a scored result, but also knows not
// to count it.
Type: ScoreType_Unknown,
Value: score.Value,
Weight: 0,
ScoreCompletion: score.ScoreCompletion,
DataCompletion: score.DataCompletion,
DataTotal: score.DataTotal,
}, nil)
return
}

if impact.Weight > 0 {
score.Weight = uint32(impact.Weight)
} else if score.Weight == 0 {
Expand Down Expand Up @@ -490,22 +468,22 @@ func (c *bandedScoreCalculator) Add(score *Score, impact *explorer.Impact) {

if category <= 10 {
c.critMax += score.Weight
if score.Value == 100 {
if score.Value < 100 {
c.crit += score.Weight
}
} else if category <= 30 {
c.highMax += score.Weight
if score.Value == 100 {
if score.Value < 100 {
c.high += score.Weight
}
} else if category <= 60 {
c.midMax += score.Weight
if score.Value == 100 {
if score.Value < 100 {
c.mid += score.Weight
}
} else {
c.lowMax += score.Weight
if score.Value == 100 {
if score.Value < 100 {
c.low += score.Weight
}
}
Expand Down
23 changes: 20 additions & 3 deletions policy/score_calculator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestBandedScores(t *testing.T) {
{Value: &explorer.ImpactValue{Value: 100}},
{Action: explorer.Action_IGNORE},
},
out: &Score{Value: 25, ScoreCompletion: 100, DataCompletion: 66, Weight: 10, Type: ScoreType_Result},
out: &Score{Value: 22, ScoreCompletion: 100, DataCompletion: 66, Weight: 10, Type: ScoreType_Result},
},
{
in: []*Score{
Expand All @@ -239,7 +239,24 @@ func TestBandedScores(t *testing.T) {
// 10 high checks
{Value: &explorer.ImpactValue{Value: 80}},
},
out: &Score{Value: 45, ScoreCompletion: 100, DataCompletion: 66, Weight: 20, Type: ScoreType_Result},
out: &Score{Value: 1, ScoreCompletion: 100, DataCompletion: 66, Weight: 20, Type: ScoreType_Result},
},
{
in: []*Score{
// 10 critical checks (9ok, 1not)
{Value: 1000, ScoreCompletion: 100, DataCompletion: 80, DataTotal: 5, Weight: 1, Type: ScoreType_Result},
{Value: 100, ScoreCompletion: 100, DataCompletion: 100, DataTotal: 1, Weight: 9, Type: ScoreType_Result},
// 10 high checks (ok)
{Value: 100, ScoreCompletion: 100, DataCompletion: 33, DataTotal: 3, Weight: 10, Type: ScoreType_Result},
},
impacts: []*explorer.Impact{
// 10 critical checks
{Value: &explorer.ImpactValue{Value: 100}},
{Value: &explorer.ImpactValue{Value: 100}},
// 10 high checks
{Value: &explorer.ImpactValue{Value: 80}},
},
out: &Score{Value: 100, ScoreCompletion: 100, DataCompletion: 66, Weight: 20, Type: ScoreType_Result},
},
{
in: []*Score{
Expand All @@ -256,7 +273,7 @@ func TestBandedScores(t *testing.T) {
// 10 high checks
{Value: &explorer.ImpactValue{Value: 80}},
},
out: &Score{Value: 9, ScoreCompletion: 100, DataCompletion: 66, Weight: 20, Type: ScoreType_Result},
out: &Score{Value: 5, ScoreCompletion: 100, DataCompletion: 66, Weight: 20, Type: ScoreType_Result},
},
})
}
Expand Down

0 comments on commit ddc8456

Please sign in to comment.