2004-11-01 23:10:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|