obigals work, cherrypicked
This commit is contained in:
parent
5b353ab759
commit
b3ba080345
160
public/include/classes/roundstats.class.php
Normal file
160
public/include/classes/roundstats.class.php
Normal file
@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
class RoundStats {
|
||||
private $sError = '';
|
||||
private $tableTrans = 'transactions';
|
||||
private $tableStats = 'statistics_shares';
|
||||
private $tableBlocks = 'blocks';
|
||||
private $tableUsers = 'accounts';
|
||||
|
||||
public function __construct($debug, $mysqli, $config) {
|
||||
$this->debug = $debug;
|
||||
$this->mysqli = $mysqli;
|
||||
$this->config = $config;
|
||||
$this->debug->append("Instantiated RoundStats class", 2);
|
||||
}
|
||||
|
||||
// get and set methods
|
||||
private function setErrorMessage($msg) {
|
||||
$this->sError = $msg;
|
||||
}
|
||||
public function getError() {
|
||||
return $this->sError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next block for round stats
|
||||
**/
|
||||
public function getNextBlockDesc($iHeight=0) {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT height
|
||||
FROM $this->tableBlocks
|
||||
WHERE height < ?
|
||||
ORDER BY height DESC
|
||||
LIMIT 1");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->height;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prev block for round stats
|
||||
**/
|
||||
public function getNextBlockAsc($iHeight=0) {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT height
|
||||
FROM $this->tableBlocks
|
||||
WHERE height > ?
|
||||
ORDER BY height ASC
|
||||
LIMIT 1");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->height;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get details for block height
|
||||
* @param height int Block Height
|
||||
* @return data array Block information from DB
|
||||
**/
|
||||
public function getDetailsForBlockHeight($iHeight=0, $isAdmin=0) {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
b.id, height, amount, confirmations, difficulty, FROM_UNIXTIME(time) as time, shares,
|
||||
IF(a.is_anonymous, IF( ? , a.username, 'anonymous'), a.username) AS finder
|
||||
FROM $this->tableBlocks as b
|
||||
LEFT JOIN $this->tableUsers AS a ON b.account_id = a.id
|
||||
WHERE b.height = ? LIMIT 1");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $isAdmin, $iHeight) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_assoc();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shares statistics for round block height
|
||||
* @param height int Block Height
|
||||
* @return data array Block information from DB
|
||||
**/
|
||||
public function getRoundStatsForAccounts($iHeight=0, $isAdmin=0) {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
IF(a.is_anonymous, IF( ? , a.username, 'anonymous'), a.username) AS username,
|
||||
s.valid,
|
||||
s.invalid
|
||||
FROM $this->tableStats AS s
|
||||
LEFT JOIN $this->tableBlocks AS b ON s.block_id = b.id
|
||||
LEFT JOIN $this->tableUsers AS a ON a.id = s.account_id
|
||||
WHERE b.height = ?
|
||||
GROUP BY username ASC
|
||||
ORDER BY valid DESC
|
||||
");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $isAdmin, $iHeight) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all transactions for round block height for admin
|
||||
* @param height int Block Height
|
||||
* @return data array Block round transactions
|
||||
**/
|
||||
public function getAllRoundTransactions($iHeight=0) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
t.id AS id,
|
||||
a.username AS username,
|
||||
t.type AS type,
|
||||
t.amount AS amount
|
||||
FROM $this->tableTrans AS t
|
||||
LEFT JOIN $this->tableBlocks AS b ON t.block_id = b.id
|
||||
LEFT JOIN $this->tableUsers AS a ON t.account_id = a.id
|
||||
WHERE b.height = ?
|
||||
ORDER BY id ASC");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
$this->debug->append('Unable to fetch transactions');
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get transactions for round block height user id
|
||||
* @param height int Block Height
|
||||
* @param id int user id
|
||||
* @return data array Block round transactions for user id
|
||||
**/
|
||||
public function getUserRoundTransactions($iHeight=0, $id=0) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
t.id AS id,
|
||||
a.username AS username,
|
||||
t.type AS type,
|
||||
t.amount AS amount
|
||||
FROM $this->tableTrans AS t
|
||||
LEFT JOIN $this->tableBlocks AS b ON t.block_id = b.id
|
||||
LEFT JOIN $this->tableUsers AS a ON t.account_id = a.id
|
||||
WHERE b.height = ? AND a.id = ?
|
||||
ORDER BY id ASC");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $iHeight, $id) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
$this->debug->append('Unable to fetch transactions');
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkStmt($bState) {
|
||||
if ($bState ===! true) {
|
||||
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
|
||||
$this->setErrorMessage('Internal application Error');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$roundstats = new RoundStats($debug, $mysqli, $config);
|
||||
@ -3,17 +3,39 @@
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY')) die('Hacking attempt');
|
||||
|
||||
if ($user->isAuthenticated()) {
|
||||
// Check if we want a specific round or general stats
|
||||
if (!empty($_REQUEST['round'])) $round = $_REQUEST['round'];
|
||||
if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
|
||||
$debug->append('No cached version available, fetching from backend', 3);
|
||||
|
||||
// Cache detection and content generation
|
||||
if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
|
||||
$debug->append('No cached version available, fetching from backend', 3);
|
||||
if (@$_REQUEST['next'] && !empty($_REQUEST['tx_key'])) {
|
||||
$_REQUEST['tx_key'] = $roundstats->getNextBlockDesc($_REQUEST['tx_key']);
|
||||
} else if (@$_REQUEST['prev'] && !empty($_REQUEST['tx_key'])) {
|
||||
$_REQUEST['tx_key'] = $roundstats->getNextBlockAsc($_REQUEST['tx_key']);
|
||||
}
|
||||
|
||||
} else {
|
||||
$debug->append('Using cached page', 3);
|
||||
}
|
||||
$smarty->assign("CONTENT", "default.tpl");
|
||||
if (empty($_REQUEST['tx_key'])) {
|
||||
$iBlock = $block->getLast();
|
||||
$iKey = $iBlock['height'];
|
||||
$_REQUEST['tx_key'] = $iKey;
|
||||
} else {
|
||||
$iKey = $_REQUEST['tx_key'];
|
||||
}
|
||||
|
||||
$aDetailsForBlockHeight = $roundstats->getDetailsForBlockHeight($iKey, $user->isAdmin($_SESSION['USERDATA']['id']));
|
||||
$aRoundShareStats = $roundstats->getRoundStatsForAccounts($iKey, $user->isAdmin($_SESSION['USERDATA']['id']));
|
||||
|
||||
if ($user->isAdmin($_SESSION['USERDATA']['id'])) {
|
||||
$aUserRoundTransactions = $roundstats->getAllRoundTransactions($iKey);
|
||||
} else {
|
||||
$aUserRoundTransactions = $roundstats->getUserRoundTransactions($iKey, $_SESSION['USERDATA']['id']);
|
||||
}
|
||||
|
||||
// Propagate content our template
|
||||
$smarty->assign('BLOCKDETAILS', $aDetailsForBlockHeight);
|
||||
$smarty->assign('ROUNDSHARES', $aRoundShareStats);
|
||||
$smarty->assign("ROUNDTRANSACTIONS", $aUserRoundTransactions);
|
||||
} else {
|
||||
$debug->append('Using cached page', 3);
|
||||
}
|
||||
|
||||
$smarty->assign("CONTENT", "default.tpl");
|
||||
?>
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
<li><a href="{$smarty.server.PHP_SELF}?page=statistics&action=pool">Pool Stats</a></li>
|
||||
<li><a href="{$smarty.server.PHP_SELF}?page=statistics&action=blocks">Block Stats</a></li>
|
||||
<li><a href="{$smarty.server.PHP_SELF}?page=statistics&action=graphs">Hashrate Graphs</a></li>
|
||||
<li><a href="{$smarty.server.PHP_SELF}?page=statistics&action=round">Round Stats</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{else}
|
||||
|
||||
61
public/templates/mmcFE/statistics/round/block_stats.tpl
Normal file
61
public/templates/mmcFE/statistics/round/block_stats.tpl
Normal file
@ -0,0 +1,61 @@
|
||||
{include file="global/block_header.tpl" ALIGN="left" BLOCK_STYLE="width: 100%" BLOCK_HEADER="Block Stats" STYLE="padding-left:5px;padding-right:5px;"}
|
||||
<table align="left" width="100%" border="0" style="font-size:13px;"><tbody><tr><td class="left">
|
||||
<table align="left" width="100%" border="0" style="font-size:13px;">
|
||||
<thead>
|
||||
<tr style="background-color:#B6DAFF;">
|
||||
<th align="left">Name</th>
|
||||
<th scope="col">Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="odd">
|
||||
<td>Block Id</td>
|
||||
<td>{$BLOCKDETAILS.id|default:"0"}</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td>Heigth</td>
|
||||
<td>{$BLOCKDETAILS.height|default:"0"}</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td>Amount</td>
|
||||
<td>{$BLOCKDETAILS.amount|default:"0"}</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td>Confirmations</td>
|
||||
<td>{$BLOCKDETAILS.confirmations|default:"0"}</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td>Difficulty</td>
|
||||
<td>{$BLOCKDETAILS.difficulty|default:"0"}</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td>Time</td>
|
||||
<td>{$BLOCKDETAILS.time|default:"0"}</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td>Shares</td>
|
||||
<td>{$BLOCKDETAILS.shares|default:"0"}</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td>Finder</td>
|
||||
<td>{$BLOCKDETAILS.finder|default:"0"}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></td>
|
||||
<td class="right">
|
||||
<form action="{$smarty.server.PHP_SELF}" method="POST" id='tx_key'>
|
||||
<input type="hidden" name="page" value="{$smarty.request.page}">
|
||||
<input type="hidden" name="action" value="{$smarty.request.action}">
|
||||
<input type="text" class="pin" name="tx_key" value="{$smarty.request.tx_key|default:"%"}">
|
||||
<input type="submit" class="submit small" value="Search">
|
||||
</form></td></tr>
|
||||
<tr>
|
||||
<td class="left">
|
||||
<a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page}&action={$smarty.request.action}&tx_key={$BLOCKDETAILS.height}&prev=1"><img src="{$PATH}/images/prev.png" /></a>
|
||||
</td>
|
||||
<td class="right">
|
||||
<a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page}&action={$smarty.request.action}&tx_key={$BLOCKDETAILS.height}&next=1"><img src="{$PATH}/images/next.png" /></a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
{include file="global/block_footer.tpl"}
|
||||
@ -1 +1,9 @@
|
||||
Need content for me
|
||||
{include file="global/block_header.tpl" BLOCK_HEADER="Round Statistics" BLOCK_STYLE="clear:none;"}
|
||||
|
||||
{include file="statistics/round/block_stats.tpl"}
|
||||
|
||||
{include file="statistics/round/round_transactions.tpl"}
|
||||
|
||||
{include file="statistics/round/round_shares.tpl"}
|
||||
|
||||
{include file="global/block_footer.tpl"}
|
||||
|
||||
26
public/templates/mmcFE/statistics/round/round_shares.tpl
Normal file
26
public/templates/mmcFE/statistics/round/round_shares.tpl
Normal file
@ -0,0 +1,26 @@
|
||||
{include file="global/block_header.tpl" ALIGN="left" BLOCK_HEADER="Round Shares" }
|
||||
<center>
|
||||
<table width="100%" border="0" style="font-size:13px;">
|
||||
<thead>
|
||||
<tr style="background-color:#B6DAFF;">
|
||||
<th align="left">Rank</th>
|
||||
<th align="left" scope="col">User Name</th>
|
||||
<th class="right" scope="col">Valid</th>
|
||||
<th class="right" scope="col">Invalid</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{assign var=rank value=1}
|
||||
{assign var=listed value=0}
|
||||
{section contrib $ROUNDSHARES}
|
||||
<tr{if $GLOBAL.userdata.username == $ROUNDSHARES[contrib].username}{assign var=listed value=1} style="background-color:#99EB99;"{else} class="{cycle values="odd,even"}"{/if}>
|
||||
<td>{$rank++}</td>
|
||||
<td>{if $ROUNDSHARES[contrib].is_anonymous|default:"0" == 1}anonymous{else}{$ROUNDSHARES[contrib].username|escape}{/if}</td>
|
||||
<td class="right">{$ROUNDSHARES[contrib].valid|number_format}</td>
|
||||
<td class="right">{$ROUNDSHARES[contrib].invalid|number_format}</td>
|
||||
</tr>
|
||||
{/section}
|
||||
</tbody>
|
||||
</table>
|
||||
</center>
|
||||
{include file="global/block_footer.tpl"}
|
||||
@ -0,0 +1,24 @@
|
||||
{include file="global/block_header.tpl" ALIGN="right" BLOCK_HEADER="Round Transactions"}
|
||||
<center>
|
||||
<table width="100%" border="0" style="font-size:13px;">
|
||||
<thead>
|
||||
<tr style="background-color:#B6DAFF;">
|
||||
<th align="left">Tx Id</th>
|
||||
<th scope="col">User Name</th>
|
||||
<th scope="col">Type</th>
|
||||
<th class="right" scope="col">Amount</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{section txs $ROUNDTRANSACTIONS}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
<td>{$ROUNDTRANSACTIONS[txs].id|default:"0"}</td>
|
||||
<td>{$ROUNDTRANSACTIONS[txs].username|escape}</td>
|
||||
<td class="right">{$ROUNDTRANSACTIONS[txs].type|default:""}</td>
|
||||
<td class="right">{$ROUNDTRANSACTIONS[txs].amount|default:"0"|number_format:"8"}</td>
|
||||
</tr>
|
||||
{/section}
|
||||
</tbody>
|
||||
</table>
|
||||
</center>
|
||||
{include file="global/block_footer.tpl"}
|
||||
Loading…
Reference in New Issue
Block a user