mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
code cleanup
This commit is contained in:
parent
e148a9910d
commit
d6cec42720
@ -1,7 +1,6 @@
|
||||
package syzojclient
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
@ -228,8 +227,6 @@ func newTask(c *Client, msg *judgeTask, ackID uint64) client.Task {
|
||||
MemoryLimit: msg.Content.Param.MemoryLimit << 10,
|
||||
}
|
||||
|
||||
log.Println(msg)
|
||||
|
||||
return &Task{
|
||||
client: c,
|
||||
task: task,
|
||||
|
||||
@ -1 +0,0 @@
|
||||
package syzojclient
|
||||
@ -19,7 +19,7 @@ loop:
|
||||
for {
|
||||
select {
|
||||
case t := <-c:
|
||||
t.Progress(&types.JudgeProgress{types.ProgressStart, ""})
|
||||
t.Progress(&types.JudgeProgress{Type: types.ProgressStart, Message: ""})
|
||||
rt := j.run(done, t)
|
||||
t.Finish(rt)
|
||||
|
||||
@ -53,7 +53,7 @@ func (j *Judger) run(done <-chan struct{}, t client.Task) *types.JudgeResult {
|
||||
// compile
|
||||
compileRet := make(chan types.RunTaskResult)
|
||||
err = j.Send(types.RunTask{
|
||||
Type: "compile",
|
||||
Type: types.Compile,
|
||||
Language: p.Language,
|
||||
Code: p.Code,
|
||||
ExtraFiles: pconf.ExtraFiles,
|
||||
|
||||
@ -1 +0,0 @@
|
||||
package socketio
|
||||
@ -16,7 +16,7 @@ const maxOutput = 4 << 20 // 4M
|
||||
|
||||
func (r *Runner) run(done <-chan struct{}, task *types.RunTask) *types.RunTaskResult {
|
||||
t := language.TypeExec
|
||||
if task.Type == "compile" {
|
||||
if task.Type == types.Compile {
|
||||
t = language.TypeCompile
|
||||
}
|
||||
param := r.Language.Get(task.Language, t)
|
||||
@ -42,6 +42,9 @@ func (r *Runner) run(done <-chan struct{}, task *types.RunTask) *types.RunTaskRe
|
||||
// copyin source code for compile or exec files for exec
|
||||
if t == language.TypeCompile {
|
||||
copyIn[param.SourceFileName] = memfile.New("source", []byte(task.Code))
|
||||
for _, f := range task.ExtraFiles {
|
||||
copyIn[f.Name()] = f
|
||||
}
|
||||
} else {
|
||||
for _, f := range task.ExecFiles {
|
||||
copyIn[f.Name()] = f
|
||||
@ -50,7 +53,7 @@ func (r *Runner) run(done <-chan struct{}, task *types.RunTask) *types.RunTaskRe
|
||||
|
||||
// copyout files: If compile read compiled files
|
||||
var copyOut []string
|
||||
if task.Type == "compile" {
|
||||
if task.Type == types.Compile {
|
||||
copyOut = param.CompiledFileNames
|
||||
}
|
||||
|
||||
@ -95,7 +98,7 @@ func (r *Runner) run(done <-chan struct{}, task *types.RunTask) *types.RunTaskRe
|
||||
|
||||
// compile copyout
|
||||
var exec []file.File
|
||||
if task.Type == "compile" {
|
||||
if task.Type == types.Compile {
|
||||
for _, n := range param.CompiledFileNames {
|
||||
exec = append(exec, r0.Files[n])
|
||||
}
|
||||
@ -107,7 +110,7 @@ func (r *Runner) run(done <-chan struct{}, task *types.RunTask) *types.RunTaskRe
|
||||
spjOutput []byte
|
||||
scoreRate float64 = 1
|
||||
)
|
||||
if task.Type != "compile" {
|
||||
if task.Type != types.Compile {
|
||||
ans, err := task.AnswerFile.Content()
|
||||
if err != nil {
|
||||
return errResult("FileError", err.Error())
|
||||
|
||||
9
types/const.go
Normal file
9
types/const.go
Normal file
@ -0,0 +1,9 @@
|
||||
package types
|
||||
|
||||
// run_task / problem types
|
||||
const (
|
||||
Compile = "compile"
|
||||
Standard = "standard"
|
||||
Interactive = "interactive"
|
||||
AnswerSubmit = "answer_submit"
|
||||
)
|
||||
@ -2,6 +2,13 @@ package types
|
||||
|
||||
import "github.com/criyle/go-judge/file"
|
||||
|
||||
// SourceCode defines source code with its language
|
||||
type SourceCode struct {
|
||||
Language string
|
||||
Code file.File
|
||||
ExtraFiles []file.File
|
||||
}
|
||||
|
||||
// JudgeTask contains task received from server
|
||||
type JudgeTask struct {
|
||||
Type string // defines problem type
|
||||
@ -50,9 +57,11 @@ type JudgeCaseResult struct {
|
||||
ScoreRate float64
|
||||
Error string
|
||||
|
||||
// Details
|
||||
Time uint64
|
||||
Memory uint64
|
||||
// detail stats
|
||||
Time uint64 // ms
|
||||
Memory uint64 // kb
|
||||
|
||||
// detail outputs
|
||||
Input []byte
|
||||
Answer []byte
|
||||
UserOutput []byte
|
||||
|
||||
@ -4,16 +4,13 @@ import "github.com/criyle/go-judge/file"
|
||||
|
||||
// ProblemConfig defines a problem
|
||||
type ProblemConfig struct {
|
||||
Type string
|
||||
Subtasks []SubTask
|
||||
Type string // Problem type
|
||||
Subtasks []SubTask // SubTasks
|
||||
|
||||
SpjLanguage string
|
||||
SpjCode *file.File
|
||||
SPJ SourceCode // Special Judge
|
||||
Interactor SourceCode // Interactor
|
||||
|
||||
InteractorLanguage string
|
||||
InteractorCode *file.File
|
||||
|
||||
ExtraFiles []file.File
|
||||
ExtraFiles []file.File // Extra Files
|
||||
}
|
||||
|
||||
// SubTask defines multiple judger tasks
|
||||
|
||||
@ -5,10 +5,10 @@ import "github.com/criyle/go-judge/file"
|
||||
// RunTask is used to send task into RunQueue,
|
||||
// if taskqueue is a remote queue, taskqueue need to store / retrive files
|
||||
type RunTask struct {
|
||||
Type string
|
||||
Type string // compile / standard / interactive / answer_submit
|
||||
Language string // task programming language
|
||||
|
||||
// Used for compile task
|
||||
Language string
|
||||
Code string
|
||||
ExtraFiles []file.File
|
||||
|
||||
@ -20,12 +20,10 @@ type RunTask struct {
|
||||
AnswerFile file.File
|
||||
|
||||
// Used for standard run task
|
||||
SpjLanguage string
|
||||
SpjExecFiles []file.File
|
||||
SPJ SourceCode
|
||||
|
||||
// Used for interaction run task
|
||||
InteractorLanguage string
|
||||
InteractorExecFiles []file.File
|
||||
Interactor SourceCode
|
||||
|
||||
// Used for answer submission run task
|
||||
UserAnswer file.File
|
||||
@ -33,18 +31,26 @@ type RunTask struct {
|
||||
|
||||
// RunTaskResult return the result for run task RPC
|
||||
type RunTaskResult struct {
|
||||
// status
|
||||
Status string
|
||||
|
||||
// score
|
||||
ScoringRate float64
|
||||
|
||||
// error
|
||||
Error string
|
||||
|
||||
// compile result
|
||||
ExecFiles []file.File
|
||||
// details
|
||||
Time uint64 // ms
|
||||
Memory uint64 // kb
|
||||
Input []byte
|
||||
Answer []byte
|
||||
UserOutput []byte
|
||||
UserError []byte
|
||||
SpjOutput []byte
|
||||
ScoringRate float64
|
||||
|
||||
// detail stats
|
||||
Time uint64 // ms
|
||||
Memory uint64 // kb
|
||||
|
||||
// detail outputs
|
||||
Input []byte
|
||||
Answer []byte
|
||||
UserOutput []byte
|
||||
UserError []byte
|
||||
SpjOutput []byte
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user