diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php
index 9bfd8ae3..02b3f204 100644
--- a/public/include/classes/statistics.class.php
+++ b/public/include/classes/statistics.class.php
@@ -25,35 +25,29 @@ class Statistics extends Base {
/**
* Fetch last found blocks by time
**/
- function getLastValidBlocksbyTime($aTimeFrame) {
+ function getLastBlocksbyTime() {
$this->debug->append("STA " . __METHOD__, 4);
- if ($data = $this->memcache->get(__FUNCTION__ . $aTimeFrame)) return $data;
- $date = new DateTime();
- $actualTime = $date->getTimestamp();
- $aTimeDiff = $actualTime - $aTimeFrame;
- if ($aTimeFrame == 0) $aTimeDiff = 0;
+ if ($data = $this->memcache->get(__FUNCTION__)) return $data;
$stmt = $this->mysqli->prepare("
- SELECT COUNT(id) AS count FROM " . $this->block->getTableName() . "
- WHERE confirmations > 0
- AND time >= ?");
- if ($this->checkStmt($stmt) && $stmt->bind_param('i', $aTimeDiff) && $stmt->execute() && $result = $stmt->get_result())
- return $this->memcache->setCache(__FUNCTION__ . $aTimeFrame, $result->fetch_object()->count);
- return $this->sqlError();
- }
-
- function getLastOrphanBlocksbyTime($aTimeFrame) {
- $this->debug->append("STA " . __METHOD__, 4);
- if ($data = $this->memcache->get(__FUNCTION__ . $aTimeFrame)) return $data;
- $date = new DateTime();
- $actualTime = $date->getTimestamp();
- $aTimeDiff = $actualTime - $aTimeFrame;
- if ($aTimeFrame == 0) $aTimeDiff = 0;
- $stmt = $this->mysqli->prepare("
- SELECT COUNT(id) AS count FROM " . $this->block->getTableName() . "
- WHERE confirmations = -1
- AND time >= ?");
- if ($this->checkStmt($stmt) && $stmt->bind_param('i', $aTimeDiff) && $stmt->execute() && $result = $stmt->get_result())
- return $this->memcache->setCache(__FUNCTION__ . $aTimeFrame, $result->fetch_object()->count);
+ SELECT
+ COUNT(id) AS Total,
+ IFNULL(SUM(IF(confirmations > 0, 1, 0)), 0) AS TotalValid,
+ IFNULL(SUM(IF(confirmations = -1, 1, 0)), 0) AS TotalOrphan,
+ IFNULL(SUM(IF(FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 3600 SECOND), 1, 0)), 0) AS 1HourTotal,
+ IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 3600 SECOND), 1, 0)), 0) AS 1HourValid,
+ IFNULL(SUM(IF(confirmations = -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 3600 SECOND), 1, 0)), 0) AS 1HourOrphan,
+ IFNULL(SUM(IF(FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 86400 SECOND), 1, 0)), 0) AS 24HourTotal,
+ IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 86400 SECOND), 1, 0)), 0) AS 24HourValid,
+ IFNULL(SUM(IF(confirmations = -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 86400 SECOND), 1, 0)), 0) AS 24HourOrphan,
+ IFNULL(SUM(IF(FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 604800 SECOND), 1, 0)), 0) AS 7DaysTotal,
+ IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 604800 SECOND), 1, 0)), 0) AS 7DaysValid,
+ IFNULL(SUM(IF(confirmations = -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 604800 SECOND), 1, 0)), 0) AS 7DaysOrphan,
+ IFNULL(SUM(IF(FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 2419200 SECOND), 1, 0)), 0) AS 4WeeksTotal,
+ IFNULL(SUM(IF(confirmations > 0 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 2419200 SECOND), 1, 0)), 0) AS 4WeeksValid,
+ IFNULL(SUM(IF(confirmations = -1 AND FROM_UNIXTIME(time) >= DATE_SUB(now(), INTERVAL 2419200 SECOND), 1, 0)), 0) AS 4WeeksOrphan
+ FROM " . $this->block->getTableName());
+ if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
+ return $this->memcache->setCache(__FUNCTION__, $result->fetch_assoc());
return $this->sqlError();
}
diff --git a/public/include/pages/statistics/blocks.inc.php b/public/include/pages/statistics/blocks.inc.php
index 93e1c338..d77663b4 100644
--- a/public/include/pages/statistics/blocks.inc.php
+++ b/public/include/pages/statistics/blocks.inc.php
@@ -72,7 +72,11 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$iHours = 24;
$aPoolStatistics = $statistics->getPoolStatsHours($iHours);
+ // Past blocks found, max 4 weeks back
+ $iFoundBlocksByTime = $statistics->getLastBlocksbyTime();
+
// Propagate content our template
+ $smarty->assign("LASTBLOCKSBYTIME", $iFoundBlocksByTime);
$smarty->assign("BLOCKSFOUND", $aBlocksFoundData);
$smarty->assign("BLOCKLIMIT", $iLimit);
$smarty->assign("USEBLOCKAVERAGE", $use_average);
diff --git a/public/include/pages/statistics/pool.inc.php b/public/include/pages/statistics/pool.inc.php
index e5f76f79..c53a0c05 100644
--- a/public/include/pages/statistics/pool.inc.php
+++ b/public/include/pages/statistics/pool.inc.php
@@ -42,35 +42,11 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$dTimeSinceLast = 0;
}
-
- $iFoundLastValid = $statistics->getLastValidBlocksbyTime(0);
- $iFoundLastHourValid = $statistics->getLastValidBlocksbyTime(3600);
- $iFoundLastDayValid = $statistics->getLastValidBlocksbyTime(86400);
- $iFoundLastWeekValid = $statistics->getLastValidBlocksbyTime(604800);
- $iFoundLastMonthValid = $statistics->getLastValidBlocksbyTime(2419200);
-
- $iFoundLastOrphan = $statistics->getLastOrphanBlocksbyTime(0);
- $iFoundLastHourOrphan = $statistics->getLastOrphanBlocksbyTime(3600);
- $iFoundLastDayOrphan = $statistics->getLastOrphanBlocksbyTime(86400);
- $iFoundLastWeekOrphan = $statistics->getLastOrphanBlocksbyTime(604800);
- $iFoundLastMonthOrphan = $statistics->getLastOrphanBlocksbyTime(2419200);
-
+ // Past blocks found, max 4 weeks back
+ $iFoundBlocksByTime = $statistics->getLastBlocksbyTime();
// Propagate content our template
-
- $smarty->assign("FOUNDALLVALID", $iFoundLastValid);
- $smarty->assign("FOUNDLASTHOURVALID", $iFoundLastHourValid);
- $smarty->assign("FOUNDLAST24HOURSVALID", $iFoundLastDayValid);
- $smarty->assign("FOUNDLAST7DAYSVALID", $iFoundLastWeekValid);
- $smarty->assign("FOUNDLAST4WEEKSVALID", $iFoundLastMonthValid);
-
- $smarty->assign("FOUNDALLORPHAN", $iFoundLastOrphan);
- $smarty->assign("FOUNDLASTHOURORPHAN", $iFoundLastHourOrphan);
- $smarty->assign("FOUNDLAST24HOURSORPHAN", $iFoundLastDayOrphan);
- $smarty->assign("FOUNDLAST7DAYSORPHAN", $iFoundLastWeekOrphan);
- $smarty->assign("FOUNDLAST4WEEKSORPHAN", $iFoundLastMonthOrphan);
-
- $smarty->assign("ESTTIME", $iEstTime);
+ $smarty->assign("LASTBLOCKSBYTIME", $iFoundBlocksByTime);
$smarty->assign("ESTTIME", $iEstTime);
$smarty->assign("TIMESINCELAST", $dTimeSinceLast);
$smarty->assign("BLOCKSFOUND", $aBlocksFoundData);
diff --git a/public/templates/mpos/statistics/blocks/block_overview_time.tpl b/public/templates/mpos/statistics/blocks/block_overview_time.tpl
new file mode 100644
index 00000000..7b793a8b
--- /dev/null
+++ b/public/templates/mpos/statistics/blocks/block_overview_time.tpl
@@ -0,0 +1,45 @@
+
+
+
+
+
+ |
+ Found |
+ Valid |
+ Orphan |
+
+
+
+
+ | All Time
+ | {$LASTBLOCKSBYTIME.Total} |
+ {$LASTBLOCKSBYTIME.TotalValid} |
+ {$LASTBLOCKSBYTIME.TotalOrphan} |
+
+
+ | Last Hour
+ | {$LASTBLOCKSBYTIME.1HourTotal} |
+ {$LASTBLOCKSBYTIME.1HourValid} |
+ {$LASTBLOCKSBYTIME.1HourOrphan} |
+
+
+ | Last 24 Hours
+ | {$LASTBLOCKSBYTIME.24HourTotal} |
+ {$LASTBLOCKSBYTIME.24HourValid} |
+ {$LASTBLOCKSBYTIME.24HourOrphan} |
+
+
+ | Last 7 Days
+ | {$LASTBLOCKSBYTIME.7DaysTotal} |
+ {$LASTBLOCKSBYTIME.7DaysValid} |
+ {$LASTBLOCKSBYTIME.7DaysOrphan} |
+
+
+ | Last 4 Weeks
+ | {$LASTBLOCKSBYTIME.4WeeksTotal} |
+ {$LASTBLOCKSBYTIME.4WeeksValid} |
+ {$LASTBLOCKSBYTIME.4WeeksOrphan} |
+
+
+
+
diff --git a/public/templates/mpos/statistics/blocks/block_shares_graph.tpl b/public/templates/mpos/statistics/blocks/block_shares_graph.tpl
new file mode 100644
index 00000000..fb27a2b9
--- /dev/null
+++ b/public/templates/mpos/statistics/blocks/block_shares_graph.tpl
@@ -0,0 +1,45 @@
+
+
+
+ Block Shares
+
+
+{section block $BLOCKSFOUND step=-1}
+ | {$BLOCKSFOUND[block].height} |
+{/section}
+
+
+
+
+ | Expected |
+{section block $BLOCKSFOUND step=-1}
+ {$BLOCKSFOUND[block].estshares} |
+{/section}
+
+
+ | Actual |
+{section block $BLOCKSFOUND step=-1}
+ {$BLOCKSFOUND[block].shares|default:"0"} |
+{/section}
+
+ {if $GLOBAL.config.payout_system == 'pplns'}
+ | PPLNS |
+{section block $BLOCKSFOUND step=-1}
+ {$BLOCKSFOUND[block].pplns_shares} |
+{/section}
+
{/if}
+ {if $USEBLOCKAVERAGE}
+ | Average |
+{section block $BLOCKSFOUND step=-1}
+ {$BLOCKSFOUND[block].block_avg} |
+{/section}
+
{/if}
+
+
+
+
diff --git a/public/templates/mpos/statistics/blocks/block_shares_time.tpl b/public/templates/mpos/statistics/blocks/block_shares_time.tpl
new file mode 100644
index 00000000..3add8da4
--- /dev/null
+++ b/public/templates/mpos/statistics/blocks/block_shares_time.tpl
@@ -0,0 +1,40 @@
+
+
+
+
+
+ | 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/blocks_found_details.tpl b/public/templates/mpos/statistics/blocks/blocks_found_details.tpl
new file mode 100644
index 00000000..9ea712ce
--- /dev/null
+++ b/public/templates/mpos/statistics/blocks/blocks_found_details.tpl
@@ -0,0 +1,70 @@
+
+ Last {$BLOCKLIMIT} Blocks Found
+
+
+
+ | Block |
+ Validity |
+ Finder |
+ Time |
+ Difficulty |
+ Amount |
+ Expected Shares |
+{if $GLOBAL.config.payout_system == 'pplns'}PPLNS Shares | {/if}
+ Actual Shares |
+ Percentage |
+
+
+
+{assign var=count value=0}
+{assign var=totalexpectedshares value=0}
+{assign var=totalshares value=0}
+{assign var=pplnsshares value=0}
+{section block $BLOCKSFOUND}
+ {assign var="totalshares" value=$totalshares+$BLOCKSFOUND[block].shares}
+ {assign var="count" value=$count+1}
+ {if $GLOBAL.config.payout_system == 'pplns'}{assign var="pplnsshares" value=$pplnsshares+$BLOCKSFOUND[block].pplns_shares}{/if}
+
+{if ! $GLOBAL.website.blockexplorer.disabled}
+ | {$BLOCKSFOUND[block].height} |
+{else}
+ {$BLOCKSFOUND[block].height} |
+{/if}
+
+{if $BLOCKSFOUND[block].confirmations >= $GLOBAL.confirmations}
+ Confirmed
+{else if $BLOCKSFOUND[block].confirmations == -1}
+ Orphan
+{else}
+ {$GLOBAL.confirmations - $BLOCKSFOUND[block].confirmations} left
+{/if}
+ |
+ {if $BLOCKSFOUND[block].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$BLOCKSFOUND[block].finder|default:"unknown"|escape}{/if} |
+ {$BLOCKSFOUND[block].time|date_format:"%d/%m %H:%M:%S"} |
+ {$BLOCKSFOUND[block].difficulty|number_format:"2"} |
+ {$BLOCKSFOUND[block].amount|number_format:"2"} |
+
+{assign var="totalexpectedshares" value=$totalexpectedshares+$BLOCKSFOUND[block].estshares}
+ {$BLOCKSFOUND[block].estshares|number_format}
+ |
+{if $GLOBAL.config.payout_system == 'pplns'}{$BLOCKSFOUND[block].pplns_shares|number_format} | {/if}
+ {$BLOCKSFOUND[block].shares|number_format} |
+
+{math assign="percentage" equation="shares / estshares * 100" shares=$BLOCKSFOUND[block].shares|default:"0" estshares=$BLOCKSFOUND[block].estshares}
+ {$percentage|number_format:"2"}
+ |
+
+{/section}
+
+ | Totals |
+ {$totalexpectedshares|number_format} |
+ {if $GLOBAL.config.payout_system == 'pplns'}{$pplnsshares|number_format} | {/if}
+ {$totalshares|number_format} |
+ {if $count > 0}{($totalshares / $totalexpectedshares * 100)|number_format:"2"}{else}0{/if} |
+
+
+
+
+
diff --git a/public/templates/mpos/statistics/blocks/default.tpl b/public/templates/mpos/statistics/blocks/default.tpl
index d23d8713..2882fdb0 100644
--- a/public/templates/mpos/statistics/blocks/default.tpl
+++ b/public/templates/mpos/statistics/blocks/default.tpl
@@ -1,156 +1,4 @@
-
-
-
- Block Shares
-
-
-{section block $BLOCKSFOUND step=-1}
- | {$BLOCKSFOUND[block].height} |
-{/section}
-
-
-
-
- | Expected |
-{section block $BLOCKSFOUND step=-1}
- {$BLOCKSFOUND[block].estshares} |
-{/section}
-
-
- | Actual |
-{section block $BLOCKSFOUND step=-1}
- {$BLOCKSFOUND[block].shares|default:"0"} |
-{/section}
-
- {if $GLOBAL.config.payout_system == 'pplns'}
- | PPLNS |
-{section block $BLOCKSFOUND step=-1}
- {$BLOCKSFOUND[block].pplns_shares} |
-{/section}
-
{/if}
- {if $USEBLOCKAVERAGE}
- | Average |
-{section block $BLOCKSFOUND step=-1}
- {$BLOCKSFOUND[block].block_avg} |
-{/section}
-
{/if}
-
-
-
-
-
-
-
-
- | 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"} |
-
-
-
-
-
-
-
-
-
- Last {$BLOCKLIMIT} Blocks Found
-
-
-
- | Block |
- Validity |
- Finder |
- Time |
- Difficulty |
- Amount |
- Expected Shares |
-{if $GLOBAL.config.payout_system == 'pplns'}PPLNS Shares | {/if}
- Actual Shares |
- Percentage |
-
-
-
-{assign var=count value=0}
-{assign var=totalexpectedshares value=0}
-{assign var=totalshares value=0}
-{assign var=pplnsshares value=0}
-{section block $BLOCKSFOUND}
- {assign var="totalshares" value=$totalshares+$BLOCKSFOUND[block].shares}
- {assign var="count" value=$count+1}
- {if $GLOBAL.config.payout_system == 'pplns'}{assign var="pplnsshares" value=$pplnsshares+$BLOCKSFOUND[block].pplns_shares}{/if}
-
-{if ! $GLOBAL.website.blockexplorer.disabled}
- | {$BLOCKSFOUND[block].height} |
-{else}
- {$BLOCKSFOUND[block].height} |
-{/if}
-
-{if $BLOCKSFOUND[block].confirmations >= $GLOBAL.confirmations}
- Confirmed
-{else if $BLOCKSFOUND[block].confirmations == -1}
- Orphan
-{else}
- {$GLOBAL.confirmations - $BLOCKSFOUND[block].confirmations} left
-{/if}
- |
- {if $BLOCKSFOUND[block].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$BLOCKSFOUND[block].finder|default:"unknown"|escape}{/if} |
- {$BLOCKSFOUND[block].time|date_format:"%d/%m %H:%M:%S"} |
- {$BLOCKSFOUND[block].difficulty|number_format:"2"} |
- {$BLOCKSFOUND[block].amount|number_format:"2"} |
-
-{assign var="totalexpectedshares" value=$totalexpectedshares+$BLOCKSFOUND[block].estshares}
- {$BLOCKSFOUND[block].estshares|number_format}
- |
-{if $GLOBAL.config.payout_system == 'pplns'}{$BLOCKSFOUND[block].pplns_shares|number_format} | {/if}
- {$BLOCKSFOUND[block].shares|number_format} |
-
-{math assign="percentage" equation="shares / estshares * 100" shares=$BLOCKSFOUND[block].shares|default:"0" estshares=$BLOCKSFOUND[block].estshares}
- {$percentage|number_format:"2"}
- |
-
-{/section}
-
- | Totals |
- {$totalexpectedshares|number_format} |
- {if $GLOBAL.config.payout_system == 'pplns'}{$pplnsshares|number_format} | {/if}
- {$totalshares|number_format} |
- {if $count > 0}{($totalshares / $totalexpectedshares * 100)|number_format:"2"}{else}0{/if} |
-
-
-
-
-
+{include file="statistics/blocks/block_overview_time.tpl"}
+{include file="statistics/blocks/block_shares_time.tpl"}
+{include file="statistics/blocks/block_shares_graph.tpl"}
+{include file="statistics/blocks/blocks_found_details.tpl"}
diff --git a/public/templates/mpos/statistics/pool/general_stats.tpl b/public/templates/mpos/statistics/pool/general_stats.tpl
index e87bf49c..23562594 100644
--- a/public/templates/mpos/statistics/pool/general_stats.tpl
+++ b/public/templates/mpos/statistics/pool/general_stats.tpl
@@ -67,33 +67,33 @@
| All Time
- | {$FOUNDALLVALID + $FOUNDALLORPHAN} |
- {$FOUNDALLVALID} |
- {$FOUNDALLORPHAN} |
+ {$LASTBLOCKSBYTIME.Total} |
+ {$LASTBLOCKSBYTIME.TotalValid} |
+ {$LASTBLOCKSBYTIME.TotalOrphan} |
| Last Hour
- | {$FOUNDLASTHOURVALID + $FOUNDLASTHOURORPHAN} |
- {$FOUNDLASTHOURVALID} |
- {$FOUNDLASTHOURORPHAN} |
+ {$LASTBLOCKSBYTIME.1HourTotal} |
+ {$LASTBLOCKSBYTIME.1HourValid} |
+ {$LASTBLOCKSBYTIME.1HourOrphan} |
| Last 24 Hours
- | {$FOUNDLAST24HOURSVALID + $FOUNDLAST24HOURSORPHAN}
- | {$FOUNDLAST24HOURSVALID} |
- {$FOUNDLAST24HOURSORPHAN} |
+ {$LASTBLOCKSBYTIME.24HourTotal} |
+ {$LASTBLOCKSBYTIME.24HourValid} |
+ {$LASTBLOCKSBYTIME.24HourOrphan} |
| Last 7 Days
- | {$FOUNDLAST7DAYSVALID + $FOUNDLAST7DAYSORPHAN} |
- {$FOUNDLAST7DAYSVALID} |
- {$FOUNDLAST7DAYSORPHAN} |
+ {$LASTBLOCKSBYTIME.7DaysTotal} |
+ {$LASTBLOCKSBYTIME.7DaysValid} |
+ {$LASTBLOCKSBYTIME.7DaysOrphan} |
| Last 4 Weeks
- | {$FOUNDLAST4WEEKSVALID + $FOUNDLAST4WEEKSORPHAN} |
- {$FOUNDLAST4WEEKSVALID} |
- {$FOUNDLAST4WEEKSORPHAN} |
+ {$LASTBLOCKSBYTIME.4WeeksTotal} |
+ {$LASTBLOCKSBYTIME.4WeeksValid} |
+ {$LASTBLOCKSBYTIME.4WeeksOrphan} |