From 4f3503bbb1d7f0f4cb3fe0e922e34a47ca776d55 Mon Sep 17 00:00:00 2001
From: obigal
Date: Tue, 29 Oct 2013 20:13:24 -0400
Subject: [PATCH 1/2] Admin poolworkers average difficulty fixes
---
public/include/classes/worker.class.php | 38 ++++++++++++++-----
.../mmcFE/admin/poolworkers/default.tpl | 2 +
.../mpos/admin/poolworkers/default.tpl | 6 ++-
3 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php
index 2960bfe7..f77a74b3 100644
--- a/public/include/classes/worker.class.php
+++ b/public/include/classes/worker.class.php
@@ -181,28 +181,46 @@ class Worker {
* @param limit int
* @return mixed array Workers and their settings or false
**/
- public function getAllWorkers($iLimit=0) {
+ public function getAllWorkers($iLimit=0, $interval=600) {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare("
- SELECT id, username, password, monitor, difficulty,
+ SELECT id, username, password, monitor,
+ IFNULL(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0) AS difficulty,
(
SELECT
- IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536 / 600 / 1000), 0), 0) AS hashrate
+ IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536 / ? / 1000), 0), 0) AS hashrate
FROM " . $this->share->getTableName() . "
WHERE
username = w.username
- AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)
- ) + (
- SELECT
- IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536 / 600 / 1000), 0), 0) AS hashrate
+ AND time > DATE_SUB(now(), INTERVAL ? SECOND)
+ ) + (
+ SELECT
+ IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536 / ? / 1000), 0), 0) AS hashrate
FROM " . $this->share->getArchiveTableName() . "
WHERE
username = w.username
- AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)
- ) AS hashrate
+ AND time > DATE_SUB(now(), INTERVAL ? SECOND)
+ ) AS hashrate,
+ ((
+ SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 2), 0)
+ FROM " . $this->share->getTableName() . "
+ WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL ? SECOND)
+ ) + (
+ SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 2), 0)
+ FROM " . $this->share->getArchiveTableName() . "
+ WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL ? SECOND)
+ )) / ((
+ SELECT COUNT(id)
+ FROM " . $this->share->getTableName() . "
+ WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL ? SECOND)
+ ) + (
+ SELECT COUNT(id)
+ FROM " . $this->share->getArchiveTableName() . "
+ WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL ? SECOND)
+ )) AS avg_difficulty
FROM $this->table AS w
ORDER BY hashrate DESC LIMIT ?");
- if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iLimit) && $stmt->execute() && $result = $stmt->get_result())
+ if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiiiiii', $interval, $interval, $interval, $interval, $interval, $interval, $interval, $interval, $iLimit) && $stmt->execute() && $result = $stmt->get_result())
return $result->fetch_all(MYSQLI_ASSOC);
// Catchall
$this->setErrorMessage('Failed to fetch workers');
diff --git a/public/templates/mmcFE/admin/poolworkers/default.tpl b/public/templates/mmcFE/admin/poolworkers/default.tpl
index f7afe308..5a9fe375 100644
--- a/public/templates/mmcFE/admin/poolworkers/default.tpl
+++ b/public/templates/mmcFE/admin/poolworkers/default.tpl
@@ -9,6 +9,7 @@
{if $GLOBAL.config.disable_notifications != 1}| Monitor | {/if}
Khash/s |
Difficulty |
+ Avg Difficulty |
{nocache}
@@ -25,6 +26,7 @@
{/if}
{$WORKERS[worker].hashrate|number_format|default:"0"} |
{if $WORKERS[worker].hashrate > 0}{$WORKERS[worker].difficulty|number_format:"2"|default:"0"}{else}0{/if} |
+ {if $WORKERS[worker].hashrate > 0}{$WORKERS[worker].avg_difficulty|number_format:"2"|default:"0"}{else}0{/if} |
{/section}
{/nocache}
diff --git a/public/templates/mpos/admin/poolworkers/default.tpl b/public/templates/mpos/admin/poolworkers/default.tpl
index 5d721421..b9b7cc8a 100644
--- a/public/templates/mpos/admin/poolworkers/default.tpl
+++ b/public/templates/mpos/admin/poolworkers/default.tpl
@@ -8,7 +8,8 @@
Active |
{if $GLOBAL.config.disable_notifications != 1}Monitor | {/if}
Khash/s |
- Difficulty |
+ Difficulty |
+ Avg Difficulty |
{nocache}
@@ -22,7 +23,8 @@
|
{/if}
{$WORKERS[worker].hashrate|number_format|default:"0"} |
- {if $WORKERS[worker].hashrate > 0}{$WORKERS[worker].difficulty|number_format:"2"|default:"0"}{else}0{/if} |
+ {if $WORKERS[worker].hashrate > 0}{$WORKERS[worker].difficulty|number_format:"2"|default:"0"}{else}0{/if} |
+ {if $WORKERS[worker].hashrate > 0}{$WORKERS[worker].avg_difficulty|number_format:"2"|default:"0"}{else}0{/if} |
{/section}
{/nocache}
From c0756d39df2c338442d144a094c041c0bf1c4a6d Mon Sep 17 00:00:00 2001
From: obigal
Date: Tue, 29 Oct 2013 22:25:45 -0400
Subject: [PATCH 2/2] 24 hour pool statistics
---
public/include/classes/statistics.class.php | 26 +++++++++++++++
.../include/pages/statistics/blocks.inc.php | 6 +++-
.../mmcFE/statistics/blocks/default.tpl | 29 +++++++++++++++++
.../mpos/statistics/blocks/default.tpl | 32 +++++++++++++++++--
4 files changed, 90 insertions(+), 3 deletions(-)
diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php
index eea80b71..57c5e20e 100644
--- a/public/include/classes/statistics.class.php
+++ b/public/include/classes/statistics.class.php
@@ -731,6 +731,32 @@ class Statistics {
}
return $aEstimates;
}
+
+ /**
+ * Get pool stats last 24 hours
+ * @param limit int Last number of hours
+ * @return array
+ **/
+ public function getPoolStatsHours($hour=24) {
+ $this->debug->append("STA " . __METHOD__, 4);
+ if ($data = $this->memcache->get(__FUNCTION__ . $hour)) return $data;
+ $stmt = $this->mysqli->prepare("
+ SELECT
+ IFNULL(COUNT(id), 0) as count,
+ IFNULL(AVG(difficulty), 0) as average,
+ IFNULL(ROUND(SUM((difficulty * 65536) / POW(2, (" . $this->config['difficulty'] . " -16))), 0), 0) AS expected,
+ IFNULL(ROUND(SUM(shares)), 0) as shares,
+ IFNULL(SUM(amount), 0) as rewards
+ FROM " . $this->block->getTableName() . "
+ WHERE FROM_UNIXTIME(time) > DATE_SUB(now(), INTERVAL ? HOUR)
+ AND confirmations >= 1");
+ if ($this->checkStmt($stmt) && $stmt->bind_param("i", $hour) && $stmt->execute() && $result = $stmt->get_result())
+ return $this->memcache->setCache(__FUNCTION__ . $hour, $result->fetch_assoc());
+ // Catchall
+ $this->debug->append("Failed to get pool statistics:" . $this->mysqli->error);
+ return false;
+ }
+
}
diff --git a/public/include/pages/statistics/blocks.inc.php b/public/include/pages/statistics/blocks.inc.php
index c21a078b..93e1c338 100644
--- a/public/include/pages/statistics/blocks.inc.php
+++ b/public/include/pages/statistics/blocks.inc.php
@@ -68,11 +68,15 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
}
}
}
-//var_dump($aBlocksFoundData);
+
+ $iHours = 24;
+ $aPoolStatistics = $statistics->getPoolStatsHours($iHours);
+
// Propagate content our template
$smarty->assign("BLOCKSFOUND", $aBlocksFoundData);
$smarty->assign("BLOCKLIMIT", $iLimit);
$smarty->assign("USEBLOCKAVERAGE", $use_average);
+ $smarty->assign("POOLSTATS", $aPoolStatistics);
} else {
$debug->append('Using cached page', 3);
}
diff --git a/public/templates/mmcFE/statistics/blocks/default.tpl b/public/templates/mmcFE/statistics/blocks/default.tpl
index 2d952f86..5e80d361 100644
--- a/public/templates/mmcFE/statistics/blocks/default.tpl
+++ b/public/templates/mmcFE/statistics/blocks/default.tpl
@@ -40,6 +40,35 @@
The graph above illustrates N shares to find a block vs. E Shares expected to find a block based on
target and network difficulty and assuming a zero variance scenario.
+
+
+
+
+ | Last 24 hour totals |
+
+
+ | Blocks Found |
+ Rewards |
+ Avg Difficulty |
+ Expected Shares |
+ Actual Shares |
+ Percentage |
+
+
+
+ {assign var=percentage1 value=0}
+
+ | {$POOLSTATS.count|number_format:"0"} |
+ {$POOLSTATS.rewards|number_format:"4"} |
+ {$POOLSTATS.average|number_format:"4"} |
+ {$POOLSTATS.expected|number_format:"0"} |
+ {$POOLSTATS.shares|number_format:"0"} |
+ {if $POOLSTATS.shares > 0}{math assign="percentage1" equation="shares1 / estshares1 * 100" shares1=$POOLSTATS.shares estshares1=$POOLSTATS.expected}{/if}
+ {$percentage1|number_format:"2"} |
+
+
+
+
diff --git a/public/templates/mpos/statistics/blocks/default.tpl b/public/templates/mpos/statistics/blocks/default.tpl
index c2587a12..0e089b4b 100644
--- a/public/templates/mpos/statistics/blocks/default.tpl
+++ b/public/templates/mpos/statistics/blocks/default.tpl
@@ -36,6 +36,36 @@
{/if}
+
+
+
+
+
+ | Last 24 hour totals |
+
+
+ | Blocks Found |
+ Rewards |
+ Avg Difficulty |
+ Expected Shares |
+ Actual Shares |
+ Percentage |
+
+
+
+ {assign var=percentage1 value=0}
+
+ | {$POOLSTATS.count|number_format:"0"} |
+ {$POOLSTATS.rewards|number_format:"4"} |
+ {$POOLSTATS.average|number_format:"4"} |
+ {$POOLSTATS.expected|number_format:"0"} |
+ {$POOLSTATS.shares|number_format:"0"} |
+ {if $POOLSTATS.shares > 0}{math assign="percentage1" equation="shares1 / estshares1 * 100" shares1=$POOLSTATS.shares estshares1=$POOLSTATS.expected}{/if}
+ {$percentage1|number_format:"2"} |
+
+
+
+
@@ -77,7 +107,6 @@
{assign var=count value=0}
{assign var=totalexpectedshares value=0}
{assign var=totalshares value=0}
-{assign var=totalpercentage value=0}
{assign var=pplnsshares value=0}
{section block $BLOCKSFOUND}
{assign var="totalshares" value=$totalshares+$BLOCKSFOUND[block].shares}
@@ -110,7 +139,6 @@
| {$BLOCKSFOUND[block].shares|number_format} |
{math assign="percentage" equation="shares / estshares * 100" shares=$BLOCKSFOUND[block].shares estshares=$BLOCKSFOUND[block].estshares}
-{assign var="totalpercentage" value=$totalpercentage+$percentage}
{$percentage|number_format:"2"}
|