problem

package
v0.0.33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package problem is a package for test problem manipulation.

Overview

A test problem is store in a directory, for example, "dir", with following structure:

|-dir/problem.json
|-dir/data/
|---dir/tests/
|---dir/subtasks/
|---dir/static/
|-dir/workflow/ stores test workflow
|---dir/workflow/graph.json stores the workflow graph
|-dir/statement/ stores statement files
|---dir/statement/s.[lang][id].md stores statement files
|---dir/statement/t.[lang][id].md stores tutorial files
|---dir/statement/xxx stores assert files
|-dir/patch/ stores added files

Tests

Usually a problem contains multiple testcases, whose data are stored in dir/data/tests/, since a contestant's submission should be tested enoughly before being considered correct. All testcases have the same fields.

Testcase may have "_score" field, whose value is either a number string or "average".

Subtask

To better assign points to testcases with different intensity, it's common to set up several subtasks for the problem, each containing a series of testcases.

Note that if subtask is enabled, independent testcases (i.e. not in a subtask) are not allowed.

If subtask data occured (at least one field, at least one record), subtask is enabled.

For some problem, different subtasks use different files to test contestant's submission, for example, checker or input generator. Thus these data are stored in dir/data/tests/. Again, all subtasks' data have the same fields.

Subtask may have "_score" field, whose value is a number string.

For problem enabling subtask, its testcase and subtask both contain "_subtaskid" field, determining which subtask the testcase belongs to.

Static Data

Common data are stored in dir/data/static/ shared by all testcases.

Testcase Score

Score of a testcase is calculated as follows:

If subtask is enabled, testcase's "_score" is ignored, its score is {subtask score} / {number of tests in this subtask}.

Otherwise, if "average" is specified for "_score" field, its score is {problem total score} / {number of testcases}. Else its "_score" should be a number string, denoting its score.

Statement

Markdown is the standard format of statement. Other formats may be supported in the future.

Workflow

See github.com/super-yaoj/yaoj-core/workflow.

Problem gives workflow 4 datagroups naming "testcase", "subtask", "static" and "submission" respectively.

Index

Constants

This section is empty.

Variables

Functions

func GuessLang

func GuessLang(lang string) string

猜测 locale 与支持的语言中匹配的语言。如果是 Und 那么返回第一个语言(默认)

Types

type CalcMethod

type CalcMethod int

子任务中测试点得分的汇总方式

const (
	// default
	Mmin CalcMethod = iota
	Mmax
	Msum
)

type DataInfo

type DataInfo struct {
	Fullscore float64
	TestdataInfo
	Pretest TestdataInfo
	Extra   TestdataInfo
	// 静态文件
	Static     map[string]string //other properties of data
	Hackable   bool
	HackFields map[string]SubmLimit
}

type InmemoryFile added in v0.0.24

type InmemoryFile struct {
	Name string
	Ctnt []byte
}

存储文件的路径

type ProbData

type ProbData struct {
	// Usually 100.
	// Full score can be used to determine the point of testcase
	Fullscore float64

	// pretest 常用于样例评测
	Pretest ProbTestdata
	// 额外数据例如 hack 数据
	Extra ProbTestdata
	// 题目本身数据
	ProbTestdata
	// "submission" configuration
	Submission SubmConf
	// "static"
	Static record
	// "statement"
	// Statement has 1 record. "s.{lang}", "t.{lang}" represents statement and
	// tutorial respectively. "_tl" "_ml" "_ol" denotes cpu time limit (ms),
	// real memory limit (MB) and output limit (MB) respectively.
	// Others are just filename.
	Statement record
	// hack 时 tests 里需要提交的字段,以及其对应的限制
	// 为 nil 表示不支持 hack
	HackFields SubmConf
	// 由 tests 的字段映射到 workflow 的中间输出文件
	// 为 nil 表示不支持 hack
	HackIOMap map[string]workflow.Outbound
	// contains filtered or unexported fields
}

Problem data module

func LoadProbData

func LoadProbData(dir string) (*ProbData, error)

load problem from a dir

func NewProbData

func NewProbData(dir string) (*ProbData, error)

create a new problem in an empty dir

func (*ProbData) AddFile

func (r *ProbData) AddFile(name string, pathname string) (string, error)

Add file to r.dir/patch and return relative path

func (*ProbData) AddFileReader

func (r *ProbData) AddFileReader(name string, file io.Reader) (string, error)

func (*ProbData) Dir

func (r *ProbData) Dir() string

get problem dir

func (*ProbData) Export

func (r *ProbData) Export(dir string) error

export the problem's data to another empty dir and change itself to the new one

func (*ProbData) Finalize

