diff --git a/checkin_notes b/checkin_notes
index 021063a41b..084874eed8 100755
--- a/checkin_notes
+++ b/checkin_notes
@@ -12838,3 +12838,20 @@ David May 30 2004
sched/
handle_request.C
sched_send.C
+
+David May 30 2004
+ - Add the ability to sort by total or expavg credit in most lists
+ - Fix the "update credit" feature to use the same
+ formula used to compute expavg credit in the first place
+
+ html/
+ inc/
+ host.inc
+ team.inc
+ user.inc
+ user/
+ host_update_credit.php
+ hosts_user.php
+ top_hosts.php
+ top_teams.php
+ top_users.php
diff --git a/html/inc/host.inc b/html/inc/host.inc
index de2ead5d84..bbd7ed1594 100644
--- a/html/inc/host.inc
+++ b/html/inc/host.inc
@@ -116,7 +116,9 @@ function show_host($host, $private, $ipprivate) {
}
-function host_table_start($private, $show_owner) {
+// The following is used to show a user's hosts
+//
+function user_host_table_start($private) {
start_table();
echo "
";
echo "Computer ID Click for more info | \n";
@@ -125,9 +127,6 @@ function host_table_start($private, $show_owner) {
";
} else {
echo "Rank | ";
- if ($show_owner) {
- echo "Owner | \n";
- }
}
echo "
Recent average credit |
@@ -138,6 +137,32 @@ function host_table_start($private, $show_owner) {
";
}
+// the following is used for list of top hosts
+//
+function top_host_table_start($sort_by) {
+ start_table();
+ echo "
";
+ echo "Computer ID Click for more info | \n";
+ echo "Rank | ";
+ echo "Owner | \n";
+ if ($sort_by == 'total_credit') {
+ echo "
+ Recent average credit |
+ Total credit |
+ ";
+ } else {
+ echo "
+ Recent average credit |
+ Total credit |
+ ";
+ }
+ echo "
+ CPU type |
+ Operating system |
+
+ ";
+}
+
function host_nresults($host) {
$result = mysql_query("select count(*) as nresults from result where hostid=$host->id");
$foobar = mysql_fetch_object($result);
diff --git a/html/inc/team.inc b/html/inc/team.inc
index 999839168e..1f737efcc5 100644
--- a/html/inc/team.inc
+++ b/html/inc/team.inc
@@ -104,13 +104,24 @@ function require_founder_login($user, $team) {
}
}
-function team_table_start() {
+function team_table_start($sort_by) {
echo "
Rank |
Name |
Members |
- Recent average credit |
- Total credit |
+ ";
+ if ($sort_by == "total_credit") {
+ echo "
+ Recent average credit |
+ Total credit |
+ ";
+ } else {
+ echo "
+ Recent average credit |
+ Total credit |
+ ";
+ }
+ echo "
Country |
";
diff --git a/html/inc/user.inc b/html/inc/user.inc
index 50912bd7c3..904a4f9caf 100644
--- a/html/inc/user.inc
+++ b/html/inc/user.inc
@@ -132,14 +132,25 @@ function show_user_page_private($user) {
end_table();
}
-function user_table_start() {
+function user_table_start($sort_by) {
start_table();
echo "
Rank |
Name |
- Recent average credit |
- Total credit |
+ ";
+ if ($sort_by == "total_credit") {
+ echo "
+ Recent average credit |
+ Total credit |
+ ";
+ } else {
+ echo "
+ Recent average credit |
+ Total credit |
+ ";
+ }
+ echo "
Country |
Participant since |
diff --git a/html/user/host_update_credit.php b/html/user/host_update_credit.php
index 3baa91dff8..5a9123bb7a 100644
--- a/html/user/host_update_credit.php
+++ b/html/user/host_update_credit.php
@@ -24,20 +24,40 @@ function get_host($hostid, $user) {
$hostid = $_GET["hostid"];
$latest_host = get_host($hostid, $user);
- $r = mysql_query("select * from result where hostid=$hostid");
+ $r = mysql_query("select * from result where hostid=$hostid order by received_time");
$t = 0;
- $a = 0;
+ $avg = 0;
$hl = 86400*7;
$now = time();
+ $avg_time = 0;
+ $half_life = 86400*7;
while ($result = mysql_fetch_object($r)) {
+ if ($result->granted_credit <= 0) continue;
$t += $result->granted_credit;
- $td = $now - $result->received_time;
- $a += $result->granted_credit*exp(-$td*M_LN2/$hl);
+
+ // the following taken from lib/util.C
+ //
+ if ($avg_time) {
+ $diff = $result->received_time - $avg_time;
+ if ($diff <=0) $diff = 3600;
+ $diff_days = $diff/86400;
+ $weight = exp(-$diff*M_LN2/$half_life);
+ $avg *= $weight;
+ $avg += (1-$weight)*($result->granted_credit/$diff_days);
+ } else {
+ $dd = ($result->received_time - $result->sent_time)/86400;
+ $avg = $result->granted_credit/$dd;
+ }
+ $avg_time = $result->received_time;
+ echo "
$avg\n";
}
- $a /= 2; // not sure why this is needed
mysql_free_result($r);
- mysql_query("update host set total_credit=$t, expavg_credit=$a where id=$hostid");
- echo "Host credit updated";
+
+ $diff = $now - $avg_time;
+ $weight = exp(-$diff*M_LN2/$half_life);
+ $avg *= $weight;
+ mysql_query("update host set total_credit=$t, expavg_credit=$avg where id=$hostid");
+ echo "
Host credit updated";
page_tail();
?>
diff --git a/html/user/hosts_user.php b/html/user/hosts_user.php
index 5976568b15..cee6121ad8 100644
--- a/html/user/hosts_user.php
+++ b/html/user/hosts_user.php
@@ -14,7 +14,7 @@
mysql_free_result($result);
if ($user->show_hosts) {
page_head("Computers belonging to $user->name");
- host_table_start(false, false);
+ user_host_table_start(false);
} else {
echo "Hidden\n";
exit();
@@ -24,7 +24,7 @@
$user = get_logged_in_user();
$userid = $user->id;
page_head("Your computers");
- host_table_start(true, false);
+ user_host_table_start(true);
$private = true;
}
$i = 1;
diff --git a/html/user/top_hosts.php b/html/user/top_hosts.php
index 9cefc475ae..78fb9a0845 100644
--- a/html/user/top_hosts.php
+++ b/html/user/top_hosts.php
@@ -21,12 +21,12 @@
db_init();
page_head("Top computers");
if ($sort_by == "total_credit") {
- $sort_clause = "total_credit desc, total_credit desc";
+ $sort_clause = "total_credit desc";
} else {
- $sort_clause = "expavg_credit desc, total_credit desc";
+ $sort_clause = "expavg_credit desc";
}
$result = mysql_query("select * from host order by $sort_clause limit $n offset $offset");
- host_table_start(false, true);
+ top_host_table_start($sort_by);
$i = $offset+1;
while ($host = mysql_fetch_object($result)) {
show_host_row($host, $i, false, true);
diff --git a/html/user/top_teams.php b/html/user/top_teams.php
index e25b3a0f47..d2d831f539 100644
--- a/html/user/top_teams.php
+++ b/html/user/top_teams.php
@@ -14,14 +14,14 @@
page_head("Top teams");
if ($sort_by == "total_credit") {
- $sort_by = "total_credit desc, total_credit desc";
+ $sort_clause = "total_credit desc";
} else {
- $sort_by = "expavg_credit desc, total_credit desc";
+ $sort_clause = "expavg_credit desc";
}
- $result = mysql_query("select * from team order by $sort_by");
+ $result = mysql_query("select * from team order by $sort_clause");
start_table();
row1("Teams", 6);
- team_table_start();
+ team_table_start($sort_by);
$i = 1;
while ($team = mysql_fetch_object($result)) {
show_team_row($team, $i);
diff --git a/html/user/top_users.php b/html/user/top_users.php
index dcd36db16e..d9f21f6fc6 100644
--- a/html/user/top_users.php
+++ b/html/user/top_users.php
@@ -19,7 +19,7 @@
$numusers = 100;
page_head("Top $numusers participants");
$result = mysql_query("select * from user order by $sort_order limit $numusers");
- user_table_start();
+ user_table_start($sort_by);
$i = 0;
while ($user = mysql_fetch_object($result)) {
show_user_row($user, ++$i);