Update statistics.class.php
This commit is contained in:
parent
7378e593bd
commit
a42adb11b2
@ -105,13 +105,9 @@ class Statistics {
|
||||
SELECT
|
||||
(
|
||||
(
|
||||
SELECT IFNULL(ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000), 0) AS hashrate
|
||||
FROM " . $this->share->getTableName() . "
|
||||
WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
|
||||
SELECT ROUND(SUM(difficulty) * 65536/600/1000) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
|
||||
) + (
|
||||
SELECT IFNULL(ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000), 0) AS hashrate
|
||||
FROM " . $this->share->getArchiveTableName() . "
|
||||
WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
|
||||
SELECT ROUND(SUM(difficulty) * 65536/600/1000) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
|
||||
)
|
||||
) AS hashrate
|
||||
FROM DUAL");
|
||||
@ -130,9 +126,12 @@ class Statistics {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT ROUND(COUNT(id) / 600, 2) AS sharerate
|
||||
FROM " . $this->share->getTableName() . "
|
||||
WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)");
|
||||
SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM
|
||||
(
|
||||
SELECT SUM(difficulty) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
|
||||
UNION ALL
|
||||
SELECT SUM(difficulty) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
|
||||
) AS sum");
|
||||
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate);
|
||||
// Catchall
|
||||
$this->debug->append("Failed to fetch share rate: " . $this->mysqli->error);
|
||||
@ -149,8 +148,8 @@ class Statistics {
|
||||
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
IFNULL(SUM(IF(our_result='Y', 1, 0)), 0) AS valid,
|
||||
IFNULL(SUM(IF(our_result='N', 1, 0)), 0) AS invalid
|
||||
SUM(IF(our_result='Y', difficulty, 0)) AS valid,
|
||||
SUM(IF(our_result='N', difficulty, 0)) AS invalid
|
||||
FROM " . $this->share->getTableName() . "
|
||||
WHERE UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(time) FROM " . $this->block->getTableName() . "),0)");
|
||||
if ( $this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() )
|
||||
@ -171,8 +170,8 @@ class Statistics {
|
||||
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
IFNULL(SUM(IF(our_result='Y', 1, 0)), 0) AS valid,
|
||||
IFNULL(SUM(IF(our_result='N', 1, 0)), 0) AS invalid,
|
||||
SUM(IF(our_result='Y', difficulty, 0)) AS valid,
|
||||
SUM(IF(our_result='N', difficulty, 0)) AS invalid,
|
||||
u.id AS id,
|
||||
u.username AS username
|
||||
FROM " . $this->share->getTableName() . " AS s,
|
||||
@ -197,8 +196,8 @@ class Statistics {
|
||||
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
IFNULL(SUM(IF(our_result='Y', 1, 0)), 0) AS valid,
|
||||
IFNULL(SUM(IF(our_result='N', 1, 0)), 0) AS invalid
|
||||
SUM(IF(our_result='Y', difficulty, 0)) AS valid,
|
||||
SUM(IF(our_result='N', difficulty, 0)) AS invalid
|
||||
FROM " . $this->share->getTableName() . " AS s,
|
||||
" . $this->user->getTableName() . " AS u
|
||||
WHERE
|
||||
@ -228,7 +227,7 @@ class Statistics {
|
||||
a.username AS username,
|
||||
a.donate_percent AS donate_percent,
|
||||
a.email AS email,
|
||||
COUNT(s.id) AS shares
|
||||
SUM(s.difficulty) AS shares
|
||||
FROM " . $this->user->getTableName() . " AS a
|
||||
LEFT JOIN " . $this->share->getTableName() . " AS s
|
||||
ON a.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
||||
@ -252,14 +251,14 @@ class Statistics {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
(
|
||||
SELECT IFNULL(ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 600 / 1000), 0) AS hashrate
|
||||
SELECT ROUND(SUM(s.difficulty) * 65536/600/1000) AS hashrate
|
||||
FROM " . $this->share->getTableName() . " AS s,
|
||||
" . $this->user->getTableName() . " AS u
|
||||
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
||||
AND s.time > DATE_SUB(now(), INTERVAL 10 MINUTE)
|
||||
AND u.id = ?
|
||||
) + (
|
||||
SELECT IFNULL(ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 600 / 1000), 0) AS hashrate
|
||||
SELECT ROUND(SUM(s.difficulty) * 65536/600/1000) AS hashrate
|
||||
FROM " . $this->share->getArchiveTableName() . " AS s,
|
||||
" . $this->user->getTableName() . " AS u
|
||||
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
||||
@ -283,7 +282,7 @@ class Statistics {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT COUNT(s.id)/600 AS sharerate
|
||||
SELECT SUM(s.difficulty)/600 AS sharerate
|
||||
FROM " . $this->share->getTableName() . " AS s,
|
||||
" . $this->user->getTableName() . " AS u
|
||||
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
||||
@ -305,7 +304,7 @@ class Statistics {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT IFNULL(ROUND(COUNT(s.id) * POW(2,21)/600/1000), 0) AS hashrate
|
||||
SELECT ROUND(SUM(s.difficulty) * 65536/600/1000) AS hashrate
|
||||
FROM " . $this->share->getTableName() . " AS s,
|
||||
" . $this->user->getTableName() . " AS u
|
||||
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
||||
@ -333,7 +332,7 @@ class Statistics {
|
||||
SELECT
|
||||
a.donate_percent AS donate_percent,
|
||||
a.is_anonymous AS is_anonymous,
|
||||
COUNT(s.id) AS shares,
|
||||
SUM(difficulty) AS shares,
|
||||
SUBSTRING_INDEX( s.username, '.', 1 ) AS account
|
||||
FROM " . $this->share->getTableName() . " AS s
|
||||
LEFT JOIN " . $this->user->getTableName() . " AS a
|
||||
@ -354,12 +353,13 @@ class Statistics {
|
||||
a.donate_percent AS donate_percent,
|
||||
a.is_anonymous AS is_anonymous,
|
||||
IFNULL(ROUND(COUNT(t1.id) * POW(2," . $this->config['difficulty'] . ")/600/1000, 2), 0) AS hashrate,
|
||||
ROUND(SUM(t1.difficulty) * 65536/600/1000) AS hashrate,
|
||||
SUBSTRING_INDEX( t1.username, '.', 1 ) AS account
|
||||
FROM
|
||||
(
|
||||
SELECT id, username FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y'
|
||||
SELECT id, username, difficulty FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y'
|
||||
UNION
|
||||
SELECT id, username FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y'
|
||||
SELECT id, username, difficulty FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y'
|
||||
) AS t1
|
||||
LEFT JOIN " . $this->user->getTableName() . " AS a
|
||||
ON SUBSTRING_INDEX( t1.username, '.', 1 ) = a.username
|
||||
@ -367,7 +367,7 @@ class Statistics {
|
||||
ORDER BY hashrate DESC LIMIT ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $this->memcache->setCache(__FUNCTION__ . $type . $limit, $result->fetch_all(MYSQLI_ASSOC));
|
||||
$this->debug->append("Fetching shares failed: ");
|
||||
$this->debug->append("Fetching shares failed: " . $this->mysqli->error);
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
@ -383,9 +383,9 @@ class Statistics {
|
||||
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 3600 / 1000) AS hashrate,
|
||||
ROUND(SUM(s.difficulty) * 65536/3600/1000) AS hashrate,
|
||||
HOUR(s.time) AS hour
|
||||
FROM " . $this->share->getTableName() . " AS s, accounts AS a
|
||||
FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a
|
||||
WHERE time < NOW() - INTERVAL 1 HOUR
|
||||
AND time > NOW() - INTERVAL 25 HOUR
|
||||
AND a.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
||||
@ -423,9 +423,9 @@ class Statistics {
|
||||
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
IFNULL(ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 3600 / 1000), 0) AS hashrate,
|
||||
ROUND(SUM(s.difficulty) * 65536/3600/1000) AS hashrate,
|
||||
HOUR(s.time) AS hour
|
||||
FROM " . $this->share->getTableName() . " AS s
|
||||
FROM " . $this->share->getArchiveTableName() . " AS s
|
||||
WHERE time < NOW() - INTERVAL 1 HOUR
|
||||
AND time > NOW() - INTERVAL 25 HOUR
|
||||
GROUP BY HOUR(time)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user