aboutsummaryrefslogtreecommitdiff
path: root/boca-1.5.0/src/freport.php
blob: e25bd16a2a765c28be8f4bebe69dd30c63520c01 (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
<?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 05/aug/2012 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";
	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);
		$xusername[$a['un']] = $a['name'];
		$xuserfull[$a['name']] = $a['fullname'];
	}
	ksort($xusername);

	$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();

	$r = DBExec($c, $sql, "DBRunReport(get runs)");
	$n = DBnlines($r);

	for ($i=0;$i<$n;$i++) {
		$a = DBRow($r,$i);
		$xdados[$i] = $a;
		// # of runs by team
		$xuser[$a['user']]++;
		// # of runs by problem
		$xproblem[$a['problem']]++;
		if($a['yes'] == 't') {
				$xuseryes[$a['user']]++;
			$xproblemyes[$a['problem']]++;
		}
		// # of runs by language
		$xlanguage[$a['language']]++;
		if($a['yes'] == 't')
			$xlanguageyes[$a['language']]++;
		// # of runs by answer
		$xanswer[$a['answer']]++;
		// time of the runs
		array_push($xtimestamp, $a['timestamp']);
		if($a['yes'] == 't')
			array_push($xtimestampyes, $a['timestamp']);

		// # of runs by answer by problem
		$xpa[$a['problem']][$a['answer']]++;
		// # of runs by language by problem
		$xpl[$a['problem']][$a['language']]++;
		// # of runs by answer by language
		$xla[$a['language']][$a['answer']]++;
		// # of runs by problem by user
		// negative sign means team got an yes for the problem
		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;
}
?>