aboutsummaryrefslogtreecommitdiff
path: root/src/freport.php
blob: 6d990caaaba4d2dc91486403e4a05028235f9c0b (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
////////////////////////////////////////////////////////////////////////////////
//BOCA Online Contest Administrator
//    Copyright (C) 2003-2012 by BOCA Development Team (bocasystem@gmail.com)
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////////////
// Last modified 29/aug/2017 by cassio@ime.usp.br

function DBRunReport($contest,$site) {
	$c = DBConnect();
	$sql = "select r.runnumber as number, u.usernumber as un, u.username as user, r.rundatediff as timestamp, " .
                                "p.problemname as problem, l.langname as language, a.runanswer as answer, a.yes as yes " .
                             "from runtable as r, problemtable as p, langtable as l, answertable as a, usertable as u " .
                             "where r.contestnumber=$contest and p.contestnumber=r.contestnumber and " .
                                    "r.runproblem=p.problemnumber and l.contestnumber=r.contestnumber and " .
				    "l.langnumber=r.runlangnumber and a.answernumber=r.runanswer and " .
				    "a.contestnumber=r.contestnumber and (r.runstatus = 'judged' or r.runstatus = 'judged+') and " .
				    "u.usernumber=r.usernumber and u.contestnumber=$contest and " .
			 	    "u.usersitenumber=r.runsitenumber and u.usertype='team'";
	if($site != "") $sql .= " and r.runsitenumber=$site";
	$xdados = array();
	$xuser = array();
	$xuserfull = array();
	$xuseryes = array();
	$xproblem = array();
	$xproblemyes = array();

	$xusername = array();
	$r = DBExec($c, "select usernumber as un, username as name, userfullname as fullname ".
				"from usertable where contestnumber=$contest ".
				"and usersitenumber=$site and ".
                "usertype='team' and userlastlogin is not null and userenabled='t'", "DBRunReport(get users)");
	$n = DBnlines($r);
	for ($i=0;$i<$n;$i++) {
		$a = DBRow($r,$i);
		//cassiopc: staff users should see only same site, so checking of teamYYYY and staffXXXX have YYYY=XXXX
		if($_SESSION["usertable"]["usertype"] != "admin" && substr($a['name'],4,4) != substr($_SESSION["usertable"]["username"],5,4)) continue;
		$xusername[$a['un']] = $a['name'];
		$xuserfull[$a['name']] = $a['fullname'];
	}
	ksort($xusername);
	$xcolor = array();
	
	$pr = DBGetProblems($contest);
	for($i=0; $i<count($pr); $i++) {
	  $xproblem[$pr[$i]['problem']]=0;
	  $xproblemyes[$pr[$i]['problem']]=0;
	  $xcolor[$pr[$i]['problem']]=$pr[$i]['color'];
	}

	$xlanguage = array();
	$xlanguageyes = array();
	$xanswer = array();
	$xtimestamp = array();
	$xtimestampyes = array();
	$xpa = array();
	$xpl = array();
	$xla = array();
	$xup = array();
	
	$r = DBExec($c, $sql, "DBRunReport(get runs)");
	$n = DBnlines($r);

	for ($i=0;$i<$n;$i++) {
		$a = DBRow($r,$i);
		//cassiopc: staff users should see only same site, so checking of teamYYYY and staffXXXX have YYYY=XXXX
		if($_SESSION["usertable"]["usertype"] != "admin" && substr($a['user'],4,4) != substr($_SESSION["usertable"]["username"],5,4)) continue;
		$xdados[$i] = $a;
		// # of runs by team
		if(isset($xuser[$a['user']]))
			$xuser[$a['user']]++;
		else $xuser[$a['user']]=1;
		// # of runs by problem
		if(isset($xproblem[$a['problem']]))
			$xproblem[$a['problem']]++;
		else 	$xproblem[$a['problem']]=1;
		if($a['yes'] == 't') {
			if(isset($xuseryes[$a['user']]))
				$xuseryes[$a['user']]++;
			else $xuseryes[$a['user']]=1;
			$xproblemyes[$a['problem']]++;
		}
		// # of runs by language
		if(isset($xlanguage[$a['language']]))
			$xlanguage[$a['language']]++;
		else $xlanguage[$a['language']]=1;
		if($a['yes'] == 't') {
			if(isset($xlanguageyes[$a['language']]))
				$xlanguageyes[$a['language']]++;
			else $xlanguageyes[$a['language']]=1;
		}
		// # of runs by answer
		if(isset(	$xanswer[$a['answer']]))
			$xanswer[$a['answer']]++;
		else 	$xanswer[$a['answer']]=1;
		// time of the runs
		array_push($xtimestamp, $a['timestamp']);
		if($a['yes'] == 't')
			array_push($xtimestampyes, $a['timestamp']);

		// # of runs by answer by problem
		if(isset($xpa[$a['problem']][$a['answer']]))
			$xpa[$a['problem']][$a['answer']]++;
		else $xpa[$a['problem']][$a['answer']]=1;
		// # of runs by language by problem
		if(isset($xpl[$a['problem']][$a['language']]))
			$xpl[$a['problem']][$a['language']]++;
		else $xpl[$a['problem']][$a['language']]=1;
		// # of runs by answer by language
		if(isset($xla[$a['language']][$a['answer']]))
			$xla[$a['language']][$a['answer']]++;
		else $xla[$a['language']][$a['answer']]=1;
		// # of runs by problem by user
		// negative sign means team got an yes for the problem
		if(!isset($xup[$a['user']][$a['problem']]))
			$xup[$a['user']][$a['problem']]=0;
		if($xup[$a['user']][$a['problem']] < 0)
			$xup[$a['user']][$a['problem']]--;
		else {
			$xup[$a['user']][$a['problem']]++;
			if($a['yes'] == 't') $xup[$a['user']][$a['problem']] = - $xup[$a['user']][$a['problem']];
		}
	}
	ksort($xuser);
	ksort($xuseryes);
	ksort($xproblem);
	ksort($xproblemyes);
	ksort($xlanguage);
	ksort($xlanguageyes);
	ksort($xanswer);
	sort($xtimestamp);
	sort($xtimestampyes);
	$x = array(
		'color' => $xcolor,
		'user' => $xuser,
		'useryes' => $xuseryes,
		'username' => $xusername,
		'userfull' => $xuserfull,
		'problem' => $xproblem,
		'problemyes' => $xproblemyes,
		'language' => $xlanguage,
		'languageyes' => $xlanguageyes,
		'answer' => $xanswer,
		'timestamp' => $xtimestamp,
		'timestampyes' => $xtimestampyes,
		'pa' => $xpa,
		'pl' => $xpl,
		'la' => $xla,
		'up' => $xup);
	return $x;
}
?>