aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCassio de Campos <cassiopc@gmail.com>2017-07-26 18:26:05 +0000
committerCassio de Campos <cassiopc@gmail.com>2017-07-26 18:26:05 +0000
commit8a298ed1bebb0f317988fe910861b64909469ec6 (patch)
tree91e0442f4d20daa3138d89aec54023962ba5bd7c
parent443d0ebf23bc3502993cd3ba08b4d8808ed55650 (diff)
downloadboca-8a298ed1bebb0f317988fe910861b64909469ec6.tar.gz
boca-8a298ed1bebb0f317988fe910861b64909469ec6.zip
a new attempt at sorting
-rw-r--r--src/fscore.php42
-rw-r--r--src/scoretable.php2
2 files changed, 31 insertions, 13 deletions
diff --git a/src/fscore.php b/src/fscore.php
index 9687058..9d24d83 100644
--- a/src/fscore.php
+++ b/src/fscore.php
@@ -36,31 +36,49 @@ function ScoreCMP($a,$b) {
}
if ($a["user"]<$b["user"]) return 1;
else if ($a["user"]>$b["user"]) return -1;
- else return 0;
+ else {
+ if ($a["site"]<$b["site"]) return 1;
+ else if ($a["site"]>$b["site"]) return -1;
+ else return 0;
+ }
}
}
}
function ordena($a) {
+ $n = count($a);
+ /*
$r = array();
- for ($i=0; $i<count($a); $i++) {
+ for ($i=0; $i<$n; $i++) {
$max=null;
- reset($a);
- while ( list ($e, $c) = each($a) ) {
- if ($a[$e]!=null && ($max==null || ScoreCMP($a[$e],$max) > 0)) {
- $j=0;
- for(;$j<$i;$j++)
- if($r[$j]['user']==$a[$e]['user'] && $r[$j]['site']==$a[$e]['site']) break;
- if($j>=$i) {
- $max = $a[$e];
+ foreach($a as $e => $c) {
+ if ($c != null && ($max==null || ScoreCMP($c,$max) > 0)) {
+ // $j=0;
+ // for(;$j<$i;$j++)
+ // if($r[$j]['user']==$a[$e]['user'] && $r[$j]['site']==$a[$e]['site']) break;
+ // if($j>=$i) {
+ $max = $c;
$maxe = $e;
- }
+ // }
}
}
if ($max==null) break;
$r[$i] = $max;
$a[$maxe] = null;
}
- return $r;
+ */
+ uasort($a, "ScoreCMP");
+ $j = 0;
+ $r = array();
+ foreach($a as $k) {
+ if($j == 0) $r[0] = $k;
+ else {
+ if($k['user'] != $r[$j]['user'] || $k['site'] != $r[$j]['site']) {
+ $j++;
+ $r[$j] = $k;
+ }
+ }
+ }
+ return $r;
}
function DBScore($contest, $verifylastmile, $hor=-1, $globalsite='0') {
$c = DBConnect();
diff --git a/src/scoretable.php b/src/scoretable.php
index 8491611..0348d51 100644
--- a/src/scoretable.php
+++ b/src/scoretable.php
@@ -280,7 +280,7 @@ if($redo) {
}
}
- $strtmp .= "<br>\n<table id=\"myscoretable\" width=\"100%\" border=1>\n <tr>\n <td><b>#</b></td>\n <td><b>User</b></td>\n <td><b>Name</b></td>\n";
+ $strtmp .= "<br>\n<table id=\"myscoretable\" width=\"100%\" border=1>\n <tr>\n <td><b>#</b></td>\n <td><b>User/Site</b></td>\n <td><b>Name</b></td>\n";
if(!$des) {
if($level>0)
$strtmp .= "<td><b>Problems</b></td>";