-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconteststatistics.php
105 lines (91 loc) · 2.97 KB
/
conteststatistics.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
102
103
104
105
<?php
$OJ_CACHE_SHARE = true;
$cache_time = 3;
require_once("./include/db_info.inc.php");
require_once("./include/cache_start.php");
require_once("./include/const.inc.php");
require_once("./include/my_func.inc.php");
// contest start time
if (!isset($_GET['cid'])) die("No Such Contest!");
$cid = intval($_GET['cid']);
$sql = "SELECT title,end_time FROM `contest` WHERE `contest_id`=? AND `start_time`<NOW()";
$result = pdo_query($sql, $cid);
$num = count($result);
if ($num == 0) {
$view_errors = "Not Started!";
require "template/$OJ_TEMPLATE/error.php";
exit(0);
}
$row = $result[0];
$title = $row[0];
$end_time = strtotime($row[1]);
if (time() < $end_time && stripos($title, "noip")) {
$view_errors = "<h2>NOIP contest !</h2>";
require "template/$OJ_TEMPLATE/error.php";
exit(0);
}
$view_title = "Contest Statistics";
$sql = "SELECT count(`num`) FROM `contest_problem` WHERE `contest_id`=?";
$result = pdo_query($sql, $cid);
$row = $result[0];
$pid_cnt = intval($row[0]);
$sql = "SELECT `result`,`num`,`language` FROM `solution` WHERE `contest_id`=? and num>=0";
$result = pdo_query($sql, $cid);
$R = array();
foreach ($result as $row) {
$res = intval($row['result']) - 4;
if ($res < 0) $res = 8;
$num = intval($row['num']);
$lag = intval($row['language']);
if (!isset($R[$num][$res]))
$R[$num][$res] = 1;
else
$R[$num][$res]++;
if (!isset($R[$num][$lag + 11]))
$R[$num][$lag + 11] = 1;
else
$R[$num][$lag + 11]++;
if (!isset($R[$pid_cnt][$res]))
$R[$pid_cnt][$res] = 1;
else
$R[$pid_cnt][$res]++;
if (!isset($R[$pid_cnt][$lag + 11]))
$R[$pid_cnt][$lag + 11] = 1;
else
$R[$pid_cnt][$lag + 11]++;
if (!isset($R[$num][10]))
$R[$num][10] = 1;
else
$R[$num][10]++;
if (!isset($R[$pid_cnt][10]))
$R[$pid_cnt][10] = 1;
else
$R[$pid_cnt][10]++;
}
$res = 3600;
$sql = "SELECT (UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(start_time))/100 FROM contest WHERE contest_id=? ";
$result = pdo_query($sql, $cid);
$view_userstat = array();
if ($row = $result[0]) {
$res = $row[0];
}
$sql = "SELECT floor(UNIX_TIMESTAMP((in_date))/$res)*$res*1000 md,count(1) c FROM `solution` where `contest_id`=? group by md order by md desc ";
$result = pdo_query($sql, $cid);
$chart_data_all = array();
//echo $sql;
foreach ($result as $row) {
$chart_data_all[$row['md']] = $row['c'];
}
$sql = "SELECT floor(UNIX_TIMESTAMP((in_date))/$res)*$res*1000 md,count(1) c FROM `solution` where `contest_id`=? and result=4 group by md order by md desc ";
$result = pdo_query($sql, $cid);//mysql_escape_string($sql));
$chart_data_ac = array();
//echo $sql;
foreach ($result as $row) {
$chart_data_ac[$row['md']] = $row['c'];
}
/////////////////////////Template
require "template/$OJ_TEMPLATE/conteststatistics.php";
require "oj-footer.php";
/////////////////////////Common foot
if (file_exists('./include/cache_end.php'))
require_once('./include/cache_end.php');