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

View File

@ -68,6 +68,23 @@ class Share {
return false; 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='') { public function getFinderByTimeframe($current='', $old='') {
$stmt = $this->mysqli->prepare("SELECT $stmt = $this->mysqli->prepare("SELECT
SUBSTRING_INDEX( `username` , '.', 1 ) AS account SUBSTRING_INDEX( `username` , '.', 1 ) AS account