From 6baad2dd06610bf979e4342f332bd14eb4ba331d Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 11 Jan 2014 12:37:39 +0100 Subject: [PATCH] [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. --- public/include/classes/statistics.class.php | 18 ++++++++++++++++++ public/include/classes/worker.class.php | 8 ++++---- public/include/pages/admin/dashboard.inc.php | 1 + .../templates/mpos/admin/dashboard/default.tpl | 2 ++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index f6bb7eaa..9cb01c00 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -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(); diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index 2d0e606f..a028d5a4 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -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(); } diff --git a/public/include/pages/admin/dashboard.inc.php b/public/include/pages/admin/dashboard.inc.php index e878cd8a..12dcb984 100644 --- a/public/include/pages/admin/dashboard.inc.php +++ b/public/include/pages/admin/dashboard.inc.php @@ -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) diff --git a/public/templates/mpos/admin/dashboard/default.tpl b/public/templates/mpos/admin/dashboard/default.tpl index dc216a57..36e129e2 100644 --- a/public/templates/mpos/admin/dashboard/default.tpl +++ b/public/templates/mpos/admin/dashboard/default.tpl @@ -41,6 +41,7 @@ Total + Active Locked Admins No Fees @@ -49,6 +50,7 @@ {$USER_INFO.total} + {$USER_INFO.active} {$USER_INFO.locked} {$USER_INFO.admins} {$USER_INFO.nofees}