feat: run with parsed toml
This commit is contained in:
parent
df62496537
commit
0a701e3b60
|
@ -5,6 +5,6 @@ $ make clean && make && ./build/joj3
|
||||||
rm -rf ./build/*
|
rm -rf ./build/*
|
||||||
rm -rf *.out
|
rm -rf *.out
|
||||||
go build -o ./build/joj3 ./cmd/joj3
|
go build -o ./build/joj3 ./cmd/joj3
|
||||||
dummy stage 0: score: 0, comment: I'm a dummy
|
stage 0: score: 100, comment: dummy comment for stage 0
|
||||||
dummy stage 1: score: 0, comment: I'm a dummy
|
stage 1: score: 101, comment: dummy comment for stage 1
|
||||||
```
|
```
|
||||||
|
|
|
@ -9,7 +9,31 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
stages := stage.ParseStages()
|
tomlConfig := `
|
||||||
|
[[stages]]
|
||||||
|
name = "stage 0"
|
||||||
|
[stages.executor]
|
||||||
|
name = "dummy"
|
||||||
|
[stages.executor.with]
|
||||||
|
args = [ "/usr/bin/cat", "/dev/null" ]
|
||||||
|
[stages.parser]
|
||||||
|
name = "dummy"
|
||||||
|
[stages.parser.with]
|
||||||
|
score = 100
|
||||||
|
comment = "dummy comment for stage 0"
|
||||||
|
[[stages]]
|
||||||
|
name = "stage 1"
|
||||||
|
[stages.executor]
|
||||||
|
name = "dummy"
|
||||||
|
[stages.executor.with]
|
||||||
|
args = [ "/usr/bin/cat", "/dev/null" ]
|
||||||
|
[stages.parser]
|
||||||
|
name = "dummy"
|
||||||
|
[stages.parser.with]
|
||||||
|
score = 101
|
||||||
|
comment = "dummy comment for stage 1"
|
||||||
|
`
|
||||||
|
stages := stage.ParseStages(tomlConfig)
|
||||||
results := stage.Run(stages)
|
results := stage.Run(stages)
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
|
|
6
go.mod
6
go.mod
|
@ -2,11 +2,15 @@ module focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3
|
||||||
|
|
||||||
go 1.22.0
|
go 1.22.0
|
||||||
|
|
||||||
require github.com/criyle/go-judge v1.8.1
|
require (
|
||||||
|
github.com/criyle/go-judge v1.8.1
|
||||||
|
github.com/mitchellh/mapstructure v1.5.0
|
||||||
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/creack/pty v1.1.21 // indirect
|
github.com/creack/pty v1.1.21 // indirect
|
||||||
github.com/criyle/go-sandbox v0.10.1 // indirect
|
github.com/criyle/go-sandbox v0.10.1 // indirect
|
||||||
|
github.com/pelletier/go-toml/v2 v2.1.1
|
||||||
golang.org/x/sync v0.6.0 // indirect
|
golang.org/x/sync v0.6.0 // indirect
|
||||||
golang.org/x/sys v0.16.0 // indirect
|
golang.org/x/sys v0.16.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
20
go.sum
20
go.sum
|
@ -4,7 +4,27 @@ github.com/criyle/go-judge v1.8.1 h1:VI9OGz1MnLp9cv//gMVL8uruNwxSod5UmNwew8ZnfCA
|
||||||
github.com/criyle/go-judge v1.8.1/go.mod h1:yZepeuMTmQXEJnBgHZQIGVuytRYWlLhQBQHLaL84N5w=
|
github.com/criyle/go-judge v1.8.1/go.mod h1:yZepeuMTmQXEJnBgHZQIGVuytRYWlLhQBQHLaL84N5w=
|
||||||
github.com/criyle/go-sandbox v0.10.1 h1:z9Il/UXQwKEvIwdr1wVheWWWAqGWtdTItBmEsWqFqT4=
|
github.com/criyle/go-sandbox v0.10.1 h1:z9Il/UXQwKEvIwdr1wVheWWWAqGWtdTItBmEsWqFqT4=
|
||||||
github.com/criyle/go-sandbox v0.10.1/go.mod h1:ivPw/HEh5unxVRlXJxCgkgTCuy+cxTkQDX7D2XQf/kg=
|
github.com/criyle/go-sandbox v0.10.1/go.mod h1:ivPw/HEh5unxVRlXJxCgkgTCuy+cxTkQDX7D2XQf/kg=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
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/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
|
||||||
|
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
||||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|
|
@ -3,13 +3,24 @@ package dummy
|
||||||
import (
|
import (
|
||||||
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
|
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
|
||||||
"github.com/criyle/go-judge/cmd/go-judge/model"
|
"github.com/criyle/go-judge/cmd/go-judge/model"
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Score int
|
||||||
|
Comment string
|
||||||
|
}
|
||||||
|
|
||||||
type Dummy struct{}
|
type Dummy struct{}
|
||||||
|
|
||||||
func (e *Dummy) Run(result model.Result, config string) stage.ParserResult {
|
func (e *Dummy) Run(result model.Result, configAny any) stage.ParserResult {
|
||||||
|
var config Config
|
||||||
|
err := mapstructure.Decode(configAny, &config)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return stage.ParserResult{
|
return stage.ParserResult{
|
||||||
Score: 0,
|
Score: config.Score,
|
||||||
Comment: "I'm a dummy",
|
Comment: config.Comment,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
37
internal/stage/model.go
Normal file
37
internal/stage/model.go
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package stage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/criyle/go-judge/cmd/go-judge/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Stage struct {
|
||||||
|
Name string
|
||||||
|
Executor Executor
|
||||||
|
ExecutorCmd model.Cmd
|
||||||
|
Parser Parser
|
||||||
|
ParserConfig any
|
||||||
|
}
|
||||||
|
|
||||||
|
type ParserResult struct {
|
||||||
|
Score int
|
||||||
|
Comment string
|
||||||
|
}
|
||||||
|
|
||||||
|
type StageResult struct {
|
||||||
|
Name string
|
||||||
|
ParserResult
|
||||||
|
}
|
||||||
|
|
||||||
|
type StagesConfig struct {
|
||||||
|
Stages []struct {
|
||||||
|
Name string
|
||||||
|
Executor struct {
|
||||||
|
Name string
|
||||||
|
With interface{}
|
||||||
|
}
|
||||||
|
Parser struct {
|
||||||
|
Name string
|
||||||
|
With interface{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,12 +5,7 @@ import "github.com/criyle/go-judge/cmd/go-judge/model"
|
||||||
var parserMap = map[string]Parser{}
|
var parserMap = map[string]Parser{}
|
||||||
|
|
||||||
type Parser interface {
|
type Parser interface {
|
||||||
Run(model.Result, string) ParserResult
|
Run(model.Result, any) ParserResult
|
||||||
}
|
|
||||||
|
|
||||||
type ParserResult struct {
|
|
||||||
Score int
|
|
||||||
Comment string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterParser(name string, parser Parser) {
|
func RegisterParser(name string, parser Parser) {
|
||||||
|
|
|
@ -2,34 +2,23 @@ package stage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/criyle/go-judge/cmd/go-judge/model"
|
"github.com/criyle/go-judge/cmd/go-judge/model"
|
||||||
|
"github.com/pelletier/go-toml/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Stage struct {
|
func ParseStages(tomlConfig string) []Stage {
|
||||||
name string
|
var stagesConfig StagesConfig
|
||||||
executor Executor
|
err := toml.Unmarshal([]byte(tomlConfig), &stagesConfig)
|
||||||
executorCmd model.Cmd
|
if err != nil {
|
||||||
parser Parser
|
panic(err)
|
||||||
parserConfig string
|
|
||||||
}
|
|
||||||
|
|
||||||
type StageResult struct {
|
|
||||||
Name string
|
|
||||||
ParserResult
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseStages() []Stage {
|
|
||||||
stages := []Stage{}
|
|
||||||
config := [][]string{
|
|
||||||
{"dummy stage 0", "dummy", "dummy"},
|
|
||||||
{"dummy stage 1", "dummy", "dummy"},
|
|
||||||
}
|
}
|
||||||
for _, v := range config {
|
stages := []Stage{}
|
||||||
|
for _, stage := range stagesConfig.Stages {
|
||||||
stages = append(stages, Stage{
|
stages = append(stages, Stage{
|
||||||
name: v[0],
|
Name: stage.Name,
|
||||||
executor: executorMap[v[1]],
|
Executor: executorMap[stage.Executor.Name],
|
||||||
executorCmd: model.Cmd{},
|
ExecutorCmd: model.Cmd{},
|
||||||
parser: parserMap[v[2]],
|
Parser: parserMap[stage.Parser.Name],
|
||||||
parserConfig: "",
|
ParserConfig: stage.Parser.With,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return stages
|
return stages
|
||||||
|
@ -38,10 +27,10 @@ func ParseStages() []Stage {
|
||||||
func Run(stages []Stage) []StageResult {
|
func Run(stages []Stage) []StageResult {
|
||||||
var parserResults []StageResult
|
var parserResults []StageResult
|
||||||
for _, stage := range stages {
|
for _, stage := range stages {
|
||||||
executorResult := stage.executor.Run(stage.executorCmd)
|
executorResult := stage.Executor.Run(stage.ExecutorCmd)
|
||||||
parserResult := stage.parser.Run(executorResult, stage.parserConfig)
|
parserResult := stage.Parser.Run(executorResult, stage.ParserConfig)
|
||||||
parserResults = append(parserResults, StageResult{
|
parserResults = append(parserResults, StageResult{
|
||||||
Name: stage.name,
|
Name: stage.Name,
|
||||||
ParserResult: parserResult,
|
ParserResult: parserResult,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user