web: add page (per_app_list.php) to show top users/teams by app

Notes:
- it's per app, not per sub-project; that would have been harder
- it only shows the top 20

Also: shuffle code to reduce recursive includes.
This commit is contained in:
David Anderson 2014-09-28 08:11:51 -07:00
parent 087f260cae
commit 1c60e467a7
6 changed files with 175 additions and 36 deletions

View File

@ -684,4 +684,18 @@ class BoincCreditTeam {
}
}
// DEPRECATED: use BoincDb::escape_string where possible
//
// apply this to any user-supplied strings used in queries
//
function boinc_real_escape_string($x) {
if (version_compare(phpversion(),"4.3.0")>=0) {
return BoincDb::escape_string($x);
} else {
$x = str_replace("'", "\'", $x);
$x = str_replace("\"", "\\\"", $x);
return $x;
}
}
?>

View File

@ -16,8 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once('../inc/util.inc');
require_once('../inc/boinc_db.inc');
require_once('../project/project.inc');
// database-related functions.
// Presentation code (HTML) shouldn't be here
@ -25,6 +24,21 @@ require_once('../inc/boinc_db.inc');
// DEPRECATED; use boinc_db.inc instead.
// TODO: replace calls to these functions
// use mysqli if available,
// but let projects not use it if they want
// (by define('NO_MYSQLI', true) in project.inc)
//
if (defined('NO_MYSQLI') && NO_MYSQLI) {
define("MYSQLI", false);
} else {
if (class_exists("mysqli")) {
define("MYSQLI", true);
$mysqli = null;
} else {
define("MYSQLI", false);
}
}
if (MYSQLI) {
function _mysql_connect($host, $user, $pass, $dbname) {
global $mysqli;
@ -170,20 +184,6 @@ function db_init_aux($try_replica=false) {
return 0;
}
// DEPRECATED: use BoincDb::escape_string where possible
//
// apply this to any user-supplied strings used in queries
//
function boinc_real_escape_string($x) {
if (version_compare(phpversion(),"4.3.0")>=0) {
return BoincDb::escape_string($x);
} else {
$x = str_replace("'", "\'", $x);
$x = str_replace("\"", "\\\"", $x);
return $x;
}
}
// escape a string for MySQL "like"
//
function escape_pattern($str) {

View File

@ -16,23 +16,6 @@
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once("../project/project.inc");
// use mysqli if available,
// but let projects not use it if they want
// (by define('NO_MYSQLI', true) in project.inc)
//
if (defined('NO_MYSQLI') && NO_MYSQLI) {
define("MYSQLI", false);
} else {
if (class_exists("mysqli")) {
define("MYSQLI", true);
$mysqli = null;
} else {
define("MYSQLI", false);
}
}
// represents a connection to a database.
// Intended to be subclassed (e.g., BoincDb, BossaDb)
//

View File

@ -383,14 +383,18 @@ function team_table_start($sort_by, $type_url) {
";
}
function team_links($team) {
$b = badges_string(false, $team, BADGE_HEIGHT_MEDIUM);
return "<a href=team_display.php?teamid=$team->id>$team->name</a> $b";
}
function show_team_row($team, $i) {
$team_expavg_credit = format_credit_large($team->expavg_credit);
$team_total_credit = format_credit_large($team->total_credit);
$j = $i % 2;
$b = badges_string(false, $team, BADGE_HEIGHT_MEDIUM);
echo"<tr class=row$j>
<td>$i</td>
<td><a href=team_display.php?teamid=$team->id>$team->name</a> $b</td>
<td>".team_links($team)."</td>
<td align=right>".$team->nusers."</td>
<td align=right>$team_expavg_credit</td>
<td align=right>$team_total_credit</td>

129
html/user/per_app_list.php Normal file
View File

@ -0,0 +1,129 @@
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2014 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// show top users or teams, ordered by per-app credit
//
// URL args:
// is_team: if nonzero, show teams
// appid: ID of app for sorting; default is first app returned by enum
// is_total: if nonzero, sort by total credit
require_once("../inc/util.inc");
// return a column title (Average or Total),
// hyperlinked if this is not the current sort column
//
function col_title($is_team, $app, $appid, $is_total, $i) {
$x = $i?"Total":"Average";
if ($app->id == $appid && ($is_total?$i:!$i)) {
return $x;
} else {
return "<a href=per_app_list.php?appid=$app->id&is_team=$is_team&is_total=$i>$x</a>";
}
}
// print a row of app names,
// under each of which are columns for Average and Total
//
function show_header($is_team, $apps, $appid, $is_total) {
echo "<tr><th colspan=2>&nbsp;</th>";
foreach ($apps as $app) {
echo "<th colspan=2>$app->name</th>\n";
}
echo "</tr>";
echo "<tr>";
echo "<th>Rank</th><th>Name</th>\n";
foreach ($apps as $app) {
for ($i=0; $i<2; $i++) {
$x = col_title($is_team, $app, $appid, $is_total, $i);
echo "<th>$x</th>\n";
}
}
echo "</tr>";
}
// show a user or team, with their credit for each app
//
function show_row($item, $apps, $is_team, $i) {
$j = $i % 2;
if ($is_team) {
$team = BoincTeam::lookup_id($item->teamid);
if (!$team) return;
$x = "<td>".team_links($team)."</td>\n";
} else {
$user = BoincUser::lookup_id($item->userid);
if (!$user) return;
$x= "<td>".user_links($user, BADGE_HEIGHT_MEDIUM)."</td>\n";
}
echo "<tr class=row$j>";
echo "<td>$i</td>\n";
echo $x;
foreach ($apps as $app) {
if ($app->id == $item->appid) {
$c = $item;
} else {
if ($is_team) {
$c = BoincCreditTeam::lookup("teamid=$item->teamid and appid=$app->id");
} else {
$c = BoincCreditUser::lookup("userid=$item->userid and appid=$app->id");
}
if (!$c) {
$c = new StdClass;
$c->expavg = 0;
$c->total = 0;
}
}
echo "<td align=right>".format_credit($c->expavg)."</td><td align=right>".format_credit_large($c->total)."</td>\n";
}
echo "</tr>\n";
}
function show_list($is_team, $appid, $is_total) {
$x = $is_team?"teams":"participants";
page_head("Top $x by application");
$apps = BoincApp::enum("deprecated=0");
if (!$appid) {
$appid = $apps[0]->id;
}
start_table();
show_header($is_team, $apps, $appid, $is_total);
$x = $is_total?"total":"expavg";
if ($is_team) {
$items = BoincCreditTeam::enum("appid=$appid order by $x desc");
} else {
$items = BoincCreditUser::enum("appid=$appid order by $x desc");
}
$i = 0;
foreach ($items as $item) {
show_row($item, $apps, $is_team, $i);
$i++;
}
end_table();
page_tail();
}
$is_team = get_int('is_team', true);
$appid = get_int('appid', true);
$is_total = get_int('is_total', true);
show_list($is_team, $appid, $is_total);
?>

View File

@ -22,20 +22,29 @@ page_head(tra('Statistics and leaderboards'));
check_get_args(array());
$credit_by_app = parse_bool(get_config(), "credit_by_app");
start_table();
echo "
<tr><td>"
. tra("Statistics for %1",PROJECT).":
<ul>
<li><a href=\"top_users.php\">" . tra("Top participants")."</a>
<li><a href=\"top_hosts.php\">" . tra("Top computers")."</a>
";
if ($credit_by_app) {
echo "<ul><li><a href=per_app_list.php>Per application</a></ul>\n";
}
if (!DISABLE_TEAMS) {
echo "
<li><a href=\"top_teams.php\">" . tra("Top teams"). "</a>
";
if ($credit_by_app) {
echo "<ul><li><a href=per_app_list.php?is_team=1>Per application</a></ul>\n";
}
}
echo "
<li><a href=\"top_hosts.php\">" . tra("Top computers")."</a>
<li><a href=\"gpu_list.php\">" . tra("GPU models"). "</a>
<li><a href=\"cpu_list.php\">" . tra("CPU models"). "</a>
</ul>