Skip to content
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Commit d9e4f61

Browse files
committed
Performance enhance in Eval.php
2 parents b44c9e0 + 7530eb1 commit d9e4f61

File tree

17 files changed

+7011
-42
lines changed

17 files changed

+7011
-42
lines changed

admin/formula.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
$score = $points / $attempts;
3+
?>

admin/index.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
else
1515
include('header.php');
1616
connectdb();
17+
date_default_timezone_set('UTC');
1718
?>
1819
<li class="active"><a href="#">Admin Panel</a></li>
1920
<li><a href="users.php">Users</a></li>
@@ -37,18 +38,20 @@
3738
<ul class="nav nav-tabs">
3839
<li class="active"><a href="#">General</a></li>
3940
<li><a href="problems.php">Problems</a></li>
41+
<li><a href="scoring.php">Scoring</a></li>
4042
</ul>
4143
<div>
4244
<div>
4345
<form method="post" action="update.php">
4446
<?php
45-
$query = "SELECT name, accept, c, cpp, java, python FROM prefs";
47+
$query = "SELECT name, start, end, c, cpp, java, python FROM prefs";
4648
$result = mysql_query($query);
4749
$fields = mysql_fetch_array($result);
4850
?>
4951
<input type="hidden" name="action" value="settings"/>
5052
Name of event: <input name="name" type="text" value="<?php echo($fields['name']);?>"/><br/>
51-
<input name="accept" type="checkbox" <?php if($fields['accept']==1) echo("checked=\"true\"");?>/> <span class="label label-important">Accept submissions</span><br/>
53+
Start Time in UTC (dd/mm/yy hh:mm:ss): <input name="start" type="text" value="<?php echo(date('d/m/y H:i:s',$fields['start']));?>"/><br/>
54+
End Time in UTC (dd/mm/yy hh:mm:ss): <input name="end" type="text" value="<?php echo(date('d/m/y H:i:s',$fields['end']));?>"/><br/>
5255
<h1><small>Languages</small></h1>
5356
<input name="c" type="checkbox" <?php if($fields['c']==1) echo("checked=\"true\"");?>/> C<br/>
5457
<input name="cpp" type="checkbox" <?php if($fields['cpp']==1) echo("checked=\"true\"");?>/> C++<br/>

admin/problems.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<ul class="nav nav-tabs">
3939
<li><a href="index.php">General</a></li>
4040
<li class="active"><a href="#">Problems</a></li>
41+
<li><a href="scoring.php">Scoring</a></li>
4142
</ul>
4243
<div>
4344
<div>
@@ -84,7 +85,8 @@
8485
</ul>
8586
<div class="tab-content">
8687
<div class="tab-pane active" id="tab1">
87-
Problem Title: <input style="width:700px;" type="text" id="title" name="title" value="<?php echo($selected['name']);?>"/><br/>
88+
Problem Title: <input class="span8" type="text" id="title" name="title" value="<?php echo($selected['name']);?>"/><br/>
89+
Maximum Points: <input class="span2" type="text" id="points" name="points" value="<?php echo($selected['points']);?>"/><br/>
8890
<div class="controls">
8991
<div class="input-append">
9092
Time Limit: <input class="span2" id="appendedInput" size="8" type="text" name="time" value="<?php echo($selected['time']); ?>"><span class="add-on">ms</span>
@@ -119,6 +121,7 @@
119121
<div class="tab-content">
120122
<div class="tab-pane active" id="tab1">
121123
Problem Title: <input class="span8" type="text" id="title" name="title"/><br/>
124+
Maximum Points: <input class="span2" type="text" id="points" name="points"/><br/>
122125
<div class="controls">
123126
<div class="input-append">
124127
Time Limit: <input class="span2" id="appendedInput" size="8" type="text" name="time"><span class="add-on">ms</span>

admin/scoring.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria (sankha93@gmail.com)
5+
* Licensed under MIT License.
6+
*
7+
* Codjudge admin panel scoring system
8+
*/
9+
require_once('../functions.php');
10+
if(!loggedin())
11+
header("Location: login.php");
12+
else if($_SESSION['username'] !== 'admin')
13+
header("Location: login.php");
14+
else
15+
include('header.php');
16+
connectdb();
17+
?>
18+
<li class="active"><a href="#">Admin Panel</a></li>
19+
<li><a href="users.php">Users</a></li>
20+
<li><a href="logout.php">Logout</a></li>
21+
</ul>
22+
</div><!--/.nav-collapse -->
23+
</div>
24+
</div>
25+
</div>
26+
27+
<div class="container">
28+
29+
<?php
30+
if(isset($_GET['updated']))
31+
echo("<div class=\"alert alert-success\">\nScoring Formula Updated!\n</div>");
32+
?>
33+
<ul class="nav nav-tabs">
34+
<li><a href="index.php">General</a></li>
35+
<li><a href="problems.php">Problems</a></li>
36+
<li class="active"><a href="#">Scoring</a></li>
37+
</ul>
38+
<div>
39+
<div>
40+
Type out the score calculation method for each of the problems. The total score of the user will be calculated as a sum of individual scores for the problems by using the same formula on all the solved or attempted problems.<br/><br/>
41+
<b>You can use any of the following variables in your calculation:</b><br/>
42+
<code>$attempts</code> The number of attempts by the user for that problem.<br/>
43+
<code>$points</code> Maximum points alloted for that question.<br/>
44+
<code>$score</code> Score to be awarded for that problem.<br/>
45+
<span class="label label-info">The formula uses PHP styled syntax. Make sure you end each statement with a ;</span><br/><br/>
46+
47+
<form method="post" action="update.php">
48+
<input type="hidden" name="action" value="updateformula"/>
49+
<textarea style="font-family: mono; height:200px;" class="span9" name="formula" id="text"><?php
50+
$query = "SELECT formula FROM prefs";
51+
$result = mysql_query($query);
52+
$fields = mysql_fetch_array($result);
53+
echo($fields['formula']);
54+
?></textarea><br/>
55+
<input class="btn btn-primary btn-large" type="submit" value="Update Formula"/>
56+
</form>
57+
</div>
58+
</div>
59+
</div> <!-- /container -->
60+
61+
<?php
62+
include('footer.php');
63+
?>

