JOJ3/internal/parser/resultstatus/parser.go
张泊明518370910136 fa649fcabe
Some checks failed
submodules sync / sync (push) Successful in 42s
build / build (push) Failing after 1m40s
build / trigger-build-image (push) Has been skipped
feat(parser/resultstatus): conf force quit on not accepted
2024-11-01 18:39:36 -04:00

46 lines
965 B
Go

package resultstatus
import (
"fmt"
"github.com/criyle/go-judge/envexec"
"github.com/joint-online-judge/JOJ3/internal/stage"
)
type Conf struct {
Score int
Comment string
ForceQuitOnNotAccepted bool `default:"false"`
}
type ResultStatus struct{}
func (*ResultStatus) Run(results []stage.ExecutorResult, confAny any) (
[]stage.ParserResult, bool, error,
) {
conf, err := stage.DecodeConf[Conf](confAny)
if err != nil {
return nil, true, err
}
score := conf.Score
forceQuit := false
var res []stage.ParserResult
for _, result := range results {
comment := conf.Comment
if result.Status != stage.Status(envexec.StatusAccepted) {
score = 0
comment = fmt.Sprintf(
"Unexpected executor status: %s.", result.Status,
)
if conf.ForceQuitOnNotAccepted {
forceQuit = true
}
}
res = append(res, stage.ParserResult{
Score: score,
Comment: comment,
})
}
return res, forceQuit, nil
}