This commit is contained in:
obigal 2013-07-06 13:38:34 -04:00 committed by Sebastian Grewe
parent efc35bd2fc
commit 360bd22dc6
3 changed files with 14 additions and 23 deletions

View File

@ -13,19 +13,12 @@ class Share {
// This defines each share // This defines each share
public $rem_host, $username, $our_result, $upstream_result, $reason, $solution, $time, $difficulty; public $rem_host, $username, $our_result, $upstream_result, $reason, $solution, $time, $difficulty;
<<<<<<< HEAD
public function __construct($debug, $mysqli, $user, $block, $config) { public function __construct($debug, $mysqli, $user, $block, $config) {
$this->debug = $debug; $this->debug = $debug;
$this->mysqli = $mysqli; $this->mysqli = $mysqli;
$this->user = $user; $this->user = $user;
$this->config = $config; $this->config = $config;
$this->block = $block; $this->block = $block;
=======
public function __construct($debug, $mysqli, $config, $salt) {
$this->debug = $debug;
$this->mysqli = $mysqli;
$this->config = $config;
>>>>>>> Update share.class.php
$this->debug->append("Instantiated Share class", 2); $this->debug->append("Instantiated Share class", 2);
} }
@ -77,7 +70,7 @@ class Share {
**/ **/
public function getRoundShares($previous_upstream=0, $current_upstream) { public function getRoundShares($previous_upstream=0, $current_upstream) {
$stmt = $this->mysqli->prepare("SELECT $stmt = $this->mysqli->prepare("SELECT
IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 8), 0) as total IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) as total
FROM $this->table FROM $this->table
WHERE our_result = 'Y' WHERE our_result = 'Y'
AND id > ? AND id <= ? AND id > ? AND id <= ?
@ -284,7 +277,6 @@ class Share {
SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id
FROM $this->table FROM $this->table
WHERE upstream_result = 'Y' WHERE upstream_result = 'Y'
AND UNIX_TIMESTAMP(time) >= ?
AND id > ? AND id > ?
AND UNIX_TIMESTAMP(time) >= ? AND UNIX_TIMESTAMP(time) >= ?
AND UNIX_TIMESTAMP(time) <= ( ? + 60 ) AND UNIX_TIMESTAMP(time) <= ( ? + 60 )

View File

@ -105,11 +105,11 @@ class Statistics {
SELECT SELECT
( (
( (
SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000), 0) AS hashrate
FROM " . $this->share->getTableName() . " FROM " . $this->share->getTableName() . "
WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
) + ( ) + (
SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000), 0) AS hashrate
FROM " . $this->share->getArchiveTableName() . " FROM " . $this->share->getArchiveTableName() . "
WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
) )
@ -132,9 +132,9 @@ class Statistics {
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM
( (
SELECT SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
UNION ALL UNION ALL
SELECT SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
) AS sum"); ) AS sum");
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate); if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate);
// Catchall // Catchall
@ -174,8 +174,8 @@ class Statistics {
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT SELECT
IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS valid,
IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid, IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS invalid,
u.id AS id, u.id AS id,
u.username AS username u.username AS username
FROM " . $this->share->getTableName() . " AS s, FROM " . $this->share->getTableName() . " AS s,
@ -200,8 +200,8 @@ class Statistics {
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT SELECT
IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS valid,
IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS invalid
FROM " . $this->share->getTableName() . " AS s, FROM " . $this->share->getTableName() . " AS s,
" . $this->user->getTableName() . " AS u " . $this->user->getTableName() . " AS u
WHERE WHERE
@ -286,7 +286,7 @@ class Statistics {
$this->debug->append("STA " . __METHOD__, 4); $this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0)/600 AS sharerate SELECT IFNULL(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)), 0)/600 AS sharerate
FROM " . $this->share->getTableName() . " AS s, FROM " . $this->share->getTableName() . " AS s,
" . $this->user->getTableName() . " AS u " . $this->user->getTableName() . " AS u
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
@ -308,7 +308,7 @@ class Statistics {
$this->debug->append("STA " . __METHOD__, 4); $this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate SELECT IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/600/1000), 0) AS hashrate
FROM " . $this->share->getTableName() . " AS s, FROM " . $this->share->getTableName() . " AS s,
" . $this->user->getTableName() . " AS u " . $this->user->getTableName() . " AS u
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
@ -336,7 +336,7 @@ class Statistics {
SELECT SELECT
a.donate_percent AS donate_percent, a.donate_percent AS donate_percent,
a.is_anonymous AS is_anonymous, a.is_anonymous AS is_anonymous,
IFNULL(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) AS shares, IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS shares,
SUBSTRING_INDEX( s.username, '.', 1 ) AS account SUBSTRING_INDEX( s.username, '.', 1 ) AS account
FROM " . $this->share->getTableName() . " AS s FROM " . $this->share->getTableName() . " AS s
LEFT JOIN " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->user->getTableName() . " AS a
@ -356,8 +356,7 @@ class Statistics {
SELECT SELECT
a.donate_percent AS donate_percent, a.donate_percent AS donate_percent,
a.is_anonymous AS is_anonymous, a.is_anonymous AS is_anonymous,
IFNULL(ROUND(COUNT(t1.id) * POW(2," . $this->config['difficulty'] . ")/600/1000, 2), 0) AS hashrate, IFNULL(ROUND(SUM(IF(t1.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, t1.difficulty)) * 65536/600/1000), 0) AS hashrate,
ROUND(SUM(IF(t1.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, t1.difficulty)) * 65536/600/1000) AS hashrate,
SUBSTRING_INDEX( t1.username, '.', 1 ) AS account SUBSTRING_INDEX( t1.username, '.', 1 ) AS account
FROM FROM
( (

View File

@ -48,7 +48,7 @@
</tr> </tr>
<tr> <tr>
<td class="leftheader">Est. Shares this Round</td> <td class="leftheader">Est. Shares this Round</td>
<td>{(65536 * $DIFFICULTY)|number_format:"0"} <font size="1">(done: {(100 / (pow(2, 32 - $GLOBAL.config.targetdiff) * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %)</td> <td>{(65536 * $DIFFICULTY)|number_format:"0"} <font size="1">(done: {(100 / (65536 * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %)</td>
</tr> </tr>
<tr> <tr>
<td class="leftheader">Time Since Last Block</td> <td class="leftheader">Time Since Last Block</td>