From f8de41798776f8c00b277391fb984dcfd256de5d Mon Sep 17 00:00:00 2001 From: Bruce Allen Date: Fri, 29 Apr 2005 19:22:43 +0000 Subject: [PATCH] Fixed update_average() function to do the right thing when the time between successive calls is small (zero seconds): Consider the limit as diff->0, using the first-order Taylor expansion of exp(x)=1+x+O(x^2). So to the lowest order in diff: weight = 1 - diff ln(2) / half_life so one has avg += (1-weight)*(work/diff_days) avg += [diff*ln(2)/half_life] * (work*SECONDS_PER_DAY/diff) notice that diff cancels out, leaving avg += [ln(2)/half_life] * work*SECONDS_PER_DAY svn path=/trunk/boinc/; revision=5978 --- checkin_notes | 3 +++ html/inc/credit.inc | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/checkin_notes b/checkin_notes index b441105479..5a8a198863 100755 --- a/checkin_notes +++ b/checkin_notes @@ -5870,4 +5870,7 @@ Bruce 29 April 2005 lib/ util.C + html/ + inc/ + credit.inc diff --git a/html/inc/credit.inc b/html/inc/credit.inc index 7cdcb56350..e4ab635191 100644 --- a/html/inc/credit.inc +++ b/html/inc/credit.inc @@ -8,11 +8,17 @@ define("CREDIT_HALF_LIFE", 86400*7); function update_average($now, $work_start_time, $work, &$avg, &$avg_time) { if ($avg_time) { $diff = $now - $avg_time; - if ($diff <=0) $diff = 3600; + if ($diff <0) $diff = 0; $diff_days = $diff/86400; $weight = exp(-$diff*M_LN2/CREDIT_HALF_LIFE); $avg *= $weight; - $avg += (1-$weight)*($work/$diff_days); + + if ((1.0-$weight)>0.000001) { + $avg += (1.0-$weight)*($work/$diff_days); + } + else { + $avg += M_LN2*work*86400/CREDIT_HALF_LIFE; + } } else if ($work) { $dd = ($now - $work_start_time)/86400; $avg = $work/$dd;