Compare commits

..

No commits in common. "8aa4d6d70b9dbf82afbbe1174ee0768d486eb2b6" and "28777fa68cf6acf221cff9d301a1e5ecb257e18f" have entirely different histories.

4 changed files with 59 additions and 155 deletions

View File

@ -2,53 +2,47 @@ package clangtidy
import (
"fmt"
"sort"
"strings"
"github.com/joint-online-judge/JOJ3/pkg/utils"
)
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)
categoryCount := 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
score -= match.Score
}
}
}
checkNames := strings.Split(checkName, ",")
for _, checkName := range checkNames {
parts := strings.Split(checkName, "-")
if len(parts) > 0 {
category := parts[0]
// checkName might be: -warnings-as-errors
if category == "" {
continue
}
type Result struct {
Keyword string
Count int
ScoreChange int
categoryCount[category] += 1
}
var results []Result
for keyword, count := range matchCount {
results = append(results, Result{
Keyword: keyword,
Count: count,
ScoreChange: scoreChange[keyword],
}
}
sortedMap := utils.SortMap(categoryCount,
func(i, j utils.Pair[string, int]) bool {
if i.Value == j.Value {
return i.Key < j.Key
}
return i.Value > j.Value
})
}
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)
for i, kv := range sortedMap {
comment += fmt.Sprintf("%d. %s: %d\n", i+1, kv.Key, kv.Value)
}
return score, comment
}

View File

@ -3,7 +3,6 @@ package cppcheck
import (
"fmt"
"log/slog"
"sort"
"strings"
)
@ -42,9 +41,9 @@ func severityFromString(severityString string) (Severity, error) {
}
func GetResult(records []Record, conf Conf) (string, int, error) {
score := conf.Score
comment := "### Test results summary\n\n"
result := "### Test results summary\n\n"
var severityCounts [UNKNOWN + 1]int
score := conf.Score
// TODO: remove me
var severityScore [UNKNOWN + 1]int
for _, match := range conf.Matches {
@ -74,52 +73,22 @@ func GetResult(records []Record, conf Conf) (string, int, error) {
severityCounts[int(severity)] += 1
score -= severityScore[int(severity)]
}
comment += fmt.Sprintf("1. error: %d\n", severityCounts[0])
comment += fmt.Sprintf("2. warning: %d\n", severityCounts[1])
comment += fmt.Sprintf("3. portability: %d\n", severityCounts[2])
comment += fmt.Sprintf("4. performance: %d\n", severityCounts[3])
comment += fmt.Sprintf("5. style: %d\n", severityCounts[4])
comment += fmt.Sprintf("6. information: %d\n", severityCounts[5])
comment += fmt.Sprintf("7. debug: %d\n", severityCounts[6])
}
matchCount := make(map[string]int)
scoreChange := make(map[string]int)
for _, record := range records {
for _, match := range conf.Matches {
for _, keyword := range match.Keywords {
if strings.Contains(record.Id, keyword) {
matchCount[keyword] += 1
scoreChange[keyword] += -match.Score
score += -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 comment, score, nil
result += fmt.Sprintf("1. error: %d\n", severityCounts[0])
result += fmt.Sprintf("2. warning: %d\n", severityCounts[1])
result += fmt.Sprintf("3. portability: %d\n", severityCounts[2])
result += fmt.Sprintf("4. performance: %d\n", severityCounts[3])
result += fmt.Sprintf("5. style: %d\n", severityCounts[4])
result += fmt.Sprintf("6. information: %d\n", severityCounts[5])
result += fmt.Sprintf("7. debug: %d\n", severityCounts[6])
return result, score, nil
}

View File

@ -4,7 +4,6 @@ import (
"fmt"
"log/slog"
"regexp"
"sort"
"strconv"
"strings"
@ -31,15 +30,13 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
stderr := executorResult.Files[conf.Stderr]
pattern := `(.+):(\d+): (.+) \[(.+)\] \[(\d)]\n`
re := regexp.MustCompile(pattern)
regexMatches := re.FindAllStringSubmatch(stderr, -1)
matches := re.FindAllStringSubmatch(stderr, -1)
score := conf.Score
comment := "### Test results summary\n\n"
categoryCount := make(map[string]int)
matchCount := make(map[string]int)
scoreChange := make(map[string]int)
for _, regexMatch := range regexMatches {
// fileName := regexMatch[1]
// lineNum, err := strconv.Atoi(regexMatch[2])
categoryCount := map[string]int{}
for _, match := range matches {
// fileName := match[1]
// lineNum, err := strconv.Atoi(match[2])
// if err != nil {
// slog.Error("parse lineNum", "error", err)
// return stage.ParserResult{
@ -47,11 +44,11 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
// Comment: fmt.Sprintf("Unexpected parser error: %s.", err),
// }
// }
// message := regexMatch[3]
category := regexMatch[4]
// message := match[3]
category := match[4]
// TODO: remove me
if len(conf.Matches) == 0 {
confidence, err := strconv.Atoi(regexMatch[5])
confidence, err := strconv.Atoi(match[5])
if err != nil {
slog.Error("parse confidence", "error", err)
return stage.ParserResult{
@ -61,23 +58,19 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
}
score -= confidence
}
for _, match := range conf.Matches {
for _, keyword := range match.Keywords {
if strings.Contains(category, keyword) {
score -= match.Score
}
}
}
parts := strings.Split(category, "/")
if len(parts) > 0 {
category := parts[0]
categoryCount[category] += 1
}
// TODO: remove me ends
for _, match := range conf.Matches {
for _, keyword := range match.Keywords {
if strings.Contains(category, keyword) {
matchCount[keyword] += 1
scoreChange[keyword] += -match.Score
score += -match.Score
}
}
}
}
// TODO: remove me
sortedMap := utils.SortMap(categoryCount,
func(i, j utils.Pair[string, int]) bool {
if i.Value == j.Value {
@ -88,33 +81,6 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
for i, kv := range sortedMap {
comment += fmt.Sprintf("%d. %s: %d\n", i+1, kv.Key, kv.Value)
}
// TODO: remove me ends
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 stage.ParserResult{
Score: score,
Comment: comment,

View File

@ -2,7 +2,6 @@ package keyword
import (
"fmt"
"sort"
"strings"
"github.com/joint-online-judge/JOJ3/internal/stage"
@ -28,47 +27,23 @@ type Keyword struct{}
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
score := conf.Score
comment := ""
matchCount := make(map[string]int)
scoreChange := make(map[string]int)
for _, match := range conf.Matches {
for _, keyword := range match.Keywords {
keywordMatchCount := 0
for _, file := range conf.Files {
content := executorResult.Files[file]
matchCount[keyword] += strings.Count(content, keyword)
keywordMatchCount += strings.Count(content, keyword)
}
if match.MaxMatchCount > 0 {
matchCount[keyword] = min(
matchCount[keyword], match.MaxMatchCount)
keywordMatchCount = min(keywordMatchCount, match.MaxMatchCount)
}
score += -match.Score * matchCount[keyword]
scoreChange[keyword] = -match.Score * matchCount[keyword]
if keywordMatchCount > 0 {
score -= keywordMatchCount * match.Score
comment += fmt.Sprintf(
"Matched keyword %d time(s): %s\n",
keywordMatchCount, keyword)
}
}
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 stage.ParserResult{
Score: score,