feat(parser/resultdetail): new parser with default conf
This commit is contained in:
parent
b61291b5cb
commit
542394a48a
1
go.mod
1
go.mod
|
@ -7,6 +7,7 @@ require (
|
|||
github.com/go-git/go-git/v5 v5.12.0
|
||||
github.com/jinzhu/copier v0.4.0
|
||||
github.com/koding/multiconfig v0.0.0-20171124222453-69c27309b2d7
|
||||
github.com/mcuadros/go-defaults v1.2.0
|
||||
github.com/mitchellh/mapstructure v1.5.0
|
||||
google.golang.org/grpc v1.67.0
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -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.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
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/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/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
|
||||
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=
|
||||
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-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/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
_ "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/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/sample"
|
||||
)
|
||||
|
|
9
internal/parser/resultdetail/meta.go
Normal file
9
internal/parser/resultdetail/meta.go
Normal 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{})
|
||||
}
|
53
internal/parser/resultdetail/parser.go
Normal file
53
internal/parser/resultdetail/parser.go
Normal 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
|
||||
}
|
|
@ -3,14 +3,16 @@ package stage
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mcuadros/go-defaults"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
func DecodeConf[T any](confAny any) (*T, error) {
|
||||
var conf T
|
||||
err := mapstructure.Decode(confAny, &conf)
|
||||
conf := new(T)
|
||||
defaults.SetDefaults(conf)
|
||||
err := mapstructure.Decode(confAny, conf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode conf: %w", err)
|
||||
}
|
||||
return &conf, nil
|
||||
return conf, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user