2014-09-28 15:11:51 +00:00
|
|
|
<?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");
|
2014-10-09 19:01:33 +00:00
|
|
|
require_once("../inc/team.inc");
|
2014-09-28 15:11:51 +00:00
|
|
|
|
2017-03-08 16:33:23 +00:00
|
|
|
check_get_args(array("is_team", "appid", "is_total", "offset"));
|
|
|
|
|
|
|
|
define ('ITEM_LIMIT', 10000);
|
|
|
|
|
2014-09-28 15:11:51 +00:00
|
|
|
// 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> </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) {
|
2017-03-08 16:33:23 +00:00
|
|
|
global $i;
|
2014-09-28 15:11:51 +00:00
|
|
|
if ($is_team) {
|
|
|
|
$team = BoincTeam::lookup_id($item->teamid);
|
2017-03-08 16:33:23 +00:00
|
|
|
if (!$team) {
|
|
|
|
$i--;
|
|
|
|
return;
|
|
|
|
}
|
2014-09-28 15:11:51 +00:00
|
|
|
$x = "<td>".team_links($team)."</td>\n";
|
|
|
|
} else {
|
|
|
|
$user = BoincUser::lookup_id($item->userid);
|
2017-03-08 16:33:23 +00:00
|
|
|
if (!$user) {
|
|
|
|
$i--;
|
|
|
|
return;
|
|
|
|
}
|
2014-09-28 15:11:51 +00:00
|
|
|
$x= "<td>".user_links($user, BADGE_HEIGHT_MEDIUM)."</td>\n";
|
|
|
|
}
|
2016-11-11 20:36:27 +00:00
|
|
|
echo "<tr>";
|
2014-09-28 15:11:51 +00:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2017-03-08 16:33:23 +00:00
|
|
|
function get_top_items($is_team, $appid, $is_total, $offset) {
|
|
|
|
global $items_per_page;
|
2014-09-28 15:11:51 +00:00
|
|
|
$x = $is_total?"total":"expavg";
|
|
|
|
if ($is_team) {
|
2017-03-08 16:33:23 +00:00
|
|
|
return BoincCreditTeam::enum("appid=$appid order by $x desc limit $offset,$items_per_page");
|
2014-09-28 15:11:51 +00:00
|
|
|
} else {
|
2017-03-08 16:33:23 +00:00
|
|
|
return BoincCreditUser::enum("appid=$appid order by $x desc limit $offset,$items_per_page");
|
2014-09-28 15:11:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$is_team = get_int('is_team', true);
|
|
|
|
$appid = get_int('appid', true);
|
|
|
|
$is_total = get_int('is_total', true);
|
2017-03-08 16:33:23 +00:00
|
|
|
$items_per_page = 20;
|
|
|
|
$offset = get_int('offset', true);
|
|
|
|
if (!$offset) $offset=0;
|
|
|
|
if ($offset % $items_per_page) $offset = 0;
|
|
|
|
$x = $is_team?"teams":"participants";
|
2017-03-16 10:35:59 +00:00
|
|
|
page_head(tra("Top %1 by application", $x));
|
2017-03-08 16:33:23 +00:00
|
|
|
$apps = BoincApp::enum("deprecated=0");
|
|
|
|
if (!$appid) {
|
|
|
|
$appid = $apps[0]->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($offset < ITEM_LIMIT) {
|
|
|
|
$cache_args = "appid=$appid&is_team=$is_team&is_total=$is_total&offset=$offset";
|
|
|
|
$cacheddata = get_cached_data(TOP_PAGES_TTL,$cache_args);
|
|
|
|
|
|
|
|
// Do we have the data in cache?
|
|
|
|
//
|
|
|
|
if ($cacheddata){
|
|
|
|
$data = unserialize($cacheddata); // use the cached data
|
|
|
|
} else {
|
|
|
|
//if not do queries etc to generate new data
|
|
|
|
$data = get_top_items($is_team, $appid, $is_total, $offset);
|
|
|
|
|
|
|
|
//save data in cache
|
|
|
|
//
|
|
|
|
set_cached_data(TOP_PAGES_TTL, serialize($data),$cache_args);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error_page(tra("Limit exceeded - Sorry, first %1 items only", ITEM_LIMIT));
|
|
|
|
}
|
|
|
|
|
|
|
|
start_table('table_striped');
|
|
|
|
show_header($is_team, $apps, $appid, $is_total);
|
|
|
|
$i = 1 + $offset;
|
|
|
|
$n = sizeof($data);
|
|
|
|
|
|
|
|
foreach ($data as $item) {
|
|
|
|
show_row($item, $apps, $is_team, $i);
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
end_table();
|
|
|
|
|
|
|
|
if ($offset > 0) {
|
|
|
|
$new_offset = $offset - $items_per_page;
|
|
|
|
echo "<a href=per_app_list.php?appid=$appid&is_team=$is_team&is_total=$is_total&offset=$new_offset>".tra("Previous %1", $items_per_page)."</a> · ";
|
|
|
|
}
|
|
|
|
|
2017-03-16 10:35:59 +00:00
|
|
|
if ($n == $items_per_page) {
|
2017-03-08 16:33:23 +00:00
|
|
|
$new_offset = $offset + $items_per_page;
|
|
|
|
echo "<a href=per_app_list.php?appid=$appid&is_team=$is_team&is_total=$is_total&offset=$new_offset>".tra("Next %1", $items_per_page)."</a>";
|
|
|
|
}
|
2014-09-28 15:11:51 +00:00
|
|
|
|
2017-03-08 16:33:23 +00:00
|
|
|
page_tail();
|
2014-09-28 15:11:51 +00:00
|
|
|
|
|
|
|
?>
|