|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models\Eloquent; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
|
|
7
|
|
|
class ContestProblem extends Model |
|
8
|
|
|
{ |
|
9
|
|
|
protected $table='contest_problem'; |
|
10
|
|
|
protected $primaryKey='cpid'; |
|
11
|
|
|
public $timestamps = null; |
|
12
|
|
|
const DELETED_AT=null; |
|
13
|
|
|
const UPDATED_AT=null; |
|
14
|
|
|
const CREATED_AT=null; |
|
15
|
|
|
|
|
16
|
|
|
public function contest() |
|
17
|
|
|
{ |
|
18
|
|
|
return $this->belongsTo('App\Models\Eloquent\ContestModel','cid','cid'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function problem() |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->belongsTo('App\Models\Eloquent\ProblemModel','pid','pid'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function submissions() |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->problem->submissions()->where('cid',$this->contest->cid); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
//This should be a repository...or service function ? |
|
32
|
|
|
public function userStatus($user) |
|
33
|
|
|
{ |
|
34
|
|
|
$ret=[ |
|
35
|
|
|
'solved' => 0, |
|
36
|
|
|
'solved_time' => '', |
|
37
|
|
|
'solved_time_parsed' => '', |
|
38
|
|
|
'wrong_doings' => 0, |
|
39
|
|
|
'color' => '', |
|
40
|
|
|
]; |
|
41
|
|
|
$ac_record = $this->ac_record($user); |
|
42
|
|
|
if(!empty($ac_record[0])){ |
|
43
|
|
|
$ret['solved'] = 1; |
|
44
|
|
|
$ret['solved_time'] = $ac_record[0]->submission_date - strtotime($this->contest->begin_time); |
|
45
|
|
|
$ret['solved_time_parsed'] = formatProblemSolvedTime($ret['solved_time']); |
|
46
|
|
|
$ret['wrong_doings'] = $ac_record[2]; |
|
47
|
|
|
$ret['color'] = $ac_record[1] ? 'wemd-green-text' : 'wemd-teal-text'; |
|
48
|
|
|
}else{ |
|
49
|
|
|
$ret['wrong_doings'] = $ac_record[2]; |
|
50
|
|
|
} |
|
51
|
|
|
return $ret; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function ac_record($user) |
|
55
|
|
|
{ |
|
56
|
|
|
$user_ac = $this->submissions()->where([ |
|
57
|
|
|
'uid' => $user->id, |
|
58
|
|
|
'verdict' => 'Accepted' |
|
59
|
|
|
])->first(); |
|
60
|
|
|
|
|
61
|
|
|
$other_ac = 1; |
|
62
|
|
|
$wrong_trys = 0; |
|
63
|
|
|
if(!empty($user_ac)){ |
|
64
|
|
|
$other_ac = $this->submissions() |
|
65
|
|
|
->where('verdict','Accepted') |
|
66
|
|
|
->where('submission_date', '<', $user_ac->submission_date) |
|
67
|
|
|
->count(); |
|
68
|
|
|
$wrong_trys = $this->submissions()->where([ |
|
69
|
|
|
'uid' => $user->id, |
|
70
|
|
|
])->whereIn('verdict', [ |
|
71
|
|
|
'Runtime Error', |
|
72
|
|
|
'Wrong Answer', |
|
73
|
|
|
'Time Limit Exceed', |
|
74
|
|
|
'Real Time Limit Exceed', |
|
75
|
|
|
'Memory Limit Exceed', |
|
76
|
|
|
'Presentation Error', |
|
77
|
|
|
'Output Limit Exceeded' |
|
78
|
|
|
])->where('submission_date', '<', $user_ac->submission_date)->count(); |
|
79
|
|
|
}else{ |
|
80
|
|
|
$wrong_trys = $this->submissions()->where([ |
|
81
|
|
|
'uid' => $user->id, |
|
82
|
|
|
])->whereIn('verdict', [ |
|
83
|
|
|
'Runtime Error', |
|
84
|
|
|
'Wrong Answer', |
|
85
|
|
|
'Time Limit Exceed', |
|
86
|
|
|
'Real Time Limit Exceed', |
|
87
|
|
|
'Memory Limit Exceed', |
|
88
|
|
|
'Presentation Error', |
|
89
|
|
|
'Output Limit Exceeded' |
|
90
|
|
|
])->where('submission_date', '<', $this->contest->frozen_time)->count(); |
|
91
|
|
|
} |
|
92
|
|
|
return [ |
|
93
|
|
|
$user_ac, |
|
94
|
|
|
$other_ac, |
|
95
|
|
|
$wrong_trys |
|
96
|
|
|
]; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|