|
|
|
|
@ -353,7 +353,7 @@ class Statistics extends Base {
|
|
|
|
|
* @param username str username
|
|
|
|
|
* @return data array invalid and valid share counts
|
|
|
|
|
**/
|
|
|
|
|
public function getUserShares($username, $account_id) {
|
|
|
|
|
public function getUserShares($username, $account_id=NULL) {
|
|
|
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
|
|
|
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
|
|
|
|
if ($data = $this->memcache->get(STATISTICS_ALL_USER_SHARES)) {
|
|
|
|
|
@ -365,12 +365,15 @@ class Statistics extends Base {
|
|
|
|
|
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
|
|
|
|
$stmt = $this->mysqli->prepare("
|
|
|
|
|
SELECT
|
|
|
|
|
ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid,
|
|
|
|
|
ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid
|
|
|
|
|
ROUND(IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid,
|
|
|
|
|
ROUND(IFNULL(SUM(IF(our_result='N', IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid
|
|
|
|
|
FROM " . $this->share->getTableName() . "
|
|
|
|
|
WHERE username LIKE '?.%'
|
|
|
|
|
WHERE username LIKE ?
|
|
|
|
|
AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)");
|
|
|
|
|
if ($stmt && $stmt->bind_param("i", $username) && $stmt->execute() && $result = $stmt->get_result())
|
|
|
|
|
|
|
|
|
|
$username = $username . ".%";
|
|
|
|
|
|
|
|
|
|
if ($stmt && $stmt->bind_param("s", $username) && $stmt->execute() && $result = $stmt->get_result())
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_assoc());
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
}
|
|
|
|
|
@ -495,7 +498,7 @@ class Statistics extends Base {
|
|
|
|
|
* @param $username string username
|
|
|
|
|
* @return data integer Current Hashrate in khash/s
|
|
|
|
|
**/
|
|
|
|
|
public function getUserHashrate($username, $account_id, $interval=180) {
|
|
|
|
|
public function getUserHashrate($username, $account_id=NULL, $interval=180) {
|
|
|
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
|
|
|
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
|
|
|
|
if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
|
|
|
|
|
@ -513,7 +516,7 @@ class Statistics extends Base {
|
|
|
|
|
id, our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty
|
|
|
|
|
FROM
|
|
|
|
|
shares
|
|
|
|
|
WHERE username LIKE '?.%'
|
|
|
|
|
WHERE username LIKE ?
|
|
|
|
|
AND time > DATE_SUB(now(), INTERVAL ? SECOND)
|
|
|
|
|
AND our_result = 'Y'
|
|
|
|
|
UNION
|
|
|
|
|
@ -521,26 +524,31 @@ class Statistics extends Base {
|
|
|
|
|
share_id, our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty
|
|
|
|
|
FROM
|
|
|
|
|
shares_archive
|
|
|
|
|
WHERE username LIKE '?.%'
|
|
|
|
|
WHERE username LIKE ?
|
|
|
|
|
AND time > DATE_SUB(now(), INTERVAL ? SECOND)
|
|
|
|
|
AND our_result = 'Y'
|
|
|
|
|
) AS temp");
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() )
|
|
|
|
|
AND our_result = 'Y') AS temp");
|
|
|
|
|
|
|
|
|
|
$username = $username . ".%";
|
|
|
|
|
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $interval, $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() )
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->hashrate);
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getUserUnpaidPPSShares($username, $last_paid_pps_id) {
|
|
|
|
|
public function getUserUnpaidPPSShares($username, $account_id=NULL, $last_paid_pps_id) {
|
|
|
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
|
|
|
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
|
|
|
|
$stmt = $this->mysqli->prepare("
|
|
|
|
|
SELECT
|
|
|
|
|
ROUND(IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS total
|
|
|
|
|
ROUND(IFNULL(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS total
|
|
|
|
|
FROM " . $this->share->getTableName() . "
|
|
|
|
|
WHERE username LIKE '?.%'
|
|
|
|
|
WHERE username LIKE ?
|
|
|
|
|
AND id > ?
|
|
|
|
|
AND our_result = 'Y'");
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() )
|
|
|
|
|
|
|
|
|
|
$username = $username . ".%";
|
|
|
|
|
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("si", $username, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() )
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->total);
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
}
|
|
|
|
|
@ -551,7 +559,7 @@ class Statistics extends Base {
|
|
|
|
|
* @param interval int Data interval in seconds
|
|
|
|
|
* @return double Share difficulty or 0
|
|
|
|
|
**/
|
|
|
|
|
public function getUserShareDifficulty($username, $account_id, $interval=180) {
|
|
|
|
|
public function getUserShareDifficulty($username, $account_id=NULL, $interval=180) {
|
|
|
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
|
|
|
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
|
|
|
|
if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
|
|
|
|
|
@ -566,11 +574,11 @@ class Statistics extends Base {
|
|
|
|
|
IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff,
|
|
|
|
|
COUNT(s.id) AS total
|
|
|
|
|
FROM " . $this->share->getTableName() . " AS s
|
|
|
|
|
WHERE username LIKE '?.%'
|
|
|
|
|
WHERE username LIKE ?.%
|
|
|
|
|
AND time > DATE_SUB(now(), INTERVAL ? SECOND)
|
|
|
|
|
AND our_result = 'Y'
|
|
|
|
|
");
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() )
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("si", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() )
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->avgsharediff);
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
}
|
|
|
|
|
@ -580,7 +588,7 @@ class Statistics extends Base {
|
|
|
|
|
* @param username string username
|
|
|
|
|
* @return data integer Current Sharerate in shares/s
|
|
|
|
|
**/
|
|
|
|
|
public function getUserSharerate($username, $account_id, $interval=180) {
|
|
|
|
|
public function getUserSharerate($username, $account_id=NULL, $interval=180) {
|
|
|
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
|
|
|
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
|
|
|
|
if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
|
|
|
|
|
@ -598,7 +606,7 @@ class Statistics extends Base {
|
|
|
|
|
id
|
|
|
|
|
FROM
|
|
|
|
|
shares
|
|
|
|
|
WHERE username LIKE '?.%'
|
|
|
|
|
WHERE username LIKE ?
|
|
|
|
|
AND time > DATE_SUB(now(), INTERVAL ? SECOND)
|
|
|
|
|
AND our_result = 'Y'
|
|
|
|
|
UNION
|
|
|
|
|
@ -606,11 +614,14 @@ class Statistics extends Base {
|
|
|
|
|
share_id
|
|
|
|
|
FROM
|
|
|
|
|
shares_archive
|
|
|
|
|
WHERE username LIKE '?.%'
|
|
|
|
|
WHERE username LIKE ?
|
|
|
|
|
AND time > DATE_SUB(now(), INTERVAL ? SECOND)
|
|
|
|
|
AND our_result = 'Y'
|
|
|
|
|
) AS temp");
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() )
|
|
|
|
|
|
|
|
|
|
$username = $username . ".%";
|
|
|
|
|
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param("isisi", $interval, $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() )
|
|
|
|
|
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->sharerate);
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
}
|
|
|
|
|
@ -620,16 +631,16 @@ class Statistics extends Base {
|
|
|
|
|
* @param username string username
|
|
|
|
|
* @return data int Current hashrate in khash/s
|
|
|
|
|
**/
|
|
|
|
|
public function getWorkerHashrate($worker_id, $interval=180) {
|
|
|
|
|
public function getWorkerHashrate($workername, $worker_id=NULL, $interval=180) {
|
|
|
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
|
|
|
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
|
|
|
|
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("i", $worker_id, $interval) && $stmt->execute() && $result = $stmt->get_result() )
|
|
|
|
|
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, $result->fetch_object()->hashrate);
|
|
|
|
|
return $this->sqlError();
|
|
|
|
|
}
|
|
|
|
|
@ -714,7 +725,7 @@ class Statistics extends Base {
|
|
|
|
|
* @param username string Username
|
|
|
|
|
* @return data array NOT FINISHED YET
|
|
|
|
|
**/
|
|
|
|
|
public function getHourlyHashrateByAccount($username, $account_id) {
|
|
|
|
|
public function getHourlyHashrateByAccount($username, $account_id=NULL) {
|
|
|
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
|
|
|
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
|
|
|
|
$stmt = $this->mysqli->prepare("
|
|
|
|
|
@ -725,7 +736,7 @@ class Statistics extends Base {
|
|
|
|
|
WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60))
|
|
|
|
|
AND time >= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) - INTERVAL 24 HOUR
|
|
|
|
|
AND our_result = 'Y'
|
|
|
|
|
AND username LIKE '?.%'
|
|
|
|
|
AND username LIKE ?
|
|
|
|
|
GROUP BY HOUR(time)
|
|
|
|
|
UNION
|
|
|
|
|
SELECT
|
|
|
|
|
@ -736,9 +747,12 @@ class Statistics extends Base {
|
|
|
|
|
WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60))
|
|
|
|
|
AND time >= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) - INTERVAL 24 HOUR
|
|
|
|
|
AND our_result = 'Y'
|
|
|
|
|
AND username LIKE '?.%'
|
|
|
|
|
AND username LIKE ?
|
|
|
|
|
GROUP BY HOUR(time)");
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $username, $username) && $stmt->execute() && $result = $stmt->get_result()) {
|
|
|
|
|
|
|
|
|
|
$username = $username . ".%";
|
|
|
|
|
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param('ss', $username, $username) && $stmt->execute() && $result = $stmt->get_result()) {
|
|
|
|
|
$iStartHour = date('G');
|
|
|
|
|
// Initilize array
|
|
|
|
|
for ($i = 0; $i < 24; $i++) $aData[($iStartHour + $i) % 24] = 0;
|
|
|
|
|
|