Merge pull request #863 from TheSerapher/issue-642

[FIX] Hashrate increase on round ends
This commit is contained in:
Sebastian Grewe 2013-11-27 04:51:44 -08:00
commit 3094681018

View File

@ -434,7 +434,7 @@ class Statistics extends Base {
} }
/** /**
* Same as getUserShares for Hashrate * Fetch total user hashrate based on shares and archived shares
* @param account_id integer User ID * @param account_id integer User ID
* @return data integer Current Hashrate in khash/s * @return data integer Current Hashrate in khash/s
**/ **/
@ -443,25 +443,29 @@ class Statistics extends Base {
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(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000), 0), 0) AS hashrate
SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000), 0) AS hashrate FROM (
FROM " . $this->share->getTableName() . " AS s, SELECT
" . $this->user->getTableName() . " AS u s.id, s.our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty) AS difficulty
FROM
shares AS s,
accounts AS u
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
AND our_result = 'Y'
AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) AND s.time > DATE_SUB(now(), INTERVAL ? SECOND)
AND s.our_result = 'Y'
AND u.id = ? AND u.id = ?
) + ( UNION
SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000), 0) AS hashrate SELECT
FROM " . $this->share->getArchiveTableName() . " AS s, s.share_id, s.our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty) AS difficulty
" . $this->user->getTableName() . " AS u FROM
shares_archive AS s,
accounts AS u
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
AND our_result = 'Y'
AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) AND s.time > DATE_SUB(now(), INTERVAL ? SECOND)
AND s.our_result = 'Y'
AND u.id = ? AND u.id = ?
) AS hashrate ) AS temp");
FROM DUAL"); if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $interval, $interval, $account_id, $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() )
if ($this->checkStmt($stmt) && $stmt->bind_param("iiiiii", $interval, $interval, $account_id, $interval, $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() )
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->hashrate); return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->hashrate);
return $this->sqlError(); return $this->sqlError();
} }
@ -516,27 +520,29 @@ class Statistics extends Base {
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(COUNT(*) / ?, 0) AS sharerate
( FROM (
SELECT COUNT(s.id) / ? AS sharerate SELECT
FROM " . $this->share->getTableName() . " AS s, s.id
" . $this->user->getTableName() . " AS u FROM
shares AS s,
accounts AS u
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
AND our_result = 'Y'
AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) AND s.time > DATE_SUB(now(), INTERVAL ? SECOND)
AND s.our_result = 'Y'
AND u.id = ? AND u.id = ?
) + ( UNION
SELECT COUNT(s.id) / ? AS sharerate SELECT
FROM " . $this->share->getArchiveTableName() . " AS s, s.share_id
" . $this->user->getTableName() . " AS u FROM
shares_archive AS s,
accounts AS u
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
AND our_result = 'Y'
AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) AND s.time > DATE_SUB(now(), INTERVAL ? SECOND)
AND s.our_result = 'Y'
AND u.id = ? AND u.id = ?
) ) AS temp");
) AS sharerate if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $interval, $interval, $account_id, $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() )
FROM DUAL");
if ($this->checkStmt($stmt) && $stmt->bind_param("iiiiii", $interval, $interval, $account_id, $interval, $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() )
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->sharerate); return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->sharerate);
return $this->sqlError(); return $this->sqlError();
} }
@ -621,9 +627,9 @@ class Statistics extends Base {
IFNULL(ROUND(SUM(t1.difficulty) * POW(2, " . $this->config['target_bits'] . ") / 600 / 1000, 2), 0) AS hashrate IFNULL(ROUND(SUM(t1.difficulty) * POW(2, " . $this->config['target_bits'] . ") / 600 / 1000, 2), 0) AS hashrate
FROM FROM
( (
SELECT IFNULL(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0) AS difficulty, username FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' SELECT id, IFNULL(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0) AS difficulty, username FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y'
UNION ALL UNION
SELECT IFNULL(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0) AS difficulty, username FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' SELECT share_id, IFNULL(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0) AS difficulty, username FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y'
) AS t1 ) AS t1
LEFT JOIN " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->user->getTableName() . " AS a
ON SUBSTRING_INDEX( t1.username, '.', 1 ) = a.username ON SUBSTRING_INDEX( t1.username, '.', 1 ) = a.username
@ -646,6 +652,7 @@ class Statistics extends Base {
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 SELECT
id,
IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate,
HOUR(s.time) AS hour HOUR(s.time) AS hour
FROM " . $this->share->getTableName() . " AS s, accounts AS a FROM " . $this->share->getTableName() . " AS s, accounts AS a
@ -655,8 +662,9 @@ class Statistics extends Base {
AND a.username = SUBSTRING_INDEX( s.username, '.', 1 ) AND a.username = SUBSTRING_INDEX( s.username, '.', 1 )
AND a.id = ? AND a.id = ?
GROUP BY HOUR(time) GROUP BY HOUR(time)
UNION ALL UNION
SELECT SELECT
share_id,
IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate,
HOUR(s.time) AS hour HOUR(s.time) AS hour
FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a
@ -687,6 +695,7 @@ class Statistics extends Base {
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
id,
IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate,
HOUR(s.time) AS hour HOUR(s.time) AS hour
FROM " . $this->share->getTableName() . " AS s FROM " . $this->share->getTableName() . " AS s
@ -694,8 +703,9 @@ class Statistics extends Base {
AND time > NOW() - INTERVAL 25 HOUR AND time > NOW() - INTERVAL 25 HOUR
AND our_result = 'Y' AND our_result = 'Y'
GROUP BY HOUR(time) GROUP BY HOUR(time)
UNION ALL UNION
SELECT SELECT
share_id,
IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate,
HOUR(s.time) AS hour HOUR(s.time) AS hour
FROM " . $this->share->getArchiveTableName() . " AS s FROM " . $this->share->getArchiveTableName() . " AS s