2013-12-05 18:14:26 +00:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2013 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/>.
|
|
|
|
|
2013-12-20 23:03:24 +00:00
|
|
|
// Assign badges based on RAC percentile.
|
2013-12-05 18:14:26 +00:00
|
|
|
// Customize this to grant other types of badges
|
|
|
|
|
2013-12-20 23:03:24 +00:00
|
|
|
require_once("../inc/util_ops.inc");
|
2013-12-05 18:14:26 +00:00
|
|
|
|
2013-12-20 23:03:24 +00:00
|
|
|
// thresholds for the various badges
|
|
|
|
// (i.e. gold badge is for top 1% of active users/teams)
|
|
|
|
//
|
2013-12-21 07:18:07 +00:00
|
|
|
$badge_pctiles = array(1, 5, 25);
|
2013-12-23 04:39:52 +00:00
|
|
|
$badge_images = array("pct_1.png", "pct_5.png", "pct_25.png");
|
2013-12-05 18:14:26 +00:00
|
|
|
|
2013-12-21 07:18:07 +00:00
|
|
|
// get the records for percentile badges; create them if needed
|
2013-12-20 23:03:24 +00:00
|
|
|
//
|
|
|
|
function get_pct_badges($badge_name_prefix, $badge_pctiles, $badge_images) {
|
|
|
|
$badges = array();
|
|
|
|
for ($i=0; $i<3; $i++) {
|
2013-12-24 06:13:27 +00:00
|
|
|
$badges[$i] = get_badge($badge_name_prefix."_".$i, "Top ".$badge_pctiles[$i]."% in average credit", $badge_images[$i]);
|
2013-12-05 18:14:26 +00:00
|
|
|
}
|
2013-12-20 23:03:24 +00:00
|
|
|
return $badges;
|
2013-12-05 18:14:26 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 07:18:07 +00:00
|
|
|
// get the RAC percentiles from the database
|
2013-12-20 23:03:24 +00:00
|
|
|
//
|
|
|
|
function get_percentiles($is_user, $badge_pctiles) {
|
|
|
|
$percentiles = array();
|
|
|
|
for ($i=0; $i<3; $i++) {
|
|
|
|
if ($is_user) {
|
|
|
|
$percentiles[$i] = BoincUser::percentile("expavg_credit", "expavg_credit>1", 100-$badge_pctiles[$i]);
|
2013-12-05 18:14:26 +00:00
|
|
|
} else {
|
2013-12-20 23:03:24 +00:00
|
|
|
$percentiles[$i] = BoincTeam::percentile("expavg_credit", "expavg_credit>1", 100-$badge_pctiles[$i]);
|
|
|
|
}
|
|
|
|
if ($percentiles[$i] === false) {
|
|
|
|
die("Can't get percentiles\n");
|
2013-12-05 18:14:26 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 23:03:24 +00:00
|
|
|
return $percentiles;
|
2013-12-05 18:14:26 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 07:18:07 +00:00
|
|
|
// decide which badge to assign, if any.
|
|
|
|
// Unassign other badges.
|
|
|
|
//
|
2013-12-20 23:03:24 +00:00
|
|
|
function assign_pct_badge($is_user, $item, $percentiles, $badges) {
|
|
|
|
for ($i=0; $i<3; $i++) {
|
|
|
|
if ($item->expavg_credit >= $percentiles[$i]) {
|
|
|
|
assign_badge($is_user, $item, $badges[$i]);
|
|
|
|
unassign_badges($is_user, $item, $badges, $i);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-05 18:14:26 +00:00
|
|
|
}
|
2013-12-20 23:03:24 +00:00
|
|
|
unassign_badges($is_user, $item, $badges, -1);
|
2013-12-05 18:14:26 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 07:18:07 +00:00
|
|
|
// Scan through all the users/teams, 1000 at a time,
|
|
|
|
// and assign/unassign RAC badges
|
|
|
|
//
|
2013-12-20 23:03:24 +00:00
|
|
|
function assign_badges($is_user, $badge_pctiles, $badge_images) {
|
|
|
|
$kind = $is_user?"user":"team";
|
|
|
|
$badges = get_pct_badges($kind."_pct", $badge_pctiles, $badge_images);
|
|
|
|
$pctiles = get_percentiles($is_user, $badge_pctiles);
|
2014-09-24 07:55:03 +00:00
|
|
|
//echo "thresholds for $kind badges: $pctiles[0] $pctiles[1] $pctiles[2]\n";
|
2013-12-05 18:14:26 +00:00
|
|
|
|
|
|
|
$n = 0;
|
2013-12-20 23:03:24 +00:00
|
|
|
$maxid = $is_user?BoincUser::max("id"):BoincTeam::max("id");
|
2013-12-05 18:14:26 +00:00
|
|
|
while ($n <= $maxid) {
|
|
|
|
$m = $n + 1000;
|
2013-12-20 23:03:24 +00:00
|
|
|
if ($is_user) {
|
|
|
|
$items = BoincUser::enum_fields("id, expavg_credit", "id>=$n and id<$m and total_credit>0");
|
|
|
|
} else {
|
|
|
|
$items = BoincTeam::enum_fields("id, expavg_credit", "id>=$n and id<$m and total_credit>0");
|
|
|
|
}
|
|
|
|
foreach ($items as $item) {
|
|
|
|
assign_pct_badge($is_user, $item, $pctiles, $badges);
|
|
|
|
// ... assign other types of badges
|
2013-12-05 18:14:26 +00:00
|
|
|
}
|
|
|
|
$n = $m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 07:55:03 +00:00
|
|
|
echo "Starting: ", time_str(time()), "\n";
|
|
|
|
|
2013-12-20 23:03:24 +00:00
|
|
|
assign_badges(true, $badge_pctiles, $badge_images);
|
|
|
|
assign_badges(false, $badge_pctiles, $badge_images);
|
2013-12-05 18:14:26 +00:00
|
|
|
|
2014-09-24 07:55:03 +00:00
|
|
|
echo "Finished: ", time_str(time()), "\n";
|
|
|
|
|
2013-12-05 18:14:26 +00:00
|
|
|
?>
|