mirror of
https://github.com/QingdaoU/JudgeServer.git
synced 2025-11-04 14:50:01 +08:00
parent
2da659edcb
commit
45125eb015
@ -12,6 +12,20 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Data 成员的类型参考 https://github.com/QingdaoU/Judger/blob/b6414e7a6715eb013b1ffeb7cfb04626a3ff5b4e/src/runner.h#L73
|
||||||
|
type Data struct {
|
||||||
|
CpuTime int
|
||||||
|
Result int
|
||||||
|
Memory int
|
||||||
|
RealTime int
|
||||||
|
Signal int
|
||||||
|
Error int
|
||||||
|
ExitCode int
|
||||||
|
OutputMd5 string
|
||||||
|
Output interface{}
|
||||||
|
TestCase string
|
||||||
|
}
|
||||||
|
|
||||||
type Resp struct {
|
type Resp struct {
|
||||||
RespData interface{} `json:"data"`
|
RespData interface{} `json:"data"`
|
||||||
RespErr string `json:"err"`
|
RespErr string `json:"err"`
|
||||||
@ -25,6 +39,50 @@ func (resp *Resp) Data() interface{} {
|
|||||||
return resp.RespData
|
return resp.RespData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (resp *Resp) StringData() string {
|
||||||
|
if resp == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
str, _ := resp.RespData.(string)
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
func (resp *Resp) SliceData() []*Data {
|
||||||
|
if resp == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
slice, _ := resp.RespData.([]interface{})
|
||||||
|
data := make([]*Data, 0, len(slice))
|
||||||
|
for _, s := range slice {
|
||||||
|
item, ok := s.(map[string]interface{})
|
||||||
|
if ok {
|
||||||
|
cpuTimeF64, _ := item["cpu_time"].(float64)
|
||||||
|
resultF64, _ := item["result"].(float64)
|
||||||
|
memoryF64, _ := item["memory"].(float64)
|
||||||
|
realTimeF64, _ := item["real_time"].(float64)
|
||||||
|
signalF64, _ := item["signal"].(float64)
|
||||||
|
errorF64, _ := item["error"].(float64)
|
||||||
|
exitCodeF64, _ := item["exit_code"].(float64)
|
||||||
|
outputMd5, _ := item["output_md5"].(string)
|
||||||
|
testCase, _ := item["test_case"].(string)
|
||||||
|
data = append(data, &Data{
|
||||||
|
CpuTime: int(cpuTimeF64),
|
||||||
|
Result: int(resultF64),
|
||||||
|
Memory: int(memoryF64),
|
||||||
|
RealTime: int(realTimeF64),
|
||||||
|
Signal: int(signalF64),
|
||||||
|
Error: int(errorF64),
|
||||||
|
ExitCode: int(exitCodeF64),
|
||||||
|
OutputMd5: outputMd5,
|
||||||
|
Output: item["output"],
|
||||||
|
TestCase: testCase,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
func (resp *Resp) Err() error {
|
func (resp *Resp) Err() error {
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -79,29 +79,29 @@ func main() {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
fmt.Println("cpp_judge")
|
fmt.Println("cpp_judge")
|
||||||
resp, err = client.JudgeWithRequest(&judge.JudgeRequest{
|
resp, _ = client.JudgeWithRequest(&judge.JudgeRequest{
|
||||||
Src: cppSrc,
|
Src: cppSrc,
|
||||||
LanguageConfig: judge.CPPLangConfig,
|
LanguageConfig: judge.CPPLangConfig,
|
||||||
MaxCpuTime: 1000,
|
MaxCpuTime: 1000,
|
||||||
MaxMemory: 128 * 1024 * 1024,
|
MaxMemory: 128 * 1024 * 1024,
|
||||||
TestCaseId: "normal",
|
TestCaseId: "normal",
|
||||||
})
|
})
|
||||||
fmt.Println(resp, err)
|
printSliceData(resp.SliceData())
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
fmt.Println("java_judge")
|
fmt.Println("java_judge")
|
||||||
resp, err = client.JudgeWithRequest(&judge.JudgeRequest{
|
resp, _ = client.JudgeWithRequest(&judge.JudgeRequest{
|
||||||
Src: javaSrc,
|
Src: javaSrc,
|
||||||
LanguageConfig: judge.JavaLangConfig,
|
LanguageConfig: judge.JavaLangConfig,
|
||||||
MaxCpuTime: 1000,
|
MaxCpuTime: 1000,
|
||||||
MaxMemory: 256 * 1024 * 1024,
|
MaxMemory: 256 * 1024 * 1024,
|
||||||
TestCaseId: "normal",
|
TestCaseId: "normal",
|
||||||
})
|
})
|
||||||
fmt.Println(resp, err)
|
printSliceData(resp.SliceData())
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
fmt.Println("c_spj_judge")
|
fmt.Println("c_spj_judge")
|
||||||
resp, err = client.JudgeWithRequest(&judge.JudgeRequest{
|
resp, _ = client.JudgeWithRequest(&judge.JudgeRequest{
|
||||||
Src: cSrc,
|
Src: cSrc,
|
||||||
LanguageConfig: judge.CLangConfig,
|
LanguageConfig: judge.CLangConfig,
|
||||||
MaxCpuTime: 1000,
|
MaxCpuTime: 1000,
|
||||||
@ -112,27 +112,48 @@ func main() {
|
|||||||
SPJCompileConfig: judge.CLangSPJCompile,
|
SPJCompileConfig: judge.CLangSPJCompile,
|
||||||
SPJSrc: cSPJSrc,
|
SPJSrc: cSPJSrc,
|
||||||
})
|
})
|
||||||
fmt.Println(resp, err)
|
printSliceData(resp.SliceData())
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
fmt.Println("py2_judge")
|
fmt.Println("py2_judge")
|
||||||
resp, err = client.JudgeWithRequest(&judge.JudgeRequest{
|
resp, _ = client.JudgeWithRequest(&judge.JudgeRequest{
|
||||||
Src: py2Src,
|
Src: py2Src,
|
||||||
LanguageConfig: judge.PY2LangConfig,
|
LanguageConfig: judge.PY2LangConfig,
|
||||||
MaxCpuTime: 1000,
|
MaxCpuTime: 1000,
|
||||||
MaxMemory: 128 * 1024 * 1024,
|
MaxMemory: 128 * 1024 * 1024,
|
||||||
TestCaseId: "normal",
|
TestCaseId: "normal",
|
||||||
})
|
})
|
||||||
fmt.Println(resp, err)
|
printSliceData(resp.SliceData())
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
fmt.Println("py3_judge")
|
fmt.Println("py3_judge")
|
||||||
resp, err = client.JudgeWithRequest(&judge.JudgeRequest{
|
resp, _ = client.JudgeWithRequest(&judge.JudgeRequest{
|
||||||
Src: py3Src,
|
Src: py3Src,
|
||||||
LanguageConfig: judge.PY3LangConfig,
|
LanguageConfig: judge.PY3LangConfig,
|
||||||
MaxCpuTime: 1000,
|
MaxCpuTime: 1000,
|
||||||
MaxMemory: 128 * 1024 * 1024,
|
MaxMemory: 128 * 1024 * 1024,
|
||||||
TestCaseId: "normal",
|
TestCaseId: "normal",
|
||||||
})
|
})
|
||||||
fmt.Println(resp, err)
|
printSliceData(resp.SliceData())
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
// CompileError example
|
||||||
|
fmt.Println("CompileError example")
|
||||||
|
resp, err = client.JudgeWithRequest(&judge.JudgeRequest{
|
||||||
|
Src: "this bad code",
|
||||||
|
LanguageConfig: judge.JavaLangConfig,
|
||||||
|
MaxCpuTime: 1000,
|
||||||
|
MaxMemory: 256 * 1024 * 1024,
|
||||||
|
TestCaseId: "normal",
|
||||||
|
})
|
||||||
|
// fmt.Println(resp.RespErr) // "CompileError"
|
||||||
|
fmt.Println(resp.StringData()) // 错误信息
|
||||||
|
}
|
||||||
|
|
||||||
|
func printSliceData(slice []*judge.Data) {
|
||||||
|
fmt.Print("[\n")
|
||||||
|
for _, item := range slice {
|
||||||
|
fmt.Printf("\t%#v,\n", item)
|
||||||
|
}
|
||||||
|
fmt.Print("]\n")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user