mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
add judge-v3 progress type
This commit is contained in:
parent
629caca183
commit
1f0fe639a7
@ -161,8 +161,8 @@ TestcaseDetails
|
|||||||
``` typescript
|
``` typescript
|
||||||
interface {
|
interface {
|
||||||
type: TestcaseResultType;
|
type: TestcaseResultType;
|
||||||
time: number;
|
time: number; // ms
|
||||||
memory: number;
|
memory: number; // kb
|
||||||
input?: FileContent;
|
input?: FileContent;
|
||||||
output?: FileContent; // Output in test data
|
output?: FileContent; // Output in test data
|
||||||
scoringRate: number; // e.g. 0.5
|
scoringRate: number; // e.g. 0.5
|
||||||
@ -172,3 +172,12 @@ interface {
|
|||||||
systemMessage?: string;
|
systemMessage?: string;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
FileContent
|
||||||
|
|
||||||
|
``` typescript
|
||||||
|
interface FileContent {
|
||||||
|
content: string,
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
@ -204,21 +204,6 @@ type judgeParameter struct {
|
|||||||
// interaction
|
// interaction
|
||||||
}
|
}
|
||||||
|
|
||||||
type judgeProgress struct {
|
|
||||||
TaskID string `json:"taskId"`
|
|
||||||
Type int `json:"type"`
|
|
||||||
Progress judgeResultProgress `json:"progress"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type judgeResultProgress struct {
|
|
||||||
Subtasks []subtaskResult `json:"subtasks"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type subtaskResult struct {
|
|
||||||
Time uint64 `json:"time"`
|
|
||||||
Memory uint64 `json:"memory"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func newTask(c *Client, msg *judgeTask, ackID uint64) client.Task {
|
func newTask(c *Client, msg *judgeTask, ackID uint64) client.Task {
|
||||||
task := &types.JudgeTask{
|
task := &types.JudgeTask{
|
||||||
Type: types.Standard,
|
Type: types.Standard,
|
||||||
|
|||||||
97
client/syzojclient/progress.go
Normal file
97
client/syzojclient/progress.go
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
package syzojclient
|
||||||
|
|
||||||
|
type progressType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
progressStarted progressType = iota + 1
|
||||||
|
progressCompiled
|
||||||
|
progressProgress
|
||||||
|
progressFinished
|
||||||
|
progressReported
|
||||||
|
)
|
||||||
|
|
||||||
|
type taskStatus int
|
||||||
|
|
||||||
|
const (
|
||||||
|
statusWaiting taskStatus = iota
|
||||||
|
statusRunning
|
||||||
|
statusDone
|
||||||
|
statusFailed
|
||||||
|
statusSkipped
|
||||||
|
)
|
||||||
|
|
||||||
|
type errType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
errSystem errType = iota
|
||||||
|
errData
|
||||||
|
)
|
||||||
|
|
||||||
|
type testCaseResultType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
resultAccepted testCaseResultType = iota + 1
|
||||||
|
resultWrongAnswer
|
||||||
|
resultPartiallyCorrect
|
||||||
|
resultMemoryLimitExceeded
|
||||||
|
resultTimeLimitExceeded
|
||||||
|
resultOutputLimitExceeded
|
||||||
|
resultFileError
|
||||||
|
resultRuntimeError
|
||||||
|
resultJudgementFailed
|
||||||
|
resultInvalidInteraction
|
||||||
|
)
|
||||||
|
|
||||||
|
type result struct {
|
||||||
|
TaskID string `json:"taskId"`
|
||||||
|
Type progressType `json:"type"`
|
||||||
|
Progress progress `json:"progress"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type progress struct {
|
||||||
|
Status taskStatus `json:"status"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
|
||||||
|
Error *errType `json:"error"`
|
||||||
|
SystemMessage *string `json:"systemMessage"`
|
||||||
|
Compile *compileResult `json:"compile"`
|
||||||
|
Judge *judgeResult `json:"judge"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type judgeResult struct {
|
||||||
|
Subtasks []subtaskResult `json:"subtasks"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type subtaskResult struct {
|
||||||
|
Score *float64 `json:"score"`
|
||||||
|
Cases []caseResult `json:"cases"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type caseResult struct {
|
||||||
|
Status taskStatus `json:"status"`
|
||||||
|
Result *testcaseDetails `json:"result"`
|
||||||
|
Error *string `json:"errorMessage"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type testcaseDetails struct {
|
||||||
|
Status testCaseResultType `json:"type"`
|
||||||
|
Time uint64 `json:"time"` // ms
|
||||||
|
Memory uint64 `json:"memory"` // kb
|
||||||
|
Input *fileContent `json:"input"`
|
||||||
|
Output *fileContent `json:"output"`
|
||||||
|
ScoringRate float64 `json:"scoringRate"`
|
||||||
|
UserOutput *string `json:"userOutput"`
|
||||||
|
UserError *string `json:"userError"`
|
||||||
|
SPJMessage *string `json:"spjError"`
|
||||||
|
SystemMessage *string `json:"systemMessage"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type fileContent struct {
|
||||||
|
Content string `json:"content"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type compileResult struct {
|
||||||
|
Status taskStatus `json:"status"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
@ -16,6 +16,15 @@ type Task struct {
|
|||||||
ackID uint64
|
ackID uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTask creates new syzoj task
|
||||||
|
func NewTask(client *Client, task *types.JudgeTask, ackID uint64) *Task {
|
||||||
|
return &Task{
|
||||||
|
client: client,
|
||||||
|
task: task,
|
||||||
|
ackID: ackID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Param param
|
// Param param
|
||||||
func (t *Task) Param() *types.JudgeTask {
|
func (t *Task) Param() *types.JudgeTask {
|
||||||
return t.task
|
return t.task
|
||||||
|
|||||||
@ -51,11 +51,10 @@ func (j *Judger) run(done <-chan struct{}, t client.Task) *types.JudgeResult {
|
|||||||
t.Parsed(&pConf)
|
t.Parsed(&pConf)
|
||||||
|
|
||||||
// compile
|
// compile
|
||||||
compileRet := make(chan types.RunTaskResult, 1)
|
compileRet, err := j.Send(types.RunTask{
|
||||||
err = j.Send(types.RunTask{
|
|
||||||
Type: types.Compile,
|
Type: types.Compile,
|
||||||
Compile: (*types.CompileTask)(&p.Code),
|
Compile: (*types.CompileTask)(&p.Code),
|
||||||
}, compileRet)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errResult(err)
|
return errResult(err)
|
||||||
}
|
}
|
||||||
@ -126,9 +125,8 @@ func (pj *problemJudger) runSubtask(done <-chan struct{}, s *types.SubTask, sInd
|
|||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
c := s.Cases[i]
|
c := s.Cases[i]
|
||||||
rtC := make(chan types.RunTaskResult)
|
|
||||||
|
|
||||||
pj.Send(types.RunTask{
|
rtC, err := pj.Send(types.RunTask{
|
||||||
Type: pj.ProblemConfig.Type,
|
Type: pj.ProblemConfig.Type,
|
||||||
Exec: &types.ExecTask{
|
Exec: &types.ExecTask{
|
||||||
Exec: pj.Exec,
|
Exec: pj.Exec,
|
||||||
@ -137,24 +135,28 @@ func (pj *problemJudger) runSubtask(done <-chan struct{}, s *types.SubTask, sInd
|
|||||||
InputFile: c.Input,
|
InputFile: c.Input,
|
||||||
AnswerFile: c.Answer,
|
AnswerFile: c.Answer,
|
||||||
},
|
},
|
||||||
}, rtC)
|
})
|
||||||
|
|
||||||
rt := <-rtC
|
var ret types.TestCaseResult
|
||||||
|
if err != nil {
|
||||||
|
ret.Status = types.ProgressFailed
|
||||||
|
} else {
|
||||||
|
// receive result from queue
|
||||||
|
rt := <-rtC
|
||||||
|
|
||||||
// run task result -> test case result
|
// run task result -> test case result
|
||||||
ret := types.TestCaseResult{
|
ret.Status = types.ProgressStatus(rt.Status)
|
||||||
Status: types.ProgressStatus(rt.Status),
|
if execRt := rt.Exec; execRt != nil {
|
||||||
}
|
ret.Error = execRt.Error
|
||||||
if execRt := rt.Exec; execRt != nil {
|
ret.ScoreRate = execRt.ScoringRate
|
||||||
ret.Error = execRt.Error
|
ret.Time = execRt.Time
|
||||||
ret.ScoreRate = execRt.ScoringRate
|
ret.Memory = execRt.Memory
|
||||||
ret.Time = execRt.Time
|
ret.Input = execRt.Input
|
||||||
ret.Memory = execRt.Memory
|
ret.Answer = execRt.Answer
|
||||||
ret.Input = execRt.Input
|
ret.UserOutput = execRt.UserOutput
|
||||||
ret.Answer = execRt.Answer
|
ret.UserError = execRt.UserError
|
||||||
ret.UserOutput = execRt.UserOutput
|
ret.SPJOutput = execRt.SPJOutput
|
||||||
ret.UserError = execRt.UserError
|
}
|
||||||
ret.SPJOutput = execRt.SPJOutput
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// store result
|
// store result
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import (
|
|||||||
|
|
||||||
const buffSize = 512
|
const buffSize = 512
|
||||||
|
|
||||||
|
var _ taskqueue.Queue = &Queue{}
|
||||||
|
|
||||||
// Queue implements taskqueue by buffered go channel
|
// Queue implements taskqueue by buffered go channel
|
||||||
type Queue struct {
|
type Queue struct {
|
||||||
queue chan taskqueue.Task
|
queue chan taskqueue.Task
|
||||||
@ -20,12 +22,13 @@ func New() taskqueue.Queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send puts task into run queue
|
// Send puts task into run queue
|
||||||
func (q *Queue) Send(t types.RunTask, r chan<- types.RunTaskResult) error {
|
func (q *Queue) Send(t types.RunTask) (<-chan types.RunTaskResult, error) {
|
||||||
|
c := make(chan types.RunTaskResult, 1)
|
||||||
q.queue <- Task{
|
q.queue <- Task{
|
||||||
task: t,
|
task: t,
|
||||||
result: r,
|
result: c,
|
||||||
}
|
}
|
||||||
return nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReceiveC returns the underlying channel
|
// ReceiveC returns the underlying channel
|
||||||
|
|||||||
@ -4,8 +4,8 @@ import "github.com/criyle/go-judge/types"
|
|||||||
|
|
||||||
// Sender interface is used to send run task into message queue
|
// Sender interface is used to send run task into message queue
|
||||||
type Sender interface {
|
type Sender interface {
|
||||||
// Send used to initial a RPC call and receive result to channel (should have enough space)
|
// Send used to initial a RPC call and receive result from channel
|
||||||
Send(types.RunTask, chan<- types.RunTaskResult) error
|
Send(types.RunTask) (<-chan types.RunTaskResult, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receiver interface is used to receive run task from message queue
|
// Receiver interface is used to receive run task from message queue
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user