calculate propotional payout for all shares of this block

This commit is contained in:
Sebastian Grewe 2013-05-11 00:22:23 +02:00
parent 7fe381f44c
commit 42d2fa2618
2 changed files with 34 additions and 12 deletions

View File

@ -27,22 +27,27 @@ $aAllBlocks = $block->getAll('ASC');
foreach ($aAllBlocks as $iIndex => $aBlock) {
if (!$aBlock['accounted']) {
$iPrevBlockTime = $aAllBlocks[$iIndex - 1]['time'];
if ($iPrevBlockTime) {
echo "Found a previous block with timestamp: $iPrevBlockTime\n";
if (!$iPrevBlockTime) {
$iPrevBlockTime = 0;
}
$aAccountShares = $share->getSharesForAccountsByTimeframe($aBlock['time'], $iPrevBlockTime);
$iRoundShares = $share->getRoundSharesByTimeframe($aBlock['time'], $iPrevBlockTime);
$strFinder = $share->getFinderByTimeframe($aBlock['time'], $iPrevBlockTime);
echo "Block Information:\n";
echo "Height\tTime\t\tFinder\n\n";
echo $aBlock['height'] . "\t" . $aBlock['time'] . "\t" . $strFinder . "\n";
echo "\nShares details:\n\n";
echo "ID\tUsername\tValid\tInvalid\n\n";
foreach ($aAccountShares as $aData) {
echo $aData['id'] . "\t" . $aData['username'] . "\t" . $aData['valid'] . "\t" . $aData['invalid'] . "\n";
echo "Height\tTime\t\tShares\tFinder\n";
echo $aBlock['height'] . "\t" . $aBlock['time'] . "\t" . $iRoundShares . "\t" . $strFinder . "\n\n";
echo "ID\tUsername\tValid\tInvalid\tPercentage\tPayout\n";
foreach ($aAccountShares as $key => $aData) {
$aData['percentage'] = ( 100 / $iRoundShares ) * $aData['valid'];
$aData['payout'] = ( $aData['percentage'] / 100 ) * $config['reward'];
echo $aData['id'] . "\t" .
$aData['username'] . "\t" .
$aData['valid'] . "\t" .
$aData['invalid'] . "\t" .
$aData['percentage'] . "\t" .
$aData['payout'] . "\t" .
"\n";
}
echo "\n";
// TODO: Find all shares for this blocks round and account the users
// propotional to their shares for this block
echo "------------------------------------------------------------------------\n\n";
}
// TODO: We have accounted all shares for a block so mark it accounted
// and delete all the shares we just accounted for.

View File

@ -68,6 +68,23 @@ class Share {
return false;
}
public function getRoundSharesByTimeframe($current='', $old='') {
$stmt = $this->mysqli->prepare("SELECT
count(id) as total
FROM $this->table
WHERE our_result = 'Y'
AND UNIX_TIMESTAMP(time) BETWEEN ? AND ?
");
echo $this->mysqli->error;
if ($this->checkStmt($stmt)) {
$stmt->bind_param('ii', $old, $current);
$stmt->execute();
$result = $stmt->get_result();
$stmt->close();
return $result->fetch_object()->total;
}
return false;
}
public function getFinderByTimeframe($current='', $old='') {
$stmt = $this->mysqli->prepare("SELECT
SUBSTRING_INDEX( `username` , '.', 1 ) AS account