[UPDATE] Added active workers to admin dashboard

* Using lower time range for shares: 120 seconds
* Updated worker class with new time range for active workers
* Added statistics, active users call with 120 seconds time range
* Updated admin panel dashboard template

Fixes #1352 once merged.
This commit is contained in:
Sebastian Grewe 2014-01-11 12:37:39 +01:00
parent 88c962266f
commit 6baad2dd06
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); 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(); $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 * @param none
* @return data mixed int count if any workers are active, false otherwise * @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); $this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data; if ($data = $this->memcache->get(__FUNCTION__)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT COUNT(DISTINCT(username)) AS total SELECT COUNT(DISTINCT(username)) AS total
FROM " . $this->share->getTableName() . " FROM " . $this->share->getTableName() . "
WHERE our_result = 'Y' WHERE our_result = 'Y'
AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)"); AND time > DATE_SUB(now(), INTERVAL ? SECOND)");
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) 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->memcache->setCache(__FUNCTION__, $result->fetch_object()->total);
return $this->sqlError(); return $this->sqlError();
} }

View File

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

View File

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