/* javascript routines for ers09 instrument */
  
function computeStats() {
 controlVars['FUNCTION_SUCCESS']=0 ;              // assume failure

var nrounds,clientIDs,poo,useShares,useDiscounts,shareList,discountsList;
var vv,sums1; 
// current round

rlist=extractRoundList('w')
nround=getVarInfo('nowround.g','value');

poo='<h4>>Current round: '+nround + ' </h4> \n ';

vv=extractClientData('W','*','NSUBMITS NACCEPT TOTALEARNALLACCEPT TOTALCOSTALLACCEPT TOTALCOSTALLREJECT MAXACCEPT MINREJECT',0);

z=createDO(rlist);
z.addDO(vv,'NSUBMITS NACCEPT TOTALEARNALLACCEPT TOTALCOSTALLACCEPT TOTALCOSTALLREJECT MAXACCEPT MINJREJECT');

sums1=[];
for (var i=0;i<rlist.length;i++) {
   var vv=extractRoundData('S',rlist[i],'QPOINTS_USED[1] QPOINTS_USED[2] ',0);
   sums1[i]=sumArray(vv);
}
 
z.addDO(sums1,'QPOINTS1 QPOINTS2');
ast=z.displayDO('*',0,1,10);
writeDoStatus('<h3>Stats ... (for  each round) </h3>'+ast);


// ===== all round stats
var sums=[];
sums[0]=sumArray(z.NSUBMITS);
sums[1]=sumArray(z.NACCEPT);
sums[2]=sumArray(z.TOTALEARNALLACCEPT);
sums[3]=sumArray(z.TOTALCOSTALLACCEPT);
sums[4]=sumArray(z.TOTALCOSTALLREJECT);
var zsum=createDO(sums,'NSUBMITS NACCEPT TOTALEARNALLACCEPT TOTALCOSTALLACCEPT TOTALCOSTALLREJECT');

ast=zsum.displayDO('*',0,1,10);
writeDoStatus('<h3>Totals: across all rounds </h3>'+ast);

}

/*  ======================= */
 






