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
|
||||
interface {
|
||||
type: TestcaseResultType;
|
||||
time: number;
|
||||
memory: number;
|
||||
time: number; // ms
|
||||
memory: number; // kb
|
||||
input?: FileContent;
|
||||
output?: FileContent; // Output in test data
|
||||
scoringRate: number; // e.g. 0.5
|
||||
@ -172,3 +172,12 @@ interface {
|
||||
systemMessage?: string;
|
||||
}
|
||||
```
|
||||
|
||||
FileContent
|
||||
|
||||
``` typescript
|
||||
interface FileContent {
|
||||
content: string,
|
||||
name: string
|
||||
}
|
||||
```
|
||||
|
||||
@ -204,21 +204,6 @@ type judgeParameter struct {
|
||||
// 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 {
|
||||
task := &types.JudgeTask{
|
||||
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
|
||||
}
|
||||
|
||||
// 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
|
||||
func (t *Task) Param() *types.JudgeTask {
|
||||
return t.task
|
||||
|
||||
@ -51,11 +51,10 @@ func (j *Judger) run(done <-chan struct{}, t client.Task) *types.JudgeResult {
|
||||
t.Parsed(&pConf)
|
||||
|
||||
// compile
|
||||
compileRet := make(chan types.RunTaskResult, 1)
|
||||
err = j.Send(types.RunTask{
|
||||
compileRet, err := j.Send(types.RunTask{
|
||||
Type: types.Compile,
|
||||
Compile: (*types.CompileTask)(&p.Code),
|
||||
}, compileRet)
|
||||
})
|
||||
if err != nil {
|
||||
return errResult(err)
|
||||
}
|
||||
@ -126,9 +125,8 @@ func (pj *problemJudger) runSubtask(done <-chan struct{}, s *types.SubTask, sInd
|
||||
defer wg.Done()
|
||||
|
||||
c := s.Cases[i]
|
||||
rtC := make(chan types.RunTaskResult)
|
||||
|
||||
pj.Send(types.RunTask{
|
||||
rtC, err := pj.Send(types.RunTask{
|
||||
Type: pj.ProblemConfig.Type,
|
||||
Exec: &types.ExecTask{
|
||||
Exec: pj.Exec,
|
||||
@ -137,14 +135,17 @@ func (pj *problemJudger) runSubtask(done <-chan struct{}, s *types.SubTask, sInd
|
||||
InputFile: c.Input,
|
||||
AnswerFile: c.Answer,
|
||||
},
|
||||
}, 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
|
||||
ret := types.TestCaseResult{
|
||||
Status: types.ProgressStatus(rt.Status),
|
||||
}
|
||||
ret.Status = types.ProgressStatus(rt.Status)
|
||||
if execRt := rt.Exec; execRt != nil {
|
||||
ret.Error = execRt.Error
|
||||
ret.ScoreRate = execRt.ScoringRate
|
||||
@ -156,6 +157,7 @@ func (pj *problemJudger) runSubtask(done <-chan struct{}, s *types.SubTask, sInd
|
||||
ret.UserError = execRt.UserError
|
||||
ret.SPJOutput = execRt.SPJOutput
|
||||
}
|
||||
}
|
||||
|
||||
// store result
|
||||
result.Cases[i] = ret
|
||||
|
||||
@ -7,6 +7,8 @@ import (
|
||||
|
||||
const buffSize = 512
|
||||
|
||||
var _ taskqueue.Queue = &Queue{}
|
||||
|
||||
// Queue implements taskqueue by buffered go channel
|
||||
type Queue struct {
|
||||
queue chan taskqueue.Task
|
||||
@ -20,12 +22,13 @@ func New() taskqueue.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{
|
||||
task: t,
|
||||
result: r,
|
||||
result: c,
|
||||
}
|
||||
return nil
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// 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
|
||||
type Sender interface {
|
||||
// Send used to initial a RPC call and receive result to channel (should have enough space)
|
||||
Send(types.RunTask, chan<- types.RunTaskResult) error
|
||||
// Send used to initial a RPC call and receive result from channel
|
||||
Send(types.RunTask) (<-chan types.RunTaskResult, error)
|
||||
}
|
||||
|
||||
// Receiver interface is used to receive run task from message queue
|
||||
|
||||
Loading…
Reference in New Issue
Block a user