further work on sharecounter cron, almost all features available now
This commit is contained in:
parent
42d2fa2618
commit
3971ea797c
@ -23,32 +23,36 @@ require_once('shared.inc.php');
|
||||
|
||||
// Fetch our last block found from the DB as a starting point
|
||||
$aAllBlocks = $block->getAll('ASC');
|
||||
|
||||
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
if (!$aBlock['accounted']) {
|
||||
$iPrevBlockTime = $aAllBlocks[$iIndex - 1]['time'];
|
||||
$iPrevBlockTime = @$aAllBlocks[$iIndex - 1]['time'];
|
||||
if (!$iPrevBlockTime) {
|
||||
$iPrevBlockTime = 0;
|
||||
}
|
||||
$aAccountShares = $share->getSharesForAccountsByTimeframe($aBlock['time'], $iPrevBlockTime);
|
||||
$iRoundShares = $share->getRoundSharesByTimeframe($aBlock['time'], $iPrevBlockTime);
|
||||
$strFinder = $share->getFinderByTimeframe($aBlock['time'], $iPrevBlockTime);
|
||||
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";
|
||||
echo "ID\tHeight\tTime\t\tShares\tFinder\n";
|
||||
echo $aBlock['id'] . "\t" . $aBlock['height'] . "\t" . $aBlock['time'] . "\t" . $iRoundShares . "\t" . $strFinder . "\n\n";
|
||||
echo "ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tStatus\n";
|
||||
foreach ($aAccountShares as $key => $aData) {
|
||||
$aData['percentage'] = ( 100 / $iRoundShares ) * $aData['valid'];
|
||||
$aData['payout'] = ( $aData['percentage'] / 100 ) * $config['reward'];
|
||||
$aData['percentage'] = number_format(round(( 100 / $iRoundShares ) * $aData['valid'], 10),10);
|
||||
$aData['payout'] = number_format(round(( $aData['percentage'] / 100 ) * $config['reward'], 10), 10);
|
||||
echo $aData['id'] . "\t" .
|
||||
$aData['username'] . "\t" .
|
||||
$aData['valid'] . "\t" .
|
||||
$aData['invalid'] . "\t" .
|
||||
$aData['percentage'] . "\t" .
|
||||
$aData['payout'] . "\t" .
|
||||
"\n";
|
||||
$aData['payout'] . "\t";
|
||||
if (!$statistics->updateShareStatistics($aData, $aBlock['id'])) {
|
||||
echo "Stats Failed" . "\n";
|
||||
}
|
||||
}
|
||||
echo "------------------------------------------------------------------------\n\n";
|
||||
|
||||
// Now that we have all shares counted internally let's update the tables
|
||||
// Set shares as counted and mark block as accounted for
|
||||
// $share->setCountedByTimeframe($aBlock['time'], $iPrevBlockTime);
|
||||
// $block->setAccounted($aBlock['blockhash']);
|
||||
}
|
||||
// TODO: We have accounted all shares for a block so mark it accounted
|
||||
// and delete all the shares we just accounted for.
|
||||
}
|
||||
|
||||
@ -8,4 +8,5 @@ require_once(INCLUDE_DIR . '/smarty.inc.php');
|
||||
require_once(CLASS_DIR . '/user.class.php');
|
||||
require_once(CLASS_DIR . '/block.class.php');
|
||||
require_once(CLASS_DIR . '/share.class.php');
|
||||
require_once(CLASS_DIR . '/statistics.class.php');
|
||||
require_once(CLASS_DIR . '/settings.class.php');
|
||||
|
||||
@ -61,6 +61,22 @@ class Block {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setAccounted($blockhash='') {
|
||||
if ($blockhash == '') return false;
|
||||
$stmt = $this->mysqli->prepare("UPDATE $this->table SET accounted = 1 WHERE blockhash = ?");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('s', $blockhash);
|
||||
if (!$stmt->execute()) {
|
||||
$this->debug->append("Failed to execute statement: " . $stmt->error);
|
||||
$stmt->close();
|
||||
return false;
|
||||
}
|
||||
$stmt->close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkStmt($bState) {
|
||||
if ($bState ===! true) {
|
||||
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
|
||||
|
||||
@ -40,6 +40,8 @@ class Share {
|
||||
UNIX_TIMESTAMP(time) BETWEEN ? AND ?
|
||||
AND
|
||||
our_result = 'Y'
|
||||
AND
|
||||
counted = 0
|
||||
GROUP BY account
|
||||
) validT
|
||||
LEFT JOIN
|
||||
@ -52,12 +54,13 @@ class Share {
|
||||
UNIX_TIMESTAMP(time) BETWEEN ? AND ?
|
||||
AND
|
||||
our_result = 'N'
|
||||
AND
|
||||
counted = 0
|
||||
GROUP BY account
|
||||
) invalidT
|
||||
ON validT.account = invalidT.account
|
||||
INNER JOIN accounts a ON a.username = validT.account
|
||||
GROUP BY a.username DESC");
|
||||
echo $this->mysqli->error;
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('iiii', $old, $current, $old, $current);
|
||||
$stmt->execute();
|
||||
@ -73,9 +76,9 @@ class Share {
|
||||
count(id) as total
|
||||
FROM $this->table
|
||||
WHERE our_result = 'Y'
|
||||
AND UNIX_TIMESTAMP(time) BETWEEN ? AND ?
|
||||
AND UNIX_TIMESTAMP(time) BETWEEN ? AND ?
|
||||
AND counted = 0
|
||||
");
|
||||
echo $this->mysqli->error;
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('ii', $old, $current);
|
||||
$stmt->execute();
|
||||
@ -85,20 +88,38 @@ class Share {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function getFinderByTimeframe($current='', $old='') {
|
||||
$stmt = $this->mysqli->prepare("SELECT
|
||||
SUBSTRING_INDEX( `username` , '.', 1 ) AS account
|
||||
FROM $this->table
|
||||
WHERE upstream_result = 'Y'
|
||||
AND UNIX_TIMESTAMP(time) BETWEEN ? AND ?
|
||||
ORDER BY id DESC");
|
||||
echo $this->mysqli->error;
|
||||
|
||||
public function setCountedByTimeframe($current='', $old='') {
|
||||
$stmt = $this->mysqli->prepare("UPDATE $this->table
|
||||
SET
|
||||
counted = 1
|
||||
WHERE
|
||||
UNIX_TIMESTAMP(time) BETWEEN ? AND ?
|
||||
AND counted = 0
|
||||
");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('ii', $old, $current);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$stmt->close();
|
||||
return $result->fetch_object()->account;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFinderByTimeframe($current='', $old='') {
|
||||
$stmt = $this->mysqli->prepare("SELECT
|
||||
SUBSTRING_INDEX( `username` , '.', 1 ) AS account
|
||||
FROM $this->table
|
||||
WHERE upstream_result = 'Y'
|
||||
AND UNIX_TIMESTAMP(time) BETWEEN ? AND ?
|
||||
ORDER BY id DESC");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('ii', $old, $current);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$stmt->close();
|
||||
return @$result->fetch_object()->account;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
48
public/include/classes/statistics.class.php
Normal file
48
public/include/classes/statistics.class.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
class Statistics {
|
||||
private $sError = '';
|
||||
private $table = 'statistics_shares';
|
||||
// This defines each statistic
|
||||
public $valid, $invalid, $block, $user;
|
||||
|
||||
public function __construct($debug, $mysqli, $salt) {
|
||||
$this->debug = $debug;
|
||||
$this->mysqli = $mysqli;
|
||||
$this->debug->append("Instantiated Share class", 2);
|
||||
}
|
||||
|
||||
// get and set methods
|
||||
private function setErrorMessage($msg) {
|
||||
$this->sError = $msg;
|
||||
}
|
||||
public function getError() {
|
||||
return $this->sError;
|
||||
}
|
||||
|
||||
public function updateShareStatistics($aStats, $iBlockId) {
|
||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, block_id) VALUES (?, ?, ?, ?, ?)");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('iiiddi', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId);
|
||||
if ($stmt->execute()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkStmt($bState) {
|
||||
if ($bState ===! true) {
|
||||
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
|
||||
$this->setErrorMessage('Failed to prepare statement');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$statistics = new Statistics($debug, $mysqli, SALT);
|
||||
@ -7,7 +7,7 @@ if (!defined('SECURITY'))
|
||||
class User {
|
||||
private $sError = '';
|
||||
private $userID = false;
|
||||
private $table = 'webUsers';
|
||||
private $table = 'accounts';
|
||||
private $user = array();
|
||||
private $tableAccountBalance = 'accountBalance';
|
||||
private $tablePoolWorker = 'pool_worker';
|
||||
|
||||
@ -14,16 +14,16 @@ if ($bitcoin->can_connect() === true){
|
||||
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to pushpool service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg');
|
||||
}
|
||||
|
||||
/** Disabled Stats
|
||||
// Top 15 hashrate list
|
||||
$stmt = $mysqli->prepare("SELECT username, id, hashrate FROM webUsers WHERE hashrate != '0' ORDER BY hashrate DESC LIMIT 15");
|
||||
$stmt = $mysqli->prepare("SELECT username, id, hashrate FROM accounts WHERE hashrate != '0' ORDER BY hashrate DESC LIMIT 15");
|
||||
$stmt->execute();
|
||||
$hashrates= $stmt->get_result();
|
||||
$aHashData = $hashrates->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
|
||||
// Top 15 Contributors
|
||||
# SELECT id, shares_this_round AS shares FROM webUsers WHERE shares_this_round > 0 ORDER BY shares DESC LIMIT
|
||||
$stmt = $mysqli->prepare("SELECT id, shares_this_round AS shares, username FROM webUsers WHERE shares_this_round > 0 ORDER BY shares DESC LIMIT 15");
|
||||
$stmt = $mysqli->prepare("SELECT id, shares_this_round AS shares, username FROM accounts WHERE shares_this_round > 0 ORDER BY shares DESC LIMIT 15");
|
||||
$stmt->execute();
|
||||
$contributors = $stmt->get_result();
|
||||
$aContributorData = $contributors->fetch_all(MYSQLI_ASSOC);
|
||||
@ -36,8 +36,9 @@ $blocks = $stmt->get_result();
|
||||
$aBlockData = $blocks->fetch_array();
|
||||
$stmt->close();
|
||||
|
||||
*/
|
||||
// Grab the last 10 blocks found
|
||||
$stmt = $mysqli->prepare("SELECT DISTINCT w.shareCount AS shares, w.username, n.blockNumber, n.confirms, n.timestamp FROM winning_shares w, networkBlocks n WHERE w.blockNumber = n.blockNumber ORDER BY w.blockNumber DESC LIMIT 10");
|
||||
$stmt = $mysqli->prepare("SELECT DISTINCT * FROM blocks ORDER BY height DESC LIMIT 10");
|
||||
$stmt->execute();
|
||||
$blocksfound = $stmt->get_result();
|
||||
$aBlocksFoundData = $blocksfound->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
@ -15,11 +15,11 @@
|
||||
{section block $BLOCKSFOUND}
|
||||
{assign var=user value="."|explode:$BLOCKSFOUND[block].username}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
<td>{$BLOCKSFOUND[block].blockNumber}</td>
|
||||
<td>{if $BLOCKSFOUND[block].confirms >= 120}<font color="green">Confirmed</font>{else}<font color="orange">{$BLOCKSFOUND[block].confirms - 120} left</font>{/if}</td>
|
||||
<td>{$user.0}</td>
|
||||
<td>{$BLOCKSFOUND[block].timestamp|date_format:"%d/%m/%Y %H:%M:%S"}</td>
|
||||
<td>{$BLOCKSFOUND[block].shares|number_format}</td>
|
||||
<td>{$BLOCKSFOUND[block].height}</td>
|
||||
<td>{if $BLOCKSFOUND[block].confirmations >= 120}<font color="green">Confirmed</font>{else}<font color="orange">{$BLOCKSFOUND[block].confirms - 120} left</font>{/if}</td>
|
||||
<td>{$user.0|default:"unknown"}</td>
|
||||
<td>{$BLOCKSFOUND[block].time|date_format:"%d/%m/%Y %H:%M:%S"}</td>
|
||||
<td>{$BLOCKSFOUND[block].difficulty|number_format}</td>
|
||||
</tr>
|
||||
{/section}
|
||||
</tbody>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user