1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Entities; |
4
|
|
|
|
5
|
|
|
use App\Language; |
6
|
|
|
use App\Status; |
7
|
|
|
use Carbon\Carbon; |
8
|
|
|
use Illuminate\Database\Eloquent\Model; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Solution. |
12
|
|
|
* |
13
|
|
|
* @property int $id |
14
|
|
|
* @property int $problem_id |
15
|
|
|
* @property int $order |
16
|
|
|
* @property int $contest_id |
17
|
|
|
* @property int $user_id |
18
|
|
|
* @property int $time_cost |
19
|
|
|
* @property int $memory_cost |
20
|
|
|
* @property int $language |
21
|
|
|
* @property int $result |
22
|
|
|
* @property string $ip |
23
|
|
|
* @property int $code_length |
24
|
|
|
* @property Carbon $judged_at |
25
|
|
|
* @property Carbon $created_at |
26
|
|
|
* @property Carbon $updated_at |
27
|
|
|
* @property Contest $contest |
28
|
|
|
* @property User $user |
29
|
|
|
* @property Problem $problem |
30
|
|
|
* @property-read Source $source |
31
|
|
|
* @property-read \App\Entities\CompileInfo $compileInfo |
32
|
|
|
* @property-read \App\Entities\RuntimeInfo $runtimeInfo |
33
|
|
|
*/ |
34
|
|
|
class Solution extends Model |
35
|
|
|
{ |
36
|
|
|
public static $status = [ |
37
|
|
|
4 => 'Accepted', |
38
|
|
|
5 => 'Presentation Error', |
39
|
|
|
6 => 'Wrong Answer', |
40
|
|
|
7 => 'Time Limit Exceed', |
41
|
|
|
8 => 'Memory Limit Exceed', |
42
|
|
|
9 => 'Output Limit Exceed', |
43
|
|
|
10 => 'Runtime Error', |
44
|
|
|
11 => 'Compile Error', |
45
|
|
|
12 => 'Compile OK', |
46
|
|
|
13 => 'Test Running Done', |
47
|
|
|
0 => 'Pending', |
48
|
|
|
1 => 'Pending Rejudging', |
49
|
|
|
2 => 'Compiling', |
50
|
|
|
3 => 'Running & Judging', |
51
|
|
|
]; |
52
|
|
|
protected $fillable = [ |
53
|
|
|
'problem_id', |
54
|
|
|
'user_id', |
55
|
|
|
'language', |
56
|
|
|
'ip', |
57
|
|
|
'order', |
58
|
|
|
'contest_id', |
59
|
|
|
'code', |
60
|
|
|
'result', |
61
|
|
|
'time_cost', |
62
|
|
|
'memory_cost', |
63
|
|
|
'code_length', |
64
|
|
|
'judged_at', |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo|Contest |
69
|
|
|
*/ |
70
|
|
|
public function contest() |
71
|
|
|
{ |
72
|
|
|
return $this->belongsTo(Contest::class, 'contest_id'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function problem() |
76
|
|
|
{ |
77
|
|
|
return $this->belongsTo(Problem::class, 'problem_id'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function isContest() |
81
|
|
|
{ |
82
|
|
|
return $this->contest_id > 0; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function compileInfo() |
86
|
|
|
{ |
87
|
|
|
return $this->hasOne(CompileInfo::class, 'solution_id', 'id'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function runtimeInfo() |
91
|
|
|
{ |
92
|
|
|
return $this->hasOne(RuntimeInfo::class, 'solution_id', 'id'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function source() |
96
|
|
|
{ |
97
|
|
|
return $this->hasOne(Source::class, 'solution_id', 'id'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function lang() |
101
|
|
|
{ |
102
|
|
|
return Language::showLang($this->language); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function result() |
106
|
|
|
{ |
107
|
|
|
return self::$status[$this->result]; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function isCompileError() |
111
|
|
|
{ |
112
|
|
|
return $this->result === Status::COMPILE_ERROR; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function isRuntimeError() |
116
|
|
|
{ |
117
|
|
|
return $this->result === Status::RUNTIME_ERROR; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function isFailed() |
121
|
|
|
{ |
122
|
|
|
// 既不是AC,也不是等待评测,就挂了 |
123
|
|
|
return ! $this->isAccepted() && ! $this->isPending(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function isAccepted() |
127
|
|
|
{ |
128
|
|
|
return $this->result === Status::ACCEPT; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function isPending() |
132
|
|
|
{ |
133
|
|
|
return $this->result === Status::PENDING; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get the Solution's author. |
138
|
|
|
* |
139
|
|
|
* @return User|\Illuminate\Database\Eloquent\Relations\BelongsTo |
140
|
|
|
*/ |
141
|
|
|
public function user() |
142
|
|
|
{ |
143
|
|
|
return $this->belongsTo(User::class, 'user_id'); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|