static void update_power_supply_attribute(struct power_supply_attribute * instance) { struct charging_query query={instance->check_type,instance->power_supply_type ,instance->property_enum,{0}} ; if (class_for_each_device(power_supply_class,NULL,&query,_power_supply_get_property)) { instance->last_value= query.value.intval; if (instance->average) { if(instance->property_enum == POWER_SUPPLY_PROP_VOLTAGE_MIN) update_average(instance->average ,instance->last_value / 1000) ; else update_average(instance->average ,instance->last_value) ; } } }
int update_hosts() { DB_HOST host; int retval; char buf[256]; while (1) { retval = host.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; } if (host.expavg_time > update_time_cutoff) continue; update_average(0, 0, CREDIT_HALF_LIFE, host.expavg_credit, host.expavg_time); sprintf( buf,"expavg_credit=%f, expavg_time=%f", host.expavg_credit, host.expavg_time ); retval = host.update_field(buf); if (retval) { log_messages.printf(MSG_CRITICAL, "Can't update host %d\n", host.id); return retval; } } return 0; }
void CTimeHistogram::update(){ m_max_ar[m_win_cnt]=m_max_win_dt; m_max_win_last_dt=m_max_win_dt; m_max_win_dt=0.0; m_win_cnt++; if (m_win_cnt==HISTOGRAM_QUEUE_SIZE) { m_win_cnt=0; } update_average(); }
static void update_adc_attribute(struct adc_attribute * instance) { if( instance->adc_code != 0 ) { instance->last_value = ab8500_gpadc_read_raw(ab8500_gpadc_get(), instance->adc_code, SAMPLE_16, RISING_EDGE, 0, ADC_SW); if (instance->average) update_average(instance->average ,instance->last_value); } }
static void update_callback_attribute(struct callback_attribute * instance) { int ret = -1; int val ; if (instance->update){ ret = instance->update(instance,&val); } if (ret==0) { instance->last_value = val ; if (instance->average) update_average(instance->average ,val) ; } }
// 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; }
// called after file xfer to update rates // void NET_INFO::update(double nbytes, double dt) { if (nbytes == 0 || dt==0) return; double bytes_sec = nbytes/dt; if (max_rate == 0) { max_rate = bytes_sec; // first time } else { // somewhat arbitrary weighting formula // double w = log(nbytes)/500; if (w>1) w = 1; max_rate = w*bytes_sec + (1-w)*max_rate; } double start_time = gstate.now - dt; update_average( gstate.now, start_time, nbytes, NET_RATE_HALF_LIFE, avg_rate, avg_time ); }
// carefully write any app_version records that have changed; // done at the end of every validator scan. // int write_modified_app_versions(vector<DB_APP_VERSION>& app_versions) { unsigned int i, j; int retval = 0; double now = dtime(); for (i=0; i<app_versions.size(); i++) { DB_APP_VERSION& av = app_versions[i]; if (av.pfc_samples.empty() && av.credit_samples.empty()) { continue; } for (int k=0; k<10; k++) { double pfc_n_orig = av.pfc.n; double expavg_credit_orig = av.expavg_credit; for (j=0; j<av.pfc_samples.size(); j++) { av.pfc.update( av.pfc_samples[j], AV_AVG_THRESH, AV_AVG_WEIGHT, AV_AVG_LIMIT ); } for (j=0; j<av.credit_samples.size(); j++) { update_average( now, av.credit_times[j], av.credit_samples[j], CREDIT_HALF_LIFE, av.expavg_credit, av.expavg_time ); } char query[512], clause[512]; sprintf(query, "pfc_n=%.15e, pfc_avg=%.15e, expavg_credit=%.15e, expavg_time=%f", av.pfc.n, av.pfc.avg, av.expavg_credit, av.expavg_time ); if (config.debug_credit) { log_messages.printf(MSG_NORMAL, "[credit] updating app version %d:\n", av.id ); log_messages.printf(MSG_NORMAL, "[credit] pfc.n = %f, pfc.avg = %f, expavg_credit = %f, expavg_time=%f\n", av.pfc.n, av.pfc.avg, av.expavg_credit, av.expavg_time ); } // if pfc_scale has changed (from feeder) reread it // sprintf(clause, "pfc_n=%.15e and abs(expavg_credit-%.15e)<1e-4 and abs(pfc_scale-%.15e)<1e-6", pfc_n_orig, expavg_credit_orig, av.pfc_scale ); retval = av.update_field(query, clause); if (retval) break; if (boinc_db.affected_rows() == 1) break; retval = av.lookup_id(av.id); if (retval) break; } av.pfc_samples.clear(); av.credit_samples.clear(); av.credit_times.clear(); if (retval) 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; }
int grant_credit_by_app(RESULT& result, double credit) { DB_CREDIT_USER cu; char clause1[1024], clause2[1024]; double now = dtime(); sprintf(clause1, "where userid=%lu and appid=%lu", result.userid, result.appid); int retval = cu.lookup(clause1); if (retval) { cu.clear(); cu.userid = result.userid; cu.appid = result.appid; cu.expavg_time = dtime(); retval = cu.insert(); if (retval) return retval; } update_average( now, result.sent_time, credit, CREDIT_HALF_LIFE, cu.expavg, cu.expavg_time ); sprintf(clause1, "total=total+%.15e, expavg=%.15e, expavg_time=%.15e, njobs=njobs+1", credit, cu.expavg, cu.expavg_time ); sprintf(clause2, "userid=%lu and appid=%lu", result.userid, result.appid ); retval = cu.update_fields_noid(clause1, clause2); if (retval) return retval; // team. keep track of credit for zero (no team) also // DB_CREDIT_TEAM ct; sprintf(clause1, "where teamid=%lu and appid=%lu", result.teamid, result.appid); retval = ct.lookup(clause1); if (retval) { ct.clear(); ct.teamid = result.teamid; ct.appid = result.appid; ct.expavg_time = dtime(); retval = ct.insert(); if (retval) return retval; } update_average( now, result.sent_time, credit, CREDIT_HALF_LIFE, ct.expavg, ct.expavg_time ); sprintf(clause1, "total=total+%.15e, expavg=%.15e, expavg_time=%.15e, njobs=njobs+1", credit, ct.expavg, ct.expavg_time ); sprintf(clause2, "teamid=%lu and appid=%lu", result.teamid, result.appid ); retval = ct.update_fields_noid(clause1, clause2); if (retval) return retval; return 0; }