function AverageIncrement($value1, $value2)
{
$percent = 80;
$value = ($value1*(100-$percent) + $value2*$percent) / 100;
debuglog("AverageIncrement: $value1, $value2");
return $value;
}
Or report it to Tpruvot and see if he can look at it. I'm pretty sure this is what is causing the issues.
Did you ever set up a VM to test this? If there is a race condition that is affecting this function it may only happen under heavy server load or heavy internet traffic. So you will want to run a stress test on the VM while this is running to see if the problem occurs only under stress. Also pull the network connection. See if a dropped connection affects it.
But better than all that testing is this: If either value has 0, then return the other value. So if the old value is 0 then there is nothing to average, so take the new value. If the new value is 0 then there was a server error or a race condition and no new data has actually been received, so keep the old value.
function AverageIncrement($value1, $value2)
{
if ($value1 == 0) return $value2;
if ($value2 == 0) return $value1;
$percent = 80;
$value = ($value1*(100-$percent) + $value2*$percent) / 100;
return $value;
}
That all being said, this is an extremely poor averaging function. Since it seems that things sit in the exchange state for 4-6 hours, a WMA over the previous 6 hours of samples with samples collected every 5 minutes would be a much better average. And that collected data could allow a much better prediction of future value by projecting upper and lower trend for the next 5 minute sample. The mBTC column for predicted value would then show x.xxxxx(+/- y.yyyyy). This predicted value should only be shown when the state is immature or exchange, since we don't know the final exchange rate until it's cleared. But when cleared the exchange transaction should be analyzed and the actual rate of exchange reported and paid. Add to keep it open and transparent, so clicking on any of the lines in the payout list should display a page showing the data and the calculation. That way everyone knows that it is working the way it should.