Compare commits
No commits in common. "4b848bf1f146a5698a59284599a13f49b746ca81" and "fa649fcabed7111ed18cac16112a7255a269c48c" have entirely different histories.
4b848bf1f1
...
fa649fcabe
|
@ -2,9 +2,8 @@ package clangtidy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/joint-online-judge/JOJ3/pkg/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
|
func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
|
||||||
|
@ -34,14 +33,21 @@ func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sortedMap := utils.SortMap(categoryCount,
|
type kv struct {
|
||||||
func(i, j utils.Pair[string, int]) bool {
|
Key string
|
||||||
if i.Value == j.Value {
|
Value int
|
||||||
return i.Key < j.Key
|
}
|
||||||
}
|
var ss []kv
|
||||||
return i.Value > j.Value
|
for k, v := range categoryCount {
|
||||||
})
|
ss = append(ss, kv{k, v})
|
||||||
for i, kv := range sortedMap {
|
}
|
||||||
|
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)
|
comment += fmt.Sprintf("%d. %s: %d\n", i+1, kv.Key, kv.Value)
|
||||||
}
|
}
|
||||||
return score, comment
|
return score, comment
|
||||||
|
|
|
@ -5,10 +5,8 @@ import (
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||||
"github.com/joint-online-judge/JOJ3/pkg/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
|
@ -23,19 +21,18 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||||
re := regexp.MustCompile(pattern)
|
re := regexp.MustCompile(pattern)
|
||||||
matches := re.FindAllStringSubmatch(stderr, -1)
|
matches := re.FindAllStringSubmatch(stderr, -1)
|
||||||
score := 0
|
score := 0
|
||||||
comment := "### Test results summary\n\n"
|
comment := ""
|
||||||
categoryCount := map[string]int{}
|
|
||||||
for _, match := range matches {
|
for _, match := range matches {
|
||||||
// fileName := match[1]
|
fileName := match[1]
|
||||||
// lineNum, err := strconv.Atoi(match[2])
|
lineNum, err := strconv.Atoi(match[2])
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// slog.Error("parse lineNum", "error", err)
|
slog.Error("parse lineNum", "error", err)
|
||||||
// return stage.ParserResult{
|
return stage.ParserResult{
|
||||||
// Score: 0,
|
Score: 0,
|
||||||
// Comment: fmt.Sprintf("Unexpected parser error: %s.", err),
|
Comment: fmt.Sprintf("Unexpected parser error: %s.", err),
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// message := match[3]
|
message := match[3]
|
||||||
category := match[4]
|
category := match[4]
|
||||||
confidence, err := strconv.Atoi(match[5])
|
confidence, err := strconv.Atoi(match[5])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -46,21 +43,9 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
score -= confidence
|
score -= confidence
|
||||||
parts := strings.Split(category, "/")
|
// TODO: add more detailed comment, just re-assemble for now
|
||||||
if len(parts) > 0 {
|
comment += fmt.Sprintf("%s:%d: %s [%s] [%d]\n",
|
||||||
category := parts[0]
|
fileName, lineNum, message, category, confidence)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
return stage.ParserResult{
|
return stage.ParserResult{
|
||||||
Score: score,
|
Score: score,
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
Score int
|
Score int
|
||||||
Comment string
|
Comment string
|
||||||
ForceQuitOnNotAccepted bool `default:"true"`
|
ForceQuitOnNotAccepted bool `default:"false"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResultStatus struct{}
|
type ResultStatus struct{}
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user