|
|
|
|
@ -46,46 +46,48 @@ class Statistics extends Base {
|
|
|
|
|
IFNULL(SUM(IF(confirmations = -1, 1, 0)), 0) AS TotalOrphan,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > 0, difficulty, 0)), 0) AS TotalDifficulty,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(confirmations > -1, shares, 0))), 0) AS TotalShares,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(confirmations > -1, POW(2, ( 32 - " . $this->config['target_bits'] . " )) * difficulty / POW(2, (" . $this->config['difficulty'] . " -16)), 0))), 0) AS TotalEstimatedShares,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > -1, amount, 0)), 0) AS TotalAmount,
|
|
|
|
|
IFNULL(SUM(IF(FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 3600 SECOND), 1, 0)), 0) AS 1HourTotal,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 3600 SECOND), 1, 0)), 0) AS 1HourValid,
|
|
|
|
|
IFNULL(SUM(IF(confirmations = -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 3600 SECOND), 1, 0)), 0) AS 1HourOrphan,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 3600 SECOND), difficulty, 0)), 0) AS 1HourDifficulty,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 3600 SECOND), shares, 0))), 0) AS 1HourShares,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 3600 SECOND), POW(2, ( 32 - " . $this->config['target_bits'] . " )) * difficulty / POW(2, (" . $this->config['difficulty'] . " -16)), 0))), 0) AS 1HourEstimatedShares,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 3600 SECOND), amount, 0)), 0) AS 1HourAmount,
|
|
|
|
|
IFNULL(SUM(IF(FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 86400 SECOND), 1, 0)), 0) AS 24HourTotal,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 86400 SECOND), 1, 0)), 0) AS 24HourValid,
|
|
|
|
|
IFNULL(SUM(IF(confirmations = -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 86400 SECOND), 1, 0)), 0) AS 24HourOrphan,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 86400 SECOND), difficulty, 0)), 0) AS 24HourDifficulty,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 86400 SECOND), shares, 0))), 0) AS 24HourShares,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 86400 SECOND), POW(2, ( 32 - " . $this->config['target_bits'] . " )) * difficulty / POW(2, (" . $this->config['difficulty'] . " -16)), 0))), 0) AS 24HourEstimatedShares,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 86400 SECOND), amount, 0)), 0) AS 24HourAmount,
|
|
|
|
|
IFNULL(SUM(IF(FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 604800 SECOND), 1, 0)), 0) AS 7DaysTotal,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 604800 SECOND), 1, 0)), 0) AS 7DaysValid,
|
|
|
|
|
IFNULL(SUM(IF(confirmations = -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 604800 SECOND), 1, 0)), 0) AS 7DaysOrphan,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 604800 SECOND), difficulty, 0)), 0) AS 7DaysDifficulty,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 604800 SECOND), shares, 0))), 0) AS 7DaysShares,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 604800 SECOND), POW(2, ( 32 - " . $this->config['target_bits'] . " )) * difficulty / POW(2, (" . $this->config['difficulty'] . " -16)), 0))), 0) AS 7DaysEstimatedShares,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 604800 SECOND), amount, 0)), 0) AS 7DaysAmount,
|
|
|
|
|
IFNULL(SUM(IF(FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 2419200 SECOND), 1, 0)), 0) AS 4WeeksTotal,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 2419200 SECOND), 1, 0)), 0) AS 4WeeksValid,
|
|
|
|
|
IFNULL(SUM(IF(confirmations = -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 2419200 SECOND), 1, 0)), 0) AS 4WeeksOrphan,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 2419200 SECOND), difficulty, 0)), 0) AS 4WeeksDifficulty,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 2419200 SECOND), shares, 0))), 0) AS 4WeeksShares,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 2419200 SECOND), POW(2, ( 32 - " . $this->config['target_bits'] . " )) * difficulty / POW(2, (" . $this->config['difficulty'] . " -16)), 0))), 0) AS 4WeeksEstimatedShares,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 2419200 SECOND), amount, 0)), 0) AS 4WeeksAmount,
|
|
|
|
|
IFNULL(SUM(IF(FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 29030400 SECOND), 1, 0)), 0) AS 12MonthTotal,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 29030400 SECOND), 1, 0)), 0) AS 12MonthValid,
|
|
|
|
|
IFNULL(SUM(IF(confirmations = -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 29030400 SECOND), 1, 0)), 0) AS 12MonthOrphan,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 29030400 SECOND), difficulty, 0)), 0) AS 12MonthDifficulty,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 29030400 SECOND), shares, 0))), 0) AS 12MonthShares,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 29030400 SECOND), POW(2, ( 32 - " . $this->config['target_bits'] . " )) * difficulty / POW(2, (" . $this->config['difficulty'] . " -16)), 0))), 0) AS 12MonthEstimatedShares,
|
|
|
|
|
IFNULL(SUM(IF(confirmations > -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 29030400 SECOND), amount, 0)), 0) AS 12MonthAmount
|
|
|
|
|
FROM " . $this->block->getTableName());
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__, $result->fetch_assoc());
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) {
|
|
|
|
|
$aData = $result->fetch_assoc();
|
|
|
|
|
$aData['TotalEstimatedShares'] = $this->coin->calcEstaimtedShares($aData['TotalDifficulty']);
|
|
|
|
|
$aData['1HourEstimatedShares'] = $this->coin->calcEstaimtedShares($aData['1HourDifficulty']);
|
|
|
|
|
$aData['24HourEstimatedShares'] = $this->coin->calcEstaimtedShares($aData['24HourDifficulty']);
|
|
|
|
|
$aData['7DaysEstimatedShares'] = $this->coin->calcEstaimtedShares($aData['7DaysDifficulty']);
|
|
|
|
|
$aData['4WeeksEstimatedShares'] = $this->coin->calcEstaimtedShares($aData['4WeeksDifficulty']);
|
|
|
|
|
$aData['12MonthEstimatedShares'] = $this->coin->calcEstaimtedShares($aData['12MonthDifficulty']);
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__, $aData);
|
|
|
|
|
}
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -102,7 +104,7 @@ class Statistics extends Base {
|
|
|
|
|
b.*,
|
|
|
|
|
a.username AS finder,
|
|
|
|
|
a.is_anonymous AS is_anonymous,
|
|
|
|
|
ROUND((difficulty * POW(2, 32 - " . $this->config['target_bits'] . ")) / POW(2, (" . $this->config['difficulty'] . " -16)), 0) AS estshares
|
|
|
|
|
ROUND((difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . ")) / POW(2, (" . $this->config['difficulty'] . " -16)), 0) AS estshares
|
|
|
|
|
FROM " . $this->block->getTableName() . " AS b
|
|
|
|
|
LEFT JOIN " . $this->user->getTableName() . " AS a
|
|
|
|
|
ON b.account_id = a.id
|
|
|
|
|
@ -125,7 +127,7 @@ class Statistics extends Base {
|
|
|
|
|
b.*,
|
|
|
|
|
a.username AS finder,
|
|
|
|
|
a.is_anonymous AS is_anonymous,
|
|
|
|
|
ROUND((difficulty * POW(2, 32 - " . $this->config['target_bits'] . ")) / POW(2, (" . $this->config['difficulty'] . " -16)), 0) AS estshares
|
|
|
|
|
ROUND((difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . ")) / POW(2, (" . $this->config['difficulty'] . " -16)), 0) AS estshares
|
|
|
|
|
FROM " . $this->block->getTableName() . " AS b
|
|
|
|
|
LEFT JOIN " . $this->user->getTableName() . " AS a
|
|
|
|
|
ON b.account_id = a.id
|
|
|
|
|
@ -221,19 +223,22 @@ class Statistics extends Base {
|
|
|
|
|
SELECT
|
|
|
|
|
(
|
|
|
|
|
(
|
|
|
|
|
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 IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty))), 0) AS shares
|
|
|
|
|
FROM " . $this->share->getTableName() . "
|
|
|
|
|
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND)
|
|
|
|
|
AND our_result = 'Y'
|
|
|
|
|
) + (
|
|
|
|
|
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 IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty))), 0) AS shares
|
|
|
|
|
FROM " . $this->share->getArchiveTableName() . "
|
|
|
|
|
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND)
|
|
|
|
|
AND our_result = 'Y'
|
|
|
|
|
)
|
|
|
|
|
) AS hashrate
|
|
|
|
|
) AS shares
|
|
|
|
|
FROM DUAL");
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $interval, $interval, $interval, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setStaticCache(__FUNCTION__, $result->fetch_object()->hashrate);
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $interval, $interval) && $stmt->execute() && $result = $stmt->get_result() ) {
|
|
|
|
|
$hashrate = $this->coin->calcHashrate($result->fetch_object()->shares, $interval);
|
|
|
|
|
return $this->memcache->setStaticCache(__FUNCTION__, $hashrate);
|
|
|
|
|
}
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -446,7 +451,7 @@ class Statistics extends Base {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch all user hashrates based on shares and archived shares
|
|
|
|
|
* @return data integer Current Hashrate in khash/s
|
|
|
|
|
* @return data array Set of all user stats
|
|
|
|
|
**/
|
|
|
|
|
public function getAllUserMiningStats($interval=180) {
|
|
|
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
|
|
|
@ -454,7 +459,7 @@ class Statistics extends Base {
|
|
|
|
|
SELECT
|
|
|
|
|
a.id AS id,
|
|
|
|
|
a.username AS account,
|
|
|
|
|
IFNULL(ROUND(SUM(t1.difficulty) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000, 2), 0) AS hashrate,
|
|
|
|
|
IFNULL(SUM(t1.difficulty), 0) AS shares,
|
|
|
|
|
ROUND(COUNT(t1.id) / ?, 2) AS sharerate,
|
|
|
|
|
IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff
|
|
|
|
|
FROM (
|
|
|
|
|
@ -476,12 +481,13 @@ class Statistics extends Base {
|
|
|
|
|
ON SUBSTRING_INDEX( t1.username, '.', 1 ) = a.username
|
|
|
|
|
WHERE a.id IS NOT NULL
|
|
|
|
|
GROUP BY account
|
|
|
|
|
ORDER BY hashrate DESC
|
|
|
|
|
ORDER BY shares DESC
|
|
|
|
|
");
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("iiii", $interval, $interval, $interval, $interval) && $stmt->execute() && $result = $stmt->get_result() ) {
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("iii", $interval, $interval, $interval) && $stmt->execute() && $result = $stmt->get_result() ) {
|
|
|
|
|
$aData = array();
|
|
|
|
|
while ($row = $result->fetch_assoc()) {
|
|
|
|
|
$aData['data'][$row['id']] = $row;
|
|
|
|
|
$aData['data'][$row['id']]['hashrate'] = $this->coin->calcHashrate($row['shares'], $interval);
|
|
|
|
|
}
|
|
|
|
|
return $this->memcache->setStaticCache(STATISTICS_ALL_USER_HASHRATES, $aData, 600);
|
|
|
|
|
} else {
|
|
|
|
|
@ -527,7 +533,7 @@ class Statistics extends Base {
|
|
|
|
|
$stmt = $this->mysqli->prepare("
|
|
|
|
|
SELECT
|
|
|
|
|
IFNULL(COUNT(*) / ?, 0) AS sharerate,
|
|
|
|
|
IFNULL(ROUND(SUM(difficulty) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000, 2), 0) AS hashrate,
|
|
|
|
|
IFNULL(SUM(difficulty), 0) AS shares,
|
|
|
|
|
IFNULL(AVG(difficulty), 0) AS avgsharediff
|
|
|
|
|
FROM (
|
|
|
|
|
SELECT
|
|
|
|
|
@ -547,27 +553,11 @@ class Statistics extends Base {
|
|
|
|
|
AND our_result = 'Y'
|
|
|
|
|
) AS temp");
|
|
|
|
|
$username = $username . ".%";
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("iisisi", $interval, $interval, $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() )
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_assoc());
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get hashrate for a specific worker
|
|
|
|
|
* @param username string username
|
|
|
|
|
* @return data int Current hashrate in khash/s
|
|
|
|
|
**/
|
|
|
|
|
public function getWorkerHashrate($workername, $worker_id=NULL, $interval=180) {
|
|
|
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
|
|
|
if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data;
|
|
|
|
|
$stmt = $this->mysqli->prepare("
|
|
|
|
|
SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 600 / 1000), 0) AS hashrate
|
|
|
|
|
FROM " . $this->share->getTableName() . " AS
|
|
|
|
|
WHERE username = '?'
|
|
|
|
|
AND our_result = 'Y'
|
|
|
|
|
AND time > DATE_SUB(now(), INTERVAL ? SECOND)");
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("si", $workername, $interval) && $stmt->execute() && $result = $stmt->get_result())
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__ . $worker_id, (float)$result->fetch_object()->hashrate);
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("isisi", $interval, $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) {
|
|
|
|
|
$aData = $result->fetch_assoc();
|
|
|
|
|
$aData['hashrate'] = $this->coin->calcHashrate($aData['shares'], $interval);
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData);
|
|
|
|
|
}
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -633,7 +623,7 @@ class Statistics extends Base {
|
|
|
|
|
a.username AS account,
|
|
|
|
|
a.donate_percent AS donate_percent,
|
|
|
|
|
a.is_anonymous AS is_anonymous,
|
|
|
|
|
IFNULL(ROUND(SUM(t1.difficulty) * POW(2, " . $this->config['target_bits'] . ") / 600 / 1000, 2), 0) AS hashrate
|
|
|
|
|
IFNULL(SUM(t1.difficulty), 0) AS shares
|
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
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'
|
|
|
|
|
@ -643,9 +633,17 @@ class Statistics extends Base {
|
|
|
|
|
LEFT JOIN " . $this->user->getTableName() . " AS a
|
|
|
|
|
ON SUBSTRING_INDEX( t1.username, '.', 1 ) = a.username
|
|
|
|
|
GROUP BY account
|
|
|
|
|
ORDER BY hashrate DESC LIMIT ?");
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result())
|
|
|
|
|
return $this->memcache->setStaticCache(__FUNCTION__ . $type . $limit, $result->fetch_all(MYSQLI_ASSOC));
|
|
|
|
|
ORDER BY shares DESC LIMIT ?");
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result()) {
|
|
|
|
|
$aData = array();
|
|
|
|
|
$count = 0;
|
|
|
|
|
while ($row = $result->fetch_assoc()) {
|
|
|
|
|
$aData[$count] = $row;
|
|
|
|
|
$aData[$count]['hashrate'] = $this->coin->calcHashrate($row['shares'], 600);
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
return $this->memcache->setStaticCache(__FUNCTION__ . $type . $limit, $aData);
|
|
|
|
|
}
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
@ -663,7 +661,7 @@ class Statistics extends Base {
|
|
|
|
|
$stmt = $this->mysqli->prepare("
|
|
|
|
|
SELECT
|
|
|
|
|
id,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate,
|
|
|
|
|
IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS shares,
|
|
|
|
|
HOUR(time) AS hour
|
|
|
|
|
FROM " . $this->share->getTableName() . "
|
|
|
|
|
WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60))
|
|
|
|
|
@ -674,7 +672,7 @@ class Statistics extends Base {
|
|
|
|
|
UNION
|
|
|
|
|
SELECT
|
|
|
|
|
share_id,
|
|
|
|
|
IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate,
|
|
|
|
|
IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS shares,
|
|
|
|
|
HOUR(time) AS hour
|
|
|
|
|
FROM " . $this->share->getArchiveTableName() . "
|
|
|
|
|
WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60))
|
|
|
|
|
@ -688,7 +686,7 @@ class Statistics extends Base {
|
|
|
|
|
// Initilize array
|
|
|
|
|
for ($i = 0; $i < 24; $i++) $aData[($iStartHour + $i) % 24] = 0;
|
|
|
|
|
// Fill data
|
|
|
|
|
while ($row = $result->fetch_assoc()) $aData[$row['hour']] += $row['hashrate'];
|
|
|
|
|
while ($row = $result->fetch_assoc()) $aData[$row['hour']] += (int) $this->coin->calcHashrate($row['shares'], 3600);
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData);
|
|
|
|
|
}
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
@ -705,7 +703,7 @@ class Statistics extends Base {
|
|
|
|
|
$stmt = $this->mysqli->prepare("
|
|
|
|
|
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(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) AS shares,
|
|
|
|
|
HOUR(s.time) AS hour
|
|
|
|
|
FROM " . $this->share->getTableName() . " AS s
|
|
|
|
|
WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60))
|
|
|
|
|
@ -715,7 +713,7 @@ class Statistics extends Base {
|
|
|
|
|
UNION
|
|
|
|
|
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(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) AS shares,
|
|
|
|
|
HOUR(s.time) AS hour
|
|
|
|
|
FROM " . $this->share->getArchiveTableName() . " AS s
|
|
|
|
|
WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60))
|
|
|
|
|
@ -727,7 +725,7 @@ class Statistics extends Base {
|
|
|
|
|
// Initilize array
|
|
|
|
|
for ($i = 0; $i < 24; $i++) $aData[($iStartHour + $i) % 24] = 0;
|
|
|
|
|
// Fill data
|
|
|
|
|
while ($row = $result->fetch_assoc()) $aData[$row['hour']] += (int) $row['hashrate'];
|
|
|
|
|
while ($row = $result->fetch_assoc()) $aData[$row['hour']] += (int) $this->coin->calcHashrate($row['shares'], 3600);
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__, $aData);
|
|
|
|
|
}
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
@ -788,17 +786,19 @@ class Statistics extends Base {
|
|
|
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
|
|
|
if ($data = $this->memcache->get(__FUNCTION__ . $hour)) return $data;
|
|
|
|
|
$stmt = $this->mysqli->prepare("
|
|
|
|
|
SELECT
|
|
|
|
|
IFNULL(COUNT(id), 0) as count,
|
|
|
|
|
SELECT
|
|
|
|
|
IFNULL(COUNT(id), 0) as count,
|
|
|
|
|
IFNULL(AVG(difficulty), 0) as average,
|
|
|
|
|
IFNULL(ROUND(SUM((POW(2, ( 32 - " . $this->config['target_bits'] . " )) * difficulty) / POW(2, (" . $this->config['difficulty'] . " -16))), 0), 0) AS expected,
|
|
|
|
|
IFNULL(ROUND(SUM(shares)), 0) as shares,
|
|
|
|
|
IFNULL(SUM(amount), 0) as rewards
|
|
|
|
|
IFNULL(SUM(amount), 0) as rewards
|
|
|
|
|
FROM " . $this->block->getTableName() . "
|
|
|
|
|
WHERE FROM_UNIXTIME(time) > DATE_SUB(now(), INTERVAL ? HOUR)
|
|
|
|
|
AND confirmations >= 1");
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $hour) && $stmt->execute() && $result = $stmt->get_result())
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__ . $hour, $result->fetch_assoc());
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $hour) && $stmt->execute() && $result = $stmt->get_result()) {
|
|
|
|
|
$aData = $result->fetch_assoc();
|
|
|
|
|
$aData['expected'] = $this->coin->calcEstaimtedShares($aData['average']);
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__ . $hour, $aData);
|
|
|
|
|
}
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -808,7 +808,7 @@ class Statistics extends Base {
|
|
|
|
|
* @return shares integer Share count
|
|
|
|
|
**/
|
|
|
|
|
public function getEstimatedShares($dDiff) {
|
|
|
|
|
return round((POW(2, (32 - $this->config['target_bits'])) * $dDiff) / pow(2, ($this->config['difficulty'] - 16)));
|
|
|
|
|
return $this->coin->calcEstaimtedShares($dDiff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -829,7 +829,7 @@ class Statistics extends Base {
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__, $this->config['cointarget']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__, pow(2, 32) * $dDifficulty / $dNetworkHashrate);
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__, $this->coin->calcNetworkExpectedTimePerBlock($dDifficulty, $dNetworkHashrate));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -841,11 +841,13 @@ class Statistics extends Base {
|
|
|
|
|
|
|
|
|
|
if ($this->bitcoin->can_connect() === true) {
|
|
|
|
|
$dDifficulty = $this->bitcoin->getdifficulty();
|
|
|
|
|
$dNetworkHashrate = $this->bitcoin->getnetworkhashps();
|
|
|
|
|
} else {
|
|
|
|
|
$dDifficulty = 1;
|
|
|
|
|
$dNetworkHashrate = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__, round($dDifficulty * $this->config['cointarget'] / $this->getNetworkExpectedTimePerBlock(), 8));
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__, $this->coin->calcExpectedNextDifficulty($dDifficulty, $dNetworkHashrate));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -890,7 +892,7 @@ class Statistics extends Base {
|
|
|
|
|
$pps_reward = $this->config['pps']['reward']['default'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return round($pps_reward / (pow(2, $this->config['target_bits']) * $dDifficulty), 12);
|
|
|
|
|
return round($pps_reward / (pow(2, $this->coin->getTargetBits()) * $dDifficulty), 12);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -922,5 +924,5 @@ $statistics->setMemcache($memcache);
|
|
|
|
|
$statistics->setConfig($config);
|
|
|
|
|
$statistics->setBitcoin($bitcoin);
|
|
|
|
|
$statistics->setErrorCodes($aErrorCodes);
|
|
|
|
|
|
|
|
|
|
$statistics->setCoin($coin);
|
|
|
|
|
?>
|
|
|
|
|
|