-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSubmission.php
101 lines (91 loc) · 3 KB
/
Submission.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Request;
class Submission extends Model
{
protected $table = "submissions";
protected $primaryKey = "runid";
protected $fillable = [""];
public function sim()
{
return $this->hasOne('App\Sim', 'runid');
}
public function user()
{
return $this->belongsTo('App\User', 'uid');
}
public function problem()
{
return $this->belongsTo('App\Problem', 'pid');
}
/*
* @function getValidSubmissionCount
* @input $contest_id, $problem_id
*
* @return $totalSubmissionCount
* @description Count total submission of a given problem in a given contest. All
* submissions after one's first AC submission will be ignored.
*/
public static function getValidSubmissionCount($contest_id, $problem_id)
{
if($contest_id == 0)
$totalSubmission = Submission::where([
'pid' => $problem_id,
])->orderby('uid', 'asc')->get();
else
$totalSubmission = Submission::where([
'pid' => $problem_id,
'cid' => $contest_id,
])->orderby('uid', 'asc')->get();
$tmpuid = 0;
$tmpac = 0;
$totalSubmissionCount = 0;
foreach($totalSubmission as $submission)
{
if($tmpuid != $submission->uid)
{
$tmpuid = $submission->uid;
$tmpac = 0;
}
if(!$tmpac)
$totalSubmissionCount++;
if($submission->result == 'Accepted')
$tmpac = 1;
}
return $totalSubmissionCount;
}
/*
* @function getAcCountByUserID
* @input $uid
*
* @return $data
* @description get the Accepted Submission all in the past days
*/
public static function getAcCountByUserID($uid)
{
$dayNumObj = Submission::orderby('runid', 'asc')->first();
if ($dayNumObj && $dayNumObj->count()) {
$dayOld = strtotime($dayNumObj->created_at->format('Ymd'));
$nowDate = strtotime(date('Ymd', time()));
$dayNum = round(($nowDate - $dayOld) / 3600 / 24) + 1;
$data = [];
for ($i = 0; $i < $dayNum; $i++) {
$data[$i]['date'] = date("Y-m-d", strtotime('-' . $i . ' day'));
$data[$i]['count'] = 0;
}
$submissionObj = Submission::select('result', 'created_at')->orderby('runid', 'asc')->where('uid', $uid)->get();
$submissionNum = $submissionObj->count();
for ($i = 0; $i < $submissionNum; $i++) {
if ($submissionObj[$i]['result'] == 'Accepted') {
$submissionDate = strtotime($submissionObj[$i]->created_at->format('Ymd'));
$diffDays = round(($nowDate - $submissionDate) / 3600 / 24);
if ($diffDays < $dayNum)
$data[$diffDays]['count']++;
}
}
return $data;
} else
return null;
}
}