func (r *ProbData) Finalize() error

remove problem (dir)

func (*ProbData) Hackable added in v0.0.31

func (r *ProbData) Hackable() bool

func (*ProbData) SetStmt

func (r *ProbData) SetStmt(lang string, file string)

Set statement content to file in r.dir

func (*ProbData) SetValFile

func (r *ProbData) SetValFile(rcd record, field string, filename string) error

func (*ProbData) SetWkflGraph

func (r *ProbData) SetWkflGraph(serial []byte) error

Set workflow graph

func (*ProbData) Workflow

func (r *ProbData) Workflow() workflow.Workflow

get the workflow

type ProbTestdata added in v0.0.22

type ProbTestdata struct {
	// 子任务计分方式
	CalcMethod CalcMethod
	// "tests" _subtaskid, _score ("average", {number})
	Tests table
	// "subtask" _subtaskid, _score, _depend (separated by ",")
	Subtasks table
}

题目评测时用到的数据

func (*ProbTestdata) Info added in v0.0.22

func (r *ProbTestdata) Info() TestdataInfo

func (*ProbTestdata) IsSubtask added in v0.0.22

func (r *ProbTestdata) IsSubtask() bool

Whether subtask is enabled.

type Problem

type Problem interface {
	// 将题目打包为一个文件(压缩包)
	DumpFile(filename string) error
	// 获取题面,lang 见 http://www.lingoes.net/zh/translator/langcode.htm
	Stmt(lang string) []byte
	// 题解
	Tutr(lang string) []byte
	// 附加文件
	Assert(filename string) (*os.File, error)
	// 获取提交格式的数据表格
	SubmConf() SubmConf
	// 评测用的
	Data() *ProbData
	// 展示数据
	DataInfo() DataInfo
	// 是否支持 hack
	Hackable() bool
}

对外提供的 Problem 接口

func LoadDir

func LoadDir(dir string) (Problem, error)

加载一个题目文件夹

func LoadDump

func LoadDump(filename string, dir string) (Problem, error)

将打包的题目在空的文件夹下加载

type Result

type Result struct {
	IsSubtask  bool
	CalcMethod CalcMethod
	Subtask    []SubtResult
}

Problem result

func (Result) Brief

func (r Result) Brief() string

func (Result) Byte

func (r Result) Byte() []byte

type SubmConf

type SubmConf map[string]SubmLimit

针对某个域的提交文件配置

type SubmLimit

type SubmLimit struct {
	// 接受的语言,nil 表示所有语言
	Langs []utils.LangTag
	// 接受哪些类型的文件,必须设置值
	Accepted utils.CtntType
	// 文件大小,单位 byte
	Length uint32
}

Limitation for submitted files

func (SubmLimit) Validate added in v0.0.32

func (r SubmLimit) Validate(data []byte) error

事实上只检查长度

type Submission

type Submission map[workflow.Groupname]*map[string]InmemoryFile

func LoadSubm

func LoadSubm(name string) (Submission, error)

解压

func LoadSubmData added in v0.0.28

func LoadSubmData(data []byte) (Submission, error)

func (Submission) Download added in v0.0.24

func (r Submission) Download(dir string) (res map[workflow.Groupname]*map[string]string)

to path map

func (Submission) DumpFile

func (r Submission) DumpFile(name string) error

打包

func (Submission) DumpTo added in v0.0.23

func (r Submission) DumpTo(writer io.Writer) error

func (Submission) Set

func (r Submission) Set(field string, filename string)

根据文件路径名加入提交文件

func (Submission) SetSource added in v0.0.24

func (r Submission) SetSource(group workflow.Groupname, field string, name string, reader io.Reader)

加入文件(例如custom test就可以手动加test)

group: 所属数据组,一般是 workflow.Gsubm 表示提交数据。
field: 字段名
name: 文件名(一般不带路径)
reader:文件内容

type SubtResult

type SubtResult struct {
	Subtaskid string
	Fullscore float64
	Score     float64
	Testcase  []workflow.Result
}

Subtask result

func (SubtResult) IsFull added in v0.0.25

func (r SubtResult) IsFull() bool

type SubtaskInfo

type SubtaskInfo struct {
	Id        int
	Fullscore float64
	Depend    []int
	Field     map[string]string //other properties of subtasks
	Tests     []TestInfo
}

type TestInfo

type TestInfo struct {
	Id    int
	Field map[string]string //other properties of tests, i.e. in/output file path
}

type TestdataInfo added in v0.0.22

type TestdataInfo struct {
	IsSubtask  bool
	CalcMethod CalcMethod //计分方式
	Subtasks   []SubtaskInfo
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL