feat(parser/resultdetail): new parser with default conf
All checks were successful
build / build (push) Successful in 1m48s
build / trigger-build-image (push) Successful in 7s

This commit is contained in:
张泊明518370910136 2024-10-09 18:05:59 -04:00
parent b61291b5cb
commit 542394a48a
GPG Key ID: D47306D7062CDA9D
6 changed files with 73 additions and 3 deletions

1
go.mod
View File

@ -7,6 +7,7 @@ require (
github.com/go-git/go-git/v5 v5.12.0 github.com/go-git/go-git/v5 v5.12.0
github.com/jinzhu/copier v0.4.0 github.com/jinzhu/copier v0.4.0
github.com/koding/multiconfig v0.0.0-20171124222453-69c27309b2d7 github.com/koding/multiconfig v0.0.0-20171124222453-69c27309b2d7
github.com/mcuadros/go-defaults v1.2.0
github.com/mitchellh/mapstructure v1.5.0 github.com/mitchellh/mapstructure v1.5.0
google.golang.org/grpc v1.67.0 google.golang.org/grpc v1.67.0
) )

4
go.sum
View File

@ -63,8 +63,11 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mcuadros/go-defaults v1.2.0 h1:FODb8WSf0uGaY8elWJAkoLL0Ri6AlZ1bFlenk56oZtc=
github.com/mcuadros/go-defaults v1.2.0/go.mod h1:WEZtHEVIGYVDqkKSWBdWKUVdRyKlMfulPaGDWIVeCWY=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
@ -159,6 +162,7 @@ google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6h
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=

View File

@ -8,6 +8,7 @@ import (
_ "github.com/joint-online-judge/JOJ3/internal/parser/dummy" _ "github.com/joint-online-judge/JOJ3/internal/parser/dummy"
_ "github.com/joint-online-judge/JOJ3/internal/parser/healthcheck" _ "github.com/joint-online-judge/JOJ3/internal/parser/healthcheck"
_ "github.com/joint-online-judge/JOJ3/internal/parser/keyword" _ "github.com/joint-online-judge/JOJ3/internal/parser/keyword"
_ "github.com/joint-online-judge/JOJ3/internal/parser/resultdetail"
_ "github.com/joint-online-judge/JOJ3/internal/parser/resultstatus" _ "github.com/joint-online-judge/JOJ3/internal/parser/resultstatus"
_ "github.com/joint-online-judge/JOJ3/internal/parser/sample" _ "github.com/joint-online-judge/JOJ3/internal/parser/sample"
) )

View File

@ -0,0 +1,9 @@
package resultdetail
import "github.com/joint-online-judge/JOJ3/internal/stage"
var name = "result-detail"
func init() {
stage.RegisterParser(name, &ResultDetail{})
}

View File

@ -0,0 +1,53 @@
package resultdetail
import (
"fmt"
"github.com/joint-online-judge/JOJ3/internal/stage"
)
type Conf struct {
Score int
ShowExitStatus bool `default:"false"`
ShowError bool `default:"false"`
ShowTime bool `default:"true"`
ShowMemory bool `default:"true"`
ShowRunTime bool `default:"false"`
}
type ResultDetail struct{}
func (*ResultDetail) Run(results []stage.ExecutorResult, confAny any) (
[]stage.ParserResult, bool, error,
) {
conf, err := stage.DecodeConf[Conf](confAny)
if err != nil {
return nil, true, err
}
forceQuit := false
var res []stage.ParserResult
for _, result := range results {
comment := ""
// TODO: more human readable units
if conf.ShowExitStatus {
comment += fmt.Sprintf("Exit Status: %d\n", result.ExitStatus)
}
if conf.ShowError {
comment += fmt.Sprintf("Error: %s\n", result.Error)
}
if conf.ShowTime {
comment += fmt.Sprintf("Time: %d\n", result.Time)
}
if conf.ShowMemory {
comment += fmt.Sprintf("Memory: %d\n", result.Memory)
}
if conf.ShowRunTime {
comment += fmt.Sprintf("RunTime: %d\n", result.RunTime)
}
res = append(res, stage.ParserResult{
Score: conf.Score,
Comment: comment,
})
}
return res, forceQuit, nil
}

View File

@ -3,14 +3,16 @@ package stage
import ( import (
"fmt" "fmt"
"github.com/mcuadros/go-defaults"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
) )
func DecodeConf[T any](confAny any) (*T, error) { func DecodeConf[T any](confAny any) (*T, error) {
var conf T conf := new(T)
err := mapstructure.Decode(confAny, &conf) defaults.SetDefaults(conf)
err := mapstructure.Decode(confAny, conf)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to decode conf: %w", err) return nil, fmt.Errorf("failed to decode conf: %w", err)
} }
return &conf, nil return conf, nil
} }