From 38e20515b0fd6f35b15152478fbe67b12c41496c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 2 Jan 2003 21:52:13 +0000 Subject: [PATCH] average credit formula svn path=/trunk/boinc/; revision=792 --- sched/validate.C | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sched/validate.C b/sched/validate.C index 7061131f17..16e3b98729 100644 --- a/sched/validate.C +++ b/sched/validate.C @@ -68,11 +68,11 @@ int min_quorum; // log(2) #define SECONDS_IN_DAY (3600*24) #define AVG_HALF_LIFE (SECONDS_IN_DAY*7) -#define ALPHA (1./(AVG_HALF_LIFE*LOG2)) +#define ALPHA (LOG2/AVG_HALF_LIFE) // update an exponential average of credit per second. // -void update_average(double credit, double& avg, double& avg_time) { +void update_average(double credit_assigned_time, double credit, double& avg, double& avg_time) { time_t now = time(0); // decrease existing average according to how long it's been @@ -80,9 +80,12 @@ void update_average(double credit, double& avg, double& avg_time) { // if (avg_time) { double deltat = now - avg_time; - avg *= exp(-deltat/ALPHA); + avg *= exp(-deltat*ALPHA); } - avg += credit*ALPHA; + double deltat = now - credit_assigned_time; + // Add (credit)/(number of days to return result) to credit, which + // is the average number of cobblestones per day + avg += credit/(deltat/86400); avg_time = now; } @@ -100,12 +103,12 @@ int grant_credit(RESULT& result, double credit) { if (retval) return retval; user.total_credit += credit; - update_average(credit, user.expavg_credit, user.expavg_time); + update_average(result.sent_time, credit, user.expavg_credit, user.expavg_time); retval = db_user_update(user); if (retval) return retval; host.total_credit += credit; - update_average(credit, host.expavg_credit, host.expavg_time); + update_average(result.sent_time, credit, host.expavg_credit, host.expavg_time); retval = db_host_update(host); if (retval) return retval;