// fill in the nusers, total_credit and expavg_credit fields // of the team table. // This may take a while; don't do it often // int update_teams() { DB_TEAM team; int retval; char buf[256]; while (1) { retval = team.enumerate("where expavg_credit>0.1"); if (retval) { if (retval != ERR_DB_NOT_FOUND) { log_messages.printf(MSG_CRITICAL, "lost DB conn\n"); exit(1); } break; } retval = get_team_totals(team); if (retval) { log_messages.printf(MSG_CRITICAL, "update_teams: get_team_credit([TEAM#%d]) failed: %d\n", team.id, retval ); continue; } if (team.expavg_time < update_time_cutoff) { update_average(0, 0, CREDIT_HALF_LIFE, team.expavg_credit, team.expavg_time); } sprintf( buf, "expavg_credit=%f, expavg_time=%f, nusers=%d", team.expavg_credit, team.expavg_time, team.nusers ); retval = team.update_field(buf); if (retval) { log_messages.printf(MSG_CRITICAL, "Can't update team %d\n", team.id); return retval; } } return 0; }
// Grant the host (and associated user and team) // the given amount of credit for work that started at the given time. // Update the user and team records, // but not the host record (caller must update) // int grant_credit(DB_HOST& host, double start_time, double credit) { DB_USER user; DB_TEAM team; int retval; char buf[256]; double now = dtime(); // first, process the host update_average( now, start_time, credit, CREDIT_HALF_LIFE, host.expavg_credit, host.expavg_time ); host.total_credit += credit; // then the user retval = user.lookup_id(host.userid); if (retval) { log_messages.printf(MSG_CRITICAL, "lookup of user %d failed: %s\n", host.userid, boincerror(retval) ); return retval; } update_average( now, start_time, credit, CREDIT_HALF_LIFE, user.expavg_credit, user.expavg_time ); sprintf( buf, "total_credit=total_credit+%.15e, expavg_credit=%.15e, expavg_time=%.15e", credit, user.expavg_credit, user.expavg_time ); retval = user.update_field(buf); if (retval) { log_messages.printf(MSG_CRITICAL, "update of user %d failed: %s\n", host.userid, boincerror(retval) ); } // and finally the team if (user.teamid) { retval = team.lookup_id(user.teamid); if (retval) { log_messages.printf(MSG_CRITICAL, "lookup of team %d failed: %s\n", user.teamid, boincerror(retval) ); return retval; } update_average( now, start_time, credit, CREDIT_HALF_LIFE, team.expavg_credit, team.expavg_time ); sprintf(buf, "total_credit=total_credit+%.15e, expavg_credit=%.15e, expavg_time=%.15e", credit, team.expavg_credit, team.expavg_time ); retval = team.update_field(buf); if (retval) { log_messages.printf(MSG_CRITICAL, "update of team %d failed: %s\n", team.id, boincerror(retval) ); } } return 0; }