Compare commits

..

No commits in common. "4b848bf1f146a5698a59284599a13f49b746ca81" and "fa649fcabed7111ed18cac16112a7255a269c48c" have entirely different histories.

4 changed files with 31 additions and 59 deletions

View File

@ -2,9 +2,8 @@ package clangtidy
import (
"fmt"
"sort"
"strings"
"github.com/joint-online-judge/JOJ3/pkg/utils"
)
func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
@ -34,14 +33,21 @@ func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
}
}
}
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
})
for i, kv := range sortedMap {
type kv struct {
Key string
Value int
}
var ss []kv
for k, v := range categoryCount {
ss = append(ss, kv{k, v})
}
sort.Slice(ss, func(i, j int) bool {
if ss[i].Value == ss[j].Value {
return ss[i].Key < ss[j].Key
}
return ss[i].Value > ss[j].Value
})
for i, kv := range ss {
comment += fmt.Sprintf("%d. %s: %d\n", i+1, kv.Key, kv.Value)
}
return score, comment

View File

@ -5,10 +5,8 @@ import (
"log/slog"
"regexp"
"strconv"
"strings"
"github.com/joint-online-judge/JOJ3/internal/stage"
"github.com/joint-online-judge/JOJ3/pkg/utils"
)
type Conf struct {
@ -23,19 +21,18 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
re := regexp.MustCompile(pattern)
matches := re.FindAllStringSubmatch(stderr, -1)
score := 0
comment := "### Test results summary\n\n"
categoryCount := map[string]int{}
comment := ""
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{
// Score: 0,
// Comment: fmt.Sprintf("Unexpected parser error: %s.", err),
// }
// }
// message := match[3]
fileName := match[1]
lineNum, err := strconv.Atoi(match[2])
if err != nil {
slog.Error("parse lineNum", "error", err)
return stage.ParserResult{
Score: 0,
Comment: fmt.Sprintf("Unexpected parser error: %s.", err),
}
}
message := match[3]
category := match[4]
confidence, err := strconv.Atoi(match[5])
if err != nil {
@ -46,21 +43,9 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
}
}
score -= confidence
parts := strings.Split(category, "/")
if len(parts) > 0 {
category := parts[0]
categoryCount[category] += 1
}
}
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
})
for i, kv := range sortedMap {
comment += fmt.Sprintf("%d. %s: %d\n", i+1, kv.Key, kv.Value)
// TODO: add more detailed comment, just re-assemble for now
comment += fmt.Sprintf("%s:%d: %s [%s] [%d]\n",
fileName, lineNum, message, category, confidence)
}
return stage.ParserResult{
Score: score,

View File

@ -10,7 +10,7 @@ import (
type Conf struct {
Score int
Comment string
ForceQuitOnNotAccepted bool `default:"true"`
ForceQuitOnNotAccepted bool `default:"false"`
}
type ResultStatus struct{}

View File

@ -1,19 +0,0 @@
package utils
import "sort"
type Pair[K comparable, V any] struct {
Key K
Value V
}
func SortMap[K comparable, V any](m map[K]V, less func(i, j Pair[K, V]) bool) []Pair[K, V] {
pairs := make([]Pair[K, V], 0, len(m))
for k, v := range m {
pairs = append(pairs, Pair[K, V]{k, v})
}
sort.Slice(pairs, func(i, j int) bool {
return less(pairs[i], pairs[j])
})
return pairs
}