JOJ3/internal/parser/sample/parser.go
张泊明518370910136 e68de4fcc5
Some checks failed
build / build (push) Failing after 6s
build / trigger-build-image (push) Has been skipped
submodules sync / sync (push) Has been cancelled
feat(parser): only check result status in resultstatus and healthcheck parser
2024-11-03 01:59:53 -04:00

50 lines
1.1 KiB
Go

package sample
import (
"encoding/json"
"fmt"
"github.com/joint-online-judge/JOJ3/internal/stage"
"github.com/joint-online-judge/JOJ3/pkg/sample"
)
type Conf struct {
Score int
Comment string
Stdout string `default:"stdout"`
Stderr string `default:"stderr"`
}
type Sample struct{}
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
stdout := executorResult.Files[conf.Stdout]
// stderr := executorResult.Files[conf.Stderr]
var sampleResult sample.Result
err := json.Unmarshal([]byte(stdout), &sampleResult)
if err != nil {
return stage.ParserResult{
Score: 0,
Comment: fmt.Sprintf("Failed to parse result: %s", err),
}
}
return stage.ParserResult{
Score: sampleResult.Score + conf.Score,
Comment: sampleResult.Comment + conf.Comment,
}
}
func (*Sample) Run(results []stage.ExecutorResult, confAny any) (
[]stage.ParserResult, bool, error,
) {
conf, err := stage.DecodeConf[Conf](confAny)
if err != nil {
return nil, true, err
}
var res []stage.ParserResult
for _, result := range results {
res = append(res, Parse(result, *conf))
}
return res, false, nil
}