github.com/LanceLRQ/deer-common@v0.0.9-0.20210319081233-e8222ac018a8/structs/judge.go (about)

     1  package structs
     2  
     3  import (
     4  	"encoding/xml"
     5  	"github.com/LanceLRQ/deer-common/logger"
     6  )
     7  
     8  // 评测配置信息
     9  type JudgeConfiguration struct {
    10  	TestCases     []TestCase                    `json:"test_cases"`      // Test cases
    11  	TimeLimit     int                           `json:"time_limit"`      // Time limit (ms)
    12  	MemoryLimit   int                           `json:"memory_limit"`    // Memory limit (KB)
    13  	RealTimeLimit int                           `json:"real_time_limit"` // Real Time Limit (ms) (optional)
    14  	FileSizeLimit int                           `json:"file_size_limit"` // File Size Limit (bytes) (optional)
    15  	Uid           int                           `json:"uid"`             // User id (optional)
    16  	StrictMode    bool                          `json:"strict_mode"`     // Strict Mode (if close, PE will be ignore)
    17  	SpecialJudge  SpecialJudgeOptions           `json:"special_judge"`   // Special Judge Options
    18  	Limitation    map[string]JudgeResourceLimit `json:"limitation"`      // Limitation
    19  	Problem       ProblemContent                `json:"problem"`         // Problem Info
    20  	TestLib       TestlibOptions                `json:"testlib"`         // testlib设置
    21  	AnswerCases   []AnswerCase                  `json:"answer_cases"`    // Answer cases (用于生成Output)
    22  	ConfigDir     string                        `json:"-"`               // 内部字段:config文件所在目录绝对路径
    23  }
    24  
    25  // 答案代码样例
    26  // 优先使用Content访问,其次使用FileName
    27  type AnswerCase struct {
    28  	Name     string `json:"name"`      // Case name
    29  	FileName string `json:"file_name"` // code file name
    30  	Language string `json:"language"`  // code language, default is 'auto'
    31  	Content  string `json:"content"`   // code content (optional)
    32  }
    33  
    34  // 测试数据
    35  type TestCase struct {
    36  	Handle           string `json:"handle"`            // Identifier
    37  	Order            int    `json:"order"`             // Order (ASC)
    38  	Name             string `json:"name"`              // Testcase name
    39  	Input            string `json:"input"`             // Testcase input file path
    40  	Output           string `json:"output"`            // Testcase output file path
    41  	Visible          bool   `json:"visible"`           // Is visible(for oj)
    42  	Enabled          bool   `json:"enabled"`           // Is enabled
    43  	UseGenerator     bool   `json:"use_genarator"`     // Use generator
    44  	Generator        string `json:"generator"`         // Generator script
    45  	ValidatorVerdict bool   `json:"validator_verdict"` // Testlib validator's result
    46  	ValidatorComment string `json:"validator_comment"` // Testlib validator's output
    47  }
    48  
    49  // 特殊评测设置
    50  type SpecialJudgeOptions struct {
    51  	Name               string                    `json:"name"`                 // Name, default is "checker"
    52  	Mode               int                       `json:"mode"`                 // Mode;0-Disabled;1-Normal;2-Interactor
    53  	CheckerLang        string                    `json:"checker_lang"`         // Checker languages, support gcc, g++(default) and golang, not support auto!
    54  	Checker            string                    `json:"checker"`              // Checker file path (Use code file is better then compiled binary!)
    55  	RedirectProgramOut bool                      `json:"redirect_program_out"` // Redirect target program's STDOUT to checker's STDIN (checker mode). if not, redirect testcase-in file to checker's STDIN
    56  	TimeLimit          int                       `json:"time_limit"`           // Time limit (ms)
    57  	MemoryLimit        int                       `json:"memory_limit"`         // Memory limit (kb)
    58  	UseTestlib         bool                      `json:"use_testlib"`          // If use testlib, checker will only support c++
    59  	CheckerCases       []SpecialJudgeCheckerCase `json:"checker_cases"`        // Special Judge checker cases (for Testlib, exclude interactor mode)
    60  }
    61  
    62  // 特判检查器样例
    63  // Special Judge checker case item
    64  type SpecialJudgeCheckerCase struct {
    65  	Input           string `json:"input"`            // Input (1k Limit)
    66  	Output          string `json:"output"`           // Output (1k Limit)
    67  	Answer          string `json:"answer"`           // Answer (1k Limit)
    68  	Verdict         bool   `json:"verdict"`          // Is verdict? (下边俩是否相同)
    69  	ExpectedVerdict int    `json:"expected_verdict"` // Expected judge result (flag) (期望的判定结果)
    70  	CheckerVerdict  int    `json:"checker_verdict"`  // (testlib/classical)checker's judge result (flag) (检查器的判定结果)
    71  	CheckerComment  string `json:"checker_comment"`  // (testlib/classical) checker's output (检查器输出的信息)
    72  }
    73  
    74  // TestLib设置 (只支持c++版本的testlib)
    75  // Testlib Options (we only support c++ verion)
    76  type TestlibOptions struct {
    77  	Version        string                 `json:"version"`        // Testlib version (预留,不太考虑实现)
    78  	Validator      string                 `json:"validator"`      // Validator file
    79  	ValidatorName  string                 `json:"validator_name"` // Validator name (compile target name)
    80  	Generators     []TestlibGenerator     `json:"generators"`     // Validator cases
    81  	ValidatorCases []TestlibValidatorCase `json:"validator_case"` // Validator cases
    82  	// 未来这边可以加入对拍(stress)功能
    83  }
    84  
    85  // Testlib Generator
    86  type TestlibGenerator struct {
    87  	Name   string `json:"name"`   // Generator name
    88  	Source string `json:"source"` // Source code file
    89  }
    90  
    91  // Testlib validator 样例
    92  type TestlibValidatorCase struct {
    93  	Input            string `json:"input"`             // Input (1k Limit)
    94  	Verdict          bool   `json:"verdict"`           // Is verdict? (下边俩是否相同)
    95  	ExpectedVerdict  bool   `json:"expected_verdict"`  // Expected result
    96  	ValidatorVerdict bool   `json:"validator_verdict"` // Testlib validator's result
    97  	ValidatorComment string `json:"validator_comment"` // Testlib validator's output
    98  }
    99  
   100  // 评测结果信息
   101  type JudgeResult struct {
   102  	SessionID   string                `json:"session_id"`   // Judge Session Id
   103  	JudgeResult int                   `json:"judge_result"` // Judge result flag number
   104  	TimeUsed    int                   `json:"time_used"`    // Maximum time used
   105  	MemoryUsed  int                   `json:"memory_used"`  // Maximum memory used
   106  	TestCases   []TestCaseResult      `json:"test_cases"`   // Testcase Results
   107  	ReInfo      string                `json:"re_info"`      // ReInfo when Runtime Error or special judge Runtime Error
   108  	SeInfo      string                `json:"se_info"`      // SeInfo when System Error
   109  	CeInfo      string                `json:"ce_info"`      // CeInfo when Compile Error
   110  	JudgeLogs   []logger.JudgeLogItem `json:"judge_logs"`   // Judge Logs
   111  }
   112  
   113  // 测试数据运行结果
   114  type TestCaseResult struct {
   115  	Handle       string `json:"handle"`        // Identifier
   116  	Input        string `json:"-"`             // Testcase input file path (internal)
   117  	Output       string `json:"-"`             // Testcase output file path (internal)
   118  	ProgramOut   string `json:"program_out"`   // Program-stdout file path
   119  	ProgramError string `json:"program_error"` // Program-stderr file path
   120  
   121  	CheckerOut    string `json:"checker_out"`    // Special judge checker's stdout
   122  	CheckerError  string `json:"checker_error"`  // Special judge checker's stderr
   123  	CheckerReport string `json:"checker_report"` // Special judge checker's report file
   124  
   125  	JudgeResult    int `json:"judge_result"`    // Judge result flag number
   126  	PartiallyScore int `json:"partially_score"` // Testlib Partially Score or Math.floor(SameLines / TotalLines)
   127  
   128  	TextDiffLog string `json:"text_diff_log"` // Text Checkup Log
   129  	TimeUsed    int    `json:"time_used"`     // Maximum time used
   130  	MemoryUsed  int    `json:"memory_used"`   // Maximum memory used
   131  	ReSignum    int    `json:"re_signal_num"` // Runtime error signal number
   132  	SameLines   int    `json:"same_lines"`    // Same lines when WA
   133  	TotalLines  int    `json:"total_lines"`   // Total lines when WA
   134  	ReInfo      string `json:"re_info"`       // ReInfo when Runtime Error or special judge Runtime Error
   135  	SeInfo      string `json:"se_info"`       // SeInfo when System Error
   136  	CeInfo      string `json:"ce_info"`       // CeInfo when Compile Error
   137  
   138  	SPJExitCode   int    `json:"spj_exit_code"`     // Special judge exit code
   139  	SPJTimeUsed   int    `json:"spj_time_used"`     // Special judge maximum time used
   140  	SPJMemoryUsed int    `json:"spj_memory_used"`   // Special judge maximum memory used
   141  	SPJReSignum   int    `json:"spj_re_signal_num"` // Special judge runtime error signal number
   142  	SPJMsg        string `json:"spj_msg"`           // Special judge checker  msg
   143  }
   144  
   145  // 评测资源限制信息
   146  type JudgeResourceLimit struct {
   147  	TimeLimit     int `json:"time_limit"`      // Time limit (ms)
   148  	MemoryLimit   int `json:"memory_limit"`    // Memory limit (KB)
   149  	RealTimeLimit int `json:"real_time_limit"` // Real Time Limit (ms) (optional)
   150  	FileSizeLimit int `json:"file_size_limit"` // File Size Limit (bytes) (optional)
   151  }
   152  
   153  type TestlibCheckerResult struct {
   154  	XMLName     xml.Name `xml:"result"`
   155  	Outcome     string   `xml:"outcome,attr"`
   156  	PcType      string   `xml:"pctype,attr"`
   157  	Description string   `xml:",innerxml"`
   158  }