Stakes

CurrencyStake CountTotalTotal USD
USD411,360.20$ 11,360.20
RMB1275.00$ 41.06
CAN130.00$ 23.57
QAR110.00$ 2.75
Total7$ 11,427.58
void calulate_mean_stdev_total(float *pfMean, float *pfStdv, float *pfTotal, float *pfMax, int count)
{
	int i;

	float fTotal = 0.0;
	float fMean;
	float fStdv = 0.0;
	float fMax = 0.0;
	
	
	for(i = 0; i < count; i++)
	{
		fTotal += stakesUSD[i];
		if(stakesUSD[i] > fMax)
		{
			fMax = stakesUSD[i];
		}
	}

	fMean = fTotal / count;
	
	for(i = 0; i < count; i++)
	{
		float temp = stakesUSD[i] - fMean;
		
		fStdv += (temp * temp);
	}

	fStdv = sqrt(fStdv);
	

	*pfMean = fMean;
	*pfStdv = fStdv;
	*pfTotal = fTotal;
	*pfMax = fMax;



}


void calculate_stakes(float *pfaStakesPercent, int count)
{
	int i;
	float fMean, fStdv, fTotal, fMax;
	float *pfTemp = malloc(sizeof(float) * count);
	float fTotalWhales = 0.0;
	float fLittlePeopleTotal = 0.0;
	float fLimitWhale;

		
	calulate_mean_stdev_total(&fMean, &fStdv, &fTotal, &fMax, count);

	fLimitWhale = (stddev_multiple * fStdv);
		

	printf("mean = %f stddev = %f fTotal = %f fLimitWhale =%f fMax=%f\n",fMean, fStdv, fTotal, fLimitWhale, fMax);



	for(i = 0; i < count; i++)
	{
		if((stakesUSD[i] > fLimitWhale) || (stakesUSD[i] == fMax))
		{
			pfTemp[i] = stakesUSD[i] * -1.0; //marker
			fTotalWhales += pfTemp[i];
		}
		else
		{
			pfTemp[i] = stakesUSD[i] * ((count + 1) - i);
			fLittlePeopleTotal += pfTemp[i];
		}
			
	}

	printf("fTotalWhales = %f fLittlePeopleTotal = %f\n", fTotalWhales, fLittlePeopleTotal);

	for(i = 0; i < count; i++)
	{
		float fPercent;

		printf("pfTemp[%d] = %f\n", i, pfTemp[i]);
		
		if(pfTemp[i] < 0)
		{
			fPercent = ((pfTemp[i]) / fTotalWhales) * (max_percent_whales / 100);

		}
		else
		{
			fPercent = (pfTemp[i] / fLittlePeopleTotal) * ((100 - max_percent_whales) / 100);
		}

		pfaStakesPercent[i] = fPercent;

	}

	


}


void main(void)
{

	int i;
	int count = sizeof(stakesUSD) / sizeof(float);
	float fTotalPercent = 0.0;
	float fTotalAsimov = 0.0;
	float * pfaStakesPercent = malloc(sizeof(float) * count);

	printf("calculate stakes count = %d\n", count);

	calculate_stakes(pfaStakesPercent, count);

	
	for(i = 0; i < count; i++)
	{
		float fAsimov = pfaStakesPercent[i] * total_private_state_asimov;
		printf("STAKE[%03d] percent = %.05f      asimov = %f\n", i + 1, pfaStakesPercent[i] * 100.0, fAsimov); 
		fTotalPercent +=  pfaStakesPercent[i];
		fTotalAsimov += fAsimov;
	}


	printf("Total Percent = %f   TotalAsimov = %f\n", fTotalPercent * 100.0, fTotalAsimov);
	
	


}