yusufs / grader
在线评测系统
Requires
- php: >=5.4.0
Requires (Dev)
- symfony/filesystem: 2.5.6
This package is not auto-updated.
Last update: 2024-09-18 07:10:39 UTC
README
这是一个基于PHP创建在线评测系统的库。现在您只需一行代码即可轻松编译或运行您的程序。无需担心恶意程序损坏系统,因为这个库使用了用于ACM/ICPC培训的在线评测系统的openjudge/sandbox。参考:[https://openjudge.net/Solution/Sandbox](https://openjudge.net/Solution/Sandbox) 和 [https://github.com/openjudge/sandbox](https://github.com/openjudge/sandbox)
关键词:开放评测,在线评测PHP,Laravel在线评测
安装
如果您想,可以从此存储库下载副本或克隆。但是,您可以使用Composer轻松地将此库包含到您的项目中。请将其包含在composer.json的require中
require: {
"yusufs/grader": "1.0"
}
设置库
在使用此库之前,必须执行以下几个步骤。
首先,安装sandbox
库。我保证您需要这个库,即使您最初说“这配置过程是什么鬼”。您需要这个库来防止恶意程序损坏您的系统。
$ cd Yusufs/bashcode/Sandbox/libsandbox
$ ./configure
$ sudo make install
然后,您必须编译sandbox程序。使用以下命令编译sandbox.c
gcc sandbox.c -o sandbox -lsandbox
注意
- 请注意,您必须将sandbox.c程序编译为
sandbox
文件名。这是惯例。否则,评测将不会运行。 - 不要向Sandbox提交问题,因为它是从https://github.com/openjudge/sandbox/提供的额外库。
请将以下文件设置为chmod 775
- compile.sh
- diff.sh
- runner.sh
- sandbox
完成!别忘了在项目根目录中创建storage
目录,因为这个库将在此处保存所有文件。
$ mkdir storage
例如,如果您正在使用laravel 4.2.*,则树结构将如下所示
- app
- bootstrap
- public
- vendor
- CONTRIBUTING.md
- artisan
- composer.json
- phpunit.xml
- readme.md
- server.md
现在,这些目录应该看起来像这样
- app
- bootstrap
- public
- storage
- vendor
- CONTRIBUTING.md
- artisan
- composer.json
- phpunit.xml
- readme.md
- server.md
完成!现在您可以使用此库
使用方法
以下是流程
- 您创建一个文件来保存您的代码
- 您编译您的代码,现在它被称为'程序'(一个可执行程序)
- 您创建一个输入来运行您的程序
- 您使用您的输入运行'程序'
- 您获得有关状态详情
以下是状态代码
- PD = 待处理
- OK = 正常
- RF = 限制功能
- ML = 内存限制超出
- OL = 输出限制超出
- TL = 时间限制超出
- RT = 运行时错误(SIGSEGV,SIGFPE,...)
- AT = 异常终止
- IE = 内部错误(沙箱执行器)
- BP = 坏策略(自openjudge/sandbox 0.3.3版本以来)
保存代码或脚本
@param 文件扩展名 @param 代码
return Yusufs\Grader::saveScript("c", "YOUR-CODE-HERE");
示例输出
{
success: true,
message: "File saved!",
detail: {
filename: "script_12031364091415211460.c",
path: "storage/scripts/",
extension: "c"
}
}
将代码编译为程序
@param 脚本文件名
return Yusufs\Grader::compile("script_12031364091415211460.c");
示例输出
{
status: true,
message: "Now you can run this program.",
detail: {
reason: "compiled",
time: "3",
time_unit: "ms",
exit_code: "0",
program_path: "storage/scripts/script_12031364091415211460.c"
}
}
保存输入
@param 输入内容
return Yusufs\Grader::saveInput("PROGRAM-INPUT-HERE");
示例输出
{
success: true,
message: "File saved!",
detail: {
filename: "input_7204332951415211535.txt",
path: "storage/input/",
extension: "txt"
}
}
运行程序
@param 程序文件名(与脚本名相同) @param 输入文件名 @param 时间限制(以秒为单位) @param 内存限制(以千字节为单位)
return Yusufs\Grader::run('script_12031364091415211460.c', 'input_7204332951415211535.txt', 1, 32000);
示例输出
{
status: true,
message: "You can now evaluate the result.",
detail: {
result: "OK",
cpu: "519",
vsize: "4288",
rss: "356",
cpu_unit: "ms",
vsize_unit: "kB",
rss_unit: "kB",
filename: "1415212611_output_of_input_7204332951415211535.txt",
path: "storage/output/"
}
}
比较程序
用于一次性比较两个程序的输出
return Yusufs\Grader::compareProgram('script_7357485711415184458.cpp', 'script_7357485711415184458.cpp', 'input_7080103211415181065.txt', 1, 338592);
示例输出
{
judge: {
output_file_difference: false,
output_file_similarity: true
},
program1: {
status: true,
message: "You can now evaluate the result.",
detail: {
result: "OK",
cpu: "2",
vsize: "12620",
rss: "1064",
cpu_unit: "ms",
vsize_unit: "kB",
rss_unit: "kB",
filename: "1415212854_output_of_input_7080103211415181065.txt",
path: "storage/output/"
}
},
program2: {
status: true,
message: "You can now evaluate the result.",
detail: {
result: "OK",
cpu: "2",
vsize: "12620",
rss: "1064",
cpu_unit: "ms",
vsize_unit: "kB",
rss_unit: "kB",
filename: "1415212854_output_of_input_7080103211415181065.txt",
path: "storage/output/"
}
}
}
背景
无因则无果 - Yusuf Syaifudin,2014年11月6日 01:51AM
这个库是为了完成大学作业(TUGAS KHUSUS)而制作的,我在那里感觉写的代码不够整洁,很难进行重写。"那么,为什么不直接制作一个库呢?"我想。因此,这个库就诞生了。