From fd6d0c094832b8cdd23c66acbd3dce92bf385657 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 13 May 2013 23:28:54 +0200 Subject: [PATCH] adding classes to statistics class, added getCurrentHashrate --- public/include/classes/statistics.class.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index eee203d4..2737c7f8 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -10,9 +10,11 @@ class Statistics { // This defines each statistic public $valid, $invalid, $block, $user; - public function __construct($debug, $mysqli, $salt) { + public function __construct($debug, $mysqli, $config, $share) { $this->debug = $debug; $this->mysqli = $mysqli; + $this->share = $share; + $this->config = $config; $this->debug->append("Instantiated Share class", 2); } @@ -35,6 +37,13 @@ class Statistics { return false; } + public function getCurrentHashrate() { + $stmt = $this->mysqli->prepare("SELECT ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)"); + if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) { + return $result->fetch_object()->hashrate; + } + } + private function checkStmt($bState) { if ($bState ===! true) { $this->debug->append("Failed to prepare statement: " . $this->mysqli->error); @@ -45,4 +54,4 @@ class Statistics { } } -$statistics = new Statistics($debug, $mysqli, SALT); +$statistics = new Statistics($debug, $mysqli, $config, $share);