admin/update.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
include('../functions.php');
1010
connectdb();
11+
date_default_timezone_set('UTC');
1112
if(isset($_POST['action'])){
1213
if($_POST['action']=='email') {
1314
// update the admin email
@@ -39,12 +40,15 @@
3940
if(trim($_POST['name']) == "")
4041
header("Location: index.php?derror=1");
4142
else {
42-
if($_POST['accept']=='on') $accept=1; else $accept=0;
43+
list($day, $month, $year, $hour, $minute) = split('[/ :]', $_POST['start']);
44+
$start=mktime($hour, $minute,0, $month, $day, $year);
45+
list($day, $month, $year, $hour, $minute) = split('[/ :]', $_POST['end']);
46+
$end=mktime($hour, $minute,0, $month, $day, $year);
4347
if($_POST['c']=='on') $c=1; else $c=0;
4448
if($_POST['cpp']=='on') $cpp=1; else $cpp=0;
4549
if($_POST['java']=='on') $java=1; else $java=0;
4650
if($_POST['python']=='on') $python=1; else $python=0;
47-
mysql_query("UPDATE prefs SET name='".mysql_real_escape_string($_POST['name'])."', accept=$accept, c=$c, cpp=$cpp, java=$java, python=$python");
51+
mysql_query("UPDATE prefs SET name='".mysql_real_escape_string($_POST['name'])."', start=$start, end=$end, c=$c, cpp=$cpp, java=$java, python=$python");
4852
header("Location: index.php?changed=1");
4953
}
5054
} else if($_POST['action']=='addproblem') {
@@ -65,6 +69,12 @@
6569
mysql_query($query);
6670
header("Location: problems.php?updated=1&action=edit&id=".$_POST['id']);
6771
}
72+
} else if($_POST['action']=='updateformula') {
73+
mysql_query("UPDATE prefs SET formula='".$_POST['formula']."'");
74+
$fp = fopen('formula.php','w');
75+
fwrite($fp, "<?php\n".$_POST['formula']."\n?>");
76+
fclose($fp);
77+
header("Location: scoring.php?updated=1");
6878
}
6979
}
7080
else if(isset($_GET['action'])){
@@ -86,5 +96,5 @@
8696
mysql_query($query);
8797
header("Location: users.php?unbanned=1");
8898
}
89-
}
99+
}
90100
?>

codejudge-compiler/src/codejudge/compiler/RequestThread.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,33 @@ else if(lang.equals("python"))
8585

8686
// method to return the compiler errors
8787
public String compileErrors() {
88-
String line, content = "";
88+
String line = "";
89+
StringBuilder content = new StringBuilder();
8990
try {
9091
BufferedReader fin = new BufferedReader(new InputStreamReader(new FileInputStream(dir.getAbsolutePath() + "/err.txt")));
9192
while((line = fin.readLine()) != null)
92-
content += (line + "\n");
93+
content.append(line + "\n");
9394
} catch (FileNotFoundException e) {
9495
e.printStackTrace();
9596
} catch (IOException e) {
9697
e.printStackTrace();
9798
}
98-
return content.trim();
99+
return content.toString().trim();
99100
}
100101

101102
// method to return the execution output
102103
public String execMsg() {
103-
String line, content = "";
104+
String line = "";
105+
StringBuilder content = new StringBuilder();
104106
try {
105107
BufferedReader fin = new BufferedReader(new InputStreamReader(new FileInputStream(dir.getAbsolutePath() + "/out.txt")));
106108
while((line = fin.readLine()) != null)
107-
content += (line + "\n");
109+
content.append(line + "\n");
108110
} catch (FileNotFoundException e) {
109111
e.printStackTrace();
110112
} catch (IOException e) {
111113
e.printStackTrace();
112114
}
113-
return content.trim();
115+
return content.toString().trim();
114116
}
115117
}

0 commit comments

Comments
 (0)