2004-11-01 23:10:02 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 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/>.
|
2004-11-01 23:10:02 +00:00
|
|
|
|
|
|
|
define("CREDIT_HALF_LIFE", 86400*7);
|
|
|
|
|
|
|
|
// update a credit average.
|
|
|
|
// this must match the function in lib/util.C
|
|
|
|
|
|
|
|
function update_average($now, $work_start_time, $work, &$avg, &$avg_time) {
|
|
|
|
if ($avg_time) {
|
|
|
|
$diff = $now - $avg_time;
|
2005-04-29 19:22:43 +00:00
|
|
|
if ($diff <0) $diff = 0;
|
2004-11-01 23:10:02 +00:00
|
|
|
$diff_days = $diff/86400;
|
|
|
|
$weight = exp(-$diff*M_LN2/CREDIT_HALF_LIFE);
|
|
|
|
$avg *= $weight;
|
2005-04-29 19:22:43 +00:00
|
|
|
|
|
|
|
if ((1.0-$weight)>0.000001) {
|
|
|
|
$avg += (1.0-$weight)*($work/$diff_days);
|
|
|
|
}
|
|
|
|
else {
|
2005-04-29 19:31:02 +00:00
|
|
|
$avg += M_LN2*$work*86400/CREDIT_HALF_LIFE;
|
2005-04-29 19:22:43 +00:00
|
|
|
}
|
2004-11-01 23:10:02 +00:00
|
|
|
} else if ($work) {
|
|
|
|
$dd = ($now - $work_start_time)/86400;
|
|
|
|
$avg = $work/$dd;
|
|
|
|
}
|
|
|
|
$avg_time = $now;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|