Example #1
0
function grant_credits_for_wu($wuid)
{
    $max_credit = 300;
    $ndone = 0;
    $query_r = _mysql_query("select * from result where granted_credit=0 and claimed_credit>0 and workunitid={$wuid}");
    while ($result = _mysql_fetch_object($query_r)) {
        echo "STARTING RESULT {$result->id} [Credit {$result->claimed_credit}] ...";
        $ndone++;
        $hostid = $result->hostid;
        $query_h = _mysql_query("select * from host where id={$hostid}");
        $host = _mysql_fetch_object($query_h);
        $userid = $result->userid;
        $query_u = _mysql_query("select * from user where id={$userid}");
        $user = _mysql_fetch_object($query_u);
        $credit = $result->claimed_credit;
        if ($credit > $max_credit) {
            $credit = $max_credit;
            echo " WARNING: USER {$user->name} ({$userid}) CLAIMED {$result->claimed_credit} CREDITS (getting {$credit})!";
        }
        $user->total_credit += $credit;
        update_average(time(0), $result->sent_time, $credit, $user->expavg_credit, $user->expavg_time);
        $host->total_credit += $credit;
        update_average(time(0), $result->sent_time, $credit, $host->expavg_credit, $host->expavg_time);
        $turnaround = $result->received_time - $result->sent_time;
        if ($host->avg_turnaround > 0) {
            $host->avg_turnaround = 0.7 * $host->avg_turnaround + 0.3 * $turnaround;
        } else {
            $host->avg_turnaround = $turnaround;
        }
        testquery("update result set granted_credit={$credit} where id={$result->id}");
        testquery("update user set total_credit={$user->total_credit}, expavg_credit={$user->expavg_credit}, expavg_time={$user->expavg_time} where id={$userid}");
        testquery("update host set total_credit={$host->total_credit}, expavg_credit={$host->expavg_credit}, expavg_time={$host->expavg_time}, avg_turnaround={$host->avg_turnaround} where id={$hostid}");
        $teamid = $user->teamid;
        if ($teamid) {
            $query_t = _mysql_query("select * from team where id={$teamid}");
            $team = _mysql_fetch_object($query_t);
            $team->total_credit += $credit;
            update_average(time(0), $result->sent_time, $credit, $team->expavg_credit, $team->expavg_time);
            testquery("update team set total_credit={$team->total_credit}, expavg_credit={$team->expavg_credit}, expavg_time={$team->expavg_time} where id={$teamid}");
            _mysql_free_result($query_t);
        }
        _mysql_free_result($query_h);
        _mysql_free_result($query_u);
        echo " DONE\n";
    }
    _mysql_free_result($query_r);
    return $ndone;
}
function decay($is_user)
{
    $now = time();
    if ($is_user) {
        $cs = BoincCreditUser::enum("");
    } else {
        $cs = BoincCreditTeam::enum("");
    }
    foreach ($cs as $c) {
        update_average($now, 0, 0, $c->expavg, $c->expavg_time);
        if ($is_user) {
            $c->update("expavg={$c->expavg}, expavg_time={$c->expavg_time} where userid={$c->userid} and appid={$c->appid}");
        } else {
            $c->update("expavg={$c->expavg}, expavg_time={$c->expavg_time} where teamid={$c->teamid} and appid={$c->appid}");
        }
    }
}