Merge pull request #1353 from TheSerapher/issue-1352

[UPDATE] Added active workers to admin dashboard
This commit is contained in:
Sebastian Grewe 2014-01-11 03:39:15 -08:00
commit 23c6ffe7a3
4 changed files with 25 additions and 4 deletions

View File

@ -920,6 +920,24 @@ class Statistics extends Base {
}
return round($pps_reward / (pow(2, $this->config['target_bits']) * $dDifficulty), 12);
}
/**
* Get all currently active users in the past 2 minutes
* @param interval int Time in seconds to fetch shares from
* @return data mixed int count if any users are active, false otherwise
**/
public function getCountAllActiveUsers($interval=120) {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
$stmt = $this->mysqli->prepare("
SELECT COUNT(DISTINCT(SUBSTRING_INDEX( `username` , '.', 1 ))) AS total
FROM " . $this->share->getTableName() . "
WHERE our_result = 'Y'
AND time > DATE_SUB(now(), INTERVAL ? SECOND)");
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $interval) && $stmt->execute() && $result = $stmt->get_result())
return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->total);
return $this->sqlError();
}
}
$statistics = new Statistics();

View File

@ -198,19 +198,19 @@ class Worker extends Base {
}
/**
* Get all currently active workers in the past 10 minutes
* Get all currently active workers in the past 2 minutes
* @param none
* @return data mixed int count if any workers are active, false otherwise
**/
public function getCountAllActiveWorkers() {
public function getCountAllActiveWorkers($interval=120) {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
$stmt = $this->mysqli->prepare("
SELECT COUNT(DISTINCT(username)) AS total
FROM " . $this->share->getTableName() . "
WHERE our_result = 'Y'
AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)");
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
AND time > DATE_SUB(now(), INTERVAL ? SECOND)");
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $interval) && $stmt->execute() && $result = $stmt->get_result())
return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->total);
return $this->sqlError();
}

View File

@ -39,6 +39,7 @@ $smarty->assign('CRON_DISABLED', $cron_disabled);
// Fetch user information
$aUserInfo = array(
'total' => $user->getCount(),
'active' => $statistics->getCountAllActiveUsers(),
'locked' => $user->getCountFiltered('is_locked', 1),
'admins' => $user->getCountFiltered('is_admin', 1),
'nofees' => $user->getCountFiltered('no_fees', 1)

View File

@ -41,6 +41,7 @@
<thead>
<tr>
<th align="center">Total</th>
<th align="center">Active</th>
<th align="center">Locked</th>
<th align="center">Admins</th>
<th align="center">No Fees</th>
@ -49,6 +50,7 @@
<tbody>
<tr>
<td align="center">{$USER_INFO.total}</td>
<td align="center">{$USER_INFO.active}</td>
<td align="center">{$USER_INFO.locked}</td>
<td align="center">{$USER_INFO.admins}</td>
<td align="center">{$USER_INFO.nofees}</td>