From ef84f5b1fdf1c78e4d44f990d00b3994c2de2860 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 13 May 2013 23:31:53 +0200 Subject: [PATCH] added hashrate and activity to getWorkers, properly return all active workers with getCountAllActiveWorkers --- public/include/classes/worker.class.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index 55701be2..71a13f28 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -8,10 +8,11 @@ class Worker { private $sError = ''; private $table = 'workers'; - public function __construct($debug, $mysqli, $user) { + public function __construct($debug, $mysqli, $user, $share) { $this->debug = $debug; $this->mysqli = $mysqli; $this->user = $user; + $this->share = $share; $this->debug->append("Instantiated Worker class", 2); } @@ -47,7 +48,12 @@ class Worker { return true; } public function getWorkers($account_id) { - $stmt = $this->mysqli->prepare("SELECT id, username, password, active, hashrate FROM $this->table WHERE account_id = ? ORDER BY username ASC"); + $stmt = $this->mysqli->prepare(" + SELECT $this->table.username, $this->table.password, + ( SELECT SIGN(count(id)) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS active, + ( SELECT ROUND(COUNT(id) * POW(2,21)/600/1000) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate + FROM $this->table + WHERE account_id = ?"); if ($this->checkStmt($stmt)) { if (!$stmt->bind_param('i', $account_id)) return false; if (!$stmt->execute()) return false; @@ -59,7 +65,7 @@ class Worker { } public function getCountAllActiveWorkers() { - $stmt = $this->mysqli->prepare("SELECT count(id) AS total FROM $this->table WHERE active = 1"); + $stmt = $this->mysqli->prepare("SELECT COUNT(DISTINCT username) AS total FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)"); if ($this->checkStmt($stmt)) { if (!$stmt->execute()) { return false; @@ -101,4 +107,4 @@ class Worker { } } -$worker = new Worker($debug, $mysqli, $user); +$worker = new Worker($debug, $mysqli, $user, $share);