JOJ3/internal/parser/clangtidy/score.go
张泊明518370910136 d54a557d23
Some checks failed
build / trigger-build-image (push) Blocked by required conditions
build / build (push) Has been cancelled
submodules sync / sync (push) Has been cancelled
feat(parser): show match occurrences (#76)
Reviewed-on: #76
Co-authored-by: Boming Zhang <bomingzh@sjtu.edu.cn>
Co-committed-by: Boming Zhang <bomingzh@sjtu.edu.cn>
2024-11-04 09:44:05 +08:00

55 lines
1.4 KiB
Go

package clangtidy
import (
"fmt"
"sort"
"strings"
)
func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
score := conf.Score
comment := "### Test results summary\n\n"
matchCount := make(map[string]int)
scoreChange := make(map[string]int)
for _, jsonMessage := range jsonMessages {
// checkName is commas separated string here
checkName := jsonMessage.CheckName
for _, match := range conf.Matches {
for _, keyword := range match.Keywords {
if strings.Contains(checkName, keyword) {
matchCount[keyword] += 1
scoreChange[keyword] += -match.Score
score += -match.Score
}
}
}
}
type Result struct {
Keyword string
Count int
ScoreChange int
}
var results []Result
for keyword, count := range matchCount {
results = append(results, Result{
Keyword: keyword,
Count: count,
ScoreChange: scoreChange[keyword],
})
}
sort.Slice(results, func(i, j int) bool {
if results[i].ScoreChange != results[j].ScoreChange {
return results[i].ScoreChange < results[j].ScoreChange
}
if results[i].Count != results[j].Count {
return results[i].Count > results[j].Count
}
return results[i].Keyword < results[j].Keyword
})
for i, result := range results {
comment += fmt.Sprintf("%d. `%s`: %d occurrence(s), %d point(s)\n",
i+1, result.Keyword, result.Count, result.ScoreChange)
}
return score, comment
}