1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Admin\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use Encore\Admin\Layout\Content; |
7
|
|
|
use App\Models\Eloquent\OJ; |
8
|
|
|
use App\Models\Eloquent\Problem; |
9
|
|
|
use App\Models\Eloquent\Compiler; |
10
|
|
|
use Encore\Admin\Widgets\Form; |
11
|
|
|
use Encore\Admin\Widgets\Box; |
12
|
|
|
use Encore\Admin\Widgets\Table; |
13
|
|
|
use App\Babel\Babel; |
14
|
|
|
use Arr; |
15
|
|
|
|
16
|
|
|
class CodeTesterController extends Controller |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Show the Testing Page. |
20
|
|
|
* |
21
|
|
|
* @return Response |
|
|
|
|
22
|
|
|
*/ |
23
|
|
|
public function tester(Content $content) |
24
|
|
|
{ |
25
|
|
|
$content=$content->header(__('admin.tester.tester.header')); |
|
|
|
|
26
|
|
|
$content=$content->description(__('admin.tester.tester.description')); |
|
|
|
|
27
|
|
|
if (request()->isMethod('post')) { |
28
|
|
|
$content=$content->body($this->run()); |
29
|
|
|
} |
30
|
|
|
return $content->body($this->form()); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Make a form builder. |
35
|
|
|
* |
36
|
|
|
* @return Form |
37
|
|
|
*/ |
38
|
|
|
protected function form() |
39
|
|
|
{ |
40
|
|
|
$OJ=OJ::where(["ocode"=>"noj"])->get(); |
41
|
|
|
$box=new Box(__('admin.tester.tester.title')); |
|
|
|
|
42
|
|
|
if (blank($OJ)) { |
43
|
|
|
$box->style('danger'); |
44
|
|
|
$box->content(__('admin.tester.help.installfirst')); |
|
|
|
|
45
|
|
|
return $box; |
|
|
|
|
46
|
|
|
} |
47
|
|
|
$oid=$OJ->first()->oid; |
48
|
|
|
$box->style('success'); |
49
|
|
|
$form=new Form(); |
50
|
|
|
$form->select('oid', __('admin.tester.oj'))->options($OJ->pluck('name', 'oid'))->help(__('admin.tester.help.onlinejudge'))->rules('required'); |
|
|
|
|
51
|
|
|
$form->select('pid', __('admin.tester.pid'))->options(Problem::where(["OJ"=>$oid])->get()->sortBy('readable_name')->pluck('readable_name', 'pid'))->rules('required'); |
52
|
|
|
$form->select('coid', __('admin.tester.coid'))->options(Compiler::where(["oid"=>$oid])->get()->pluck('display_name', 'coid'))->rules('required'); |
53
|
|
|
$form->textarea('solution', __('admin.tester.solution'))->rows(20)->rules('required'); |
54
|
|
|
$form->action(route('admin.codetester.tester')); |
55
|
|
|
$form->fill([ |
56
|
|
|
'oid'=>request()->oid, |
57
|
|
|
'pid'=>request()->pid, |
58
|
|
|
'coid'=>request()->coid, |
59
|
|
|
'solution'=>request()->solution, |
60
|
|
|
]); |
61
|
|
|
$form->method('POST'); |
62
|
|
|
$box->content($form); |
|
|
|
|
63
|
|
|
return $box; |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Running Test. |
68
|
|
|
* |
69
|
|
|
* @return Response |
70
|
|
|
*/ |
71
|
|
|
protected function run() |
72
|
|
|
{ |
73
|
|
|
$babel=new Babel(); |
74
|
|
|
request()->validate([ |
75
|
|
|
'oid' => 'required|integer', |
76
|
|
|
'pid' => 'required|integer', |
77
|
|
|
'coid' => 'required|integer', |
78
|
|
|
'solution' => 'required', |
79
|
|
|
]); |
80
|
|
|
$runner=$babel->testrun([ |
81
|
|
|
'name' => 'noj', |
82
|
|
|
'pid' => request()->pid, |
83
|
|
|
'coid' => request()->coid, |
84
|
|
|
'solution' => request()->solution, |
85
|
|
|
]); |
86
|
|
|
$verdict=$runner->verdict; |
87
|
|
|
$boxRun=new Box(__('admin.tester.tester.run')); |
|
|
|
|
88
|
|
|
$boxRun->style('info'); |
89
|
|
|
$verdictData=[]; |
90
|
|
|
foreach ($verdict['data'] as $v) { |
91
|
|
|
$verdictData[]=[ |
92
|
|
|
$v["test_case"], |
93
|
|
|
$v["cpu_time"], |
94
|
|
|
$v["real_time"], |
95
|
|
|
$v["memory"], |
96
|
|
|
$v["signal"], |
97
|
|
|
$v["exit_code"], |
98
|
|
|
$v["error"], |
99
|
|
|
$v["result"], |
100
|
|
|
]; |
101
|
|
|
} |
102
|
|
|
$table=new Table(['Test Case', 'CPU Time(ms)', 'Real Time(ms)', 'Memory(byte)', 'Signal', 'Exit Code', 'Error', 'Result'], $verdictData); |
103
|
|
|
$output="<p>Verdict: {$verdict['verdict']}</p>"; |
104
|
|
|
if (!blank($verdict['compile_info'])) { |
105
|
|
|
$output.="<p>Compiler Info:</p><pre>".htmlspecialchars($verdict['compile_info'])."</pre>"; |
106
|
|
|
} |
107
|
|
|
$output.=$table->render(); |
108
|
|
|
$boxRun->content($output); |
109
|
|
|
return $boxRun; |
|
|
|
|
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|