Merge branch 'next' of github.com:MPOS/php-mpos into next

This commit is contained in:
Sebastian Grewe 2014-01-20 09:58:33 +01:00
commit 954459b897
4 changed files with 76 additions and 11 deletions

View File

@ -27,10 +27,16 @@ require_once('shared.inc.php');
// Per user share statistics based on all shares submitted
$start = microtime(true);
if ( ! $aAllUserShares = $statistics->getAllUserShares() )
if ( ! $statistics->getAllUserShares() )
$log->logError('getAllUserShares update failed');
$log->logInfo("getAllUserShares " . number_format(microtime(true) - $start, 2) . " seconds");
// Get all user hashrate statistics for caching
$start = microtime(true);
if ( ! $statistics->getAllUserMiningStats() )
$log->logError('getAllUserMiningStats update failed');
$log->logInfo("getAllUserMiningStats " . number_format(microtime(true) - $start, 2) . " seconds");
$start = microtime(true);
if (!$statistics->getTopContributors('hashes'))
$log->logError("getTopContributors hashes update failed");
@ -41,13 +47,5 @@ if (!$statistics->getCurrentHashrate())
$log->logError("getCurrentHashrate update failed");
$log->logInfo("getCurrentHashrate " . number_format(microtime(true) - $start, 2) . " seconds");
/*
// Admin specific statistics, we cache the global query due to slowness
$start = microtime(true);
if (!$statistics->getAllUserStats('%'))
$log->logError("getAllUserStats update failed");
$log->logInfo("getAllUserStats " . number_format(microtime(true) - $start, 2) . " seconds");
*/
require_once('cron_end.inc.php');
?>

View File

@ -448,6 +448,51 @@ class Statistics extends Base {
return $this->sqlError();
}
/**
* Fetch all user hashrates based on shares and archived shares
* @return data integer Current Hashrate in khash/s
**/
public function getAllUserMiningStats($interval=600) {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare("
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,
ROUND(COUNT(t1.id) / ?, 2) AS sharerate,
IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff
FROM (
SELECT
id,
IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty,
username
FROM shares
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y'
UNION
SELECT
share_id,
IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty,
username
FROM shares_archive
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y'
) AS t1
LEFT JOIN " . $this->user->getTableName() . " AS a
ON SUBSTRING_INDEX( t1.username, '.', 1 ) = a.username
WHERE a.id IS NOT NULL
GROUP BY account
ORDER BY hashrate DESC
");
if ($this->checkStmt($stmt) && $stmt->bind_param("iiii", $interval, $interval, $interval, $interval) && $stmt->execute() && $result = $stmt->get_result() ) {
$aData = array();
while ($row = $result->fetch_assoc()) {
$aData['data'][$row['id']] = $row;
}
return $this->memcache->setCache(STATISTICS_ALL_USER_HASHRATES, $aData);
} else {
return $this->sqlError();
}
}
/**
* Fetch total user hashrate based on shares and archived shares
* @param account_id integer User ID
@ -455,6 +500,13 @@ class Statistics extends Base {
**/
public function getUserHashrate($account_id, $interval=600) {
$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_HASHRATES)) {
if (array_key_exists($account_id, $data['data']))
return $data['data'][$account_id]['hashrate'];
// We have no cached value, we return defaults
return 0;
}
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
$stmt = $this->mysqli->prepare("
SELECT
@ -510,6 +562,13 @@ class Statistics extends Base {
**/
public function getUserShareDifficulty($account_id, $interval=600) {
$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_HASHRATES)) {
if (array_key_exists($account_id, $data['data']))
return $data['data'][$account_id]['avgsharediff'];
// We have no cached value, we return defaults
return 0;
}
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
$stmt = $this->mysqli->prepare("
SELECT
@ -532,6 +591,13 @@ class Statistics extends Base {
**/
public function getUserSharerate($account_id, $interval=600) {
$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_HASHRATES)) {
if (array_key_exists($account_id, $data['data']))
return $data['data'][$account_id]['sharerate'];
// We have no cached value, we return defaults
return 0;
}
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
$stmt = $this->mysqli->prepare("
SELECT

View File

@ -4,5 +4,6 @@
if (!defined('SECURITY')) die('Hacking attempt');
define('STATISTICS_ALL_USER_SHARES', 'STATISTICS_ALL_USER_SHARES');
define('STATISTICS_ALL_USER_HASHRATES', 'STATISTICS_ALL_USER_HASHRATES');
define('STATISTICS_ROUND_SHARES', 'STATISTICS_ROUND_SHARES');
?>

View File

@ -684,7 +684,7 @@ margin: -5px 0 5px 0;
text-transform: uppercase;
}
fieldset input[type=text], fieldset input[type=password] {
fieldset input[type=email], fieldset input[type=text], fieldset input[type=password] {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
@ -703,7 +703,7 @@ width: 92%;
margin: 0 10px;
}
fieldset input[type=text]:focus, fieldset input[type=password]:focus, fieldset input[type=checkbox] {
fieldset input[type=text]:focus, fieldset input[type=email]:focus, fieldset input[type=password]:focus, fieldset input[type=checkbox] {
outline: none;
border: 1px solid #77BACE;
-webkit-box-shadow: inset 0 2px 2px #ccc, 0 0 10px #ADDCE6;