[ADDED] Most recent found blocks to dashboard

This commit is contained in:
Sebastian Grewe 2014-05-04 09:58:44 +02:00
parent c81d2d1352
commit fa4b32e420
7 changed files with 236 additions and 5 deletions

View File

@ -82,6 +82,17 @@ $dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
$iBlocksUntilDiffChange = $statistics->getBlocksUntilDiffChange();
// Block statistics
$aLastBlocks = $statistics->getBlocksFound(5);
if (!$user->isAdmin(@$_SESSION['USERDATA']['id'])) {
foreach ($aLastBlocks as $key => $data) {
if ($data['is_anonymous'] == 1) {
$aLastBlocks[$key]['worker_name'] = 'anonymous';
$aLastBlocks[$key]['finder'] = 'anonymous';
}
}
}
// Output JSON format
$data = array(
'raw' => array( 'personal' => array( 'hashrate' => $dPersonalHashrate ), 'pool' => array( 'hashrate' => $dPoolHashrate ), 'network' => array( 'hashrate' => $dNetworkHashrate / 1000, 'esttimeperblock' => $dExpectedTimePerBlock, 'nextdifficulty' => $dEstNextDifficulty, 'blocksuntildiffchange' => $iBlocksUntilDiffChange ) ),
@ -94,6 +105,7 @@ $data = array(
'name' => $setting->getValue('website_name'),
'currency' => $config['currency']
),
'blocks' => $aLastBlocks,
'workers' => $worker->getCountAllActiveWorkers(), 'hashrate' => $dPoolHashrateAdjusted,
'shares' => array( 'valid' => $aRoundShares['valid'], 'invalid' => $aRoundShares['invalid'], 'invalid_percent' => $dPoolInvalidPercent, 'estimated' => $iEstShares, 'progress' => $dEstPercent ),
'price' => $aPrice,

View File

@ -37,7 +37,19 @@ if ($user->isAuthenticated()) {
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
$iBlocksUntilDiffChange = $statistics->getBlocksUntilDiffChange();
// Block statistics
$aLastBlocks = $statistics->getBlocksFound(5);
if (!$user->isAdmin(@$_SESSION['USERDATA']['id'])) {
foreach ($aLastBlocks as $key => $data) {
if ($data['is_anonymous'] == 1) {
$aLastBlocks[$key]['worker_name'] = 'anonymous';
$aLastBlocks[$key]['finder'] = 'anonymous';
}
}
}
// Make it available in Smarty
$smarty->assign('BLOCKSFOUND', $aLastBlocks);
$smarty->assign('DISABLED_DASHBOARD', $setting->getValue('disable_dashboard'));
$smarty->assign('DISABLED_DASHBOARD_API', $setting->getValue('disable_dashboard_api'));
$smarty->assign('ESTIMATES', array('shares' => $iEstShares, 'percent' => $dEstPercent));

View File

@ -34,9 +34,9 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$test = true;
$count = 10;
$percent = 30;
if (@$_REQUEST['count'] && is_numeric($_REQUEST['count']))
if (@$_REQUEST['count'] && is_numeric($_REQUEST['count']))
$count = $_REQUEST['count'];
if (@$_REQUEST['percent'] && is_numeric($_REQUEST['percent']))
if (@$_REQUEST['percent'] && is_numeric($_REQUEST['percent']))
$percent = $_REQUEST['percent'];
}
@ -48,19 +48,19 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
if ($setting->getValue('statistics_show_block_average') && !$test) {
$aBlocksFoundData[$key]['block_avg'] = round($block->getAvgBlockShares($aData['height'], $config['pplns']['blockavg']['blockcount']));
$use_average = true;
}
}
}
} else if ($config['payout_system'] == 'prop' || $config['payout_system'] == 'pps') {
if ($setting->getValue('statistics_show_block_average') && !$test) {
foreach($aBlocksFoundData as $key => $aData) {
$aBlocksFoundData[$key]['block_avg'] = round($block->getAvgBlockShares($aData['height'], $config['pplns']['blockavg']['blockcount']));
$use_average = true;
}
}
}
}
// show test data in graph
if ($test) {
$use_average = true;
$use_average = true;
foreach($aBlocksFoundData as $key => $aData) {
if ($_REQUEST['test'] == 1) {
$aBlocksFoundData[$key]['block_avg'] = round($block->getAvgBlockShares($aData['height'], $count));

View File

@ -0,0 +1,126 @@
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
*
* Accepts a date, a mask, or a date and a mask.
* Returns a formatted version of the given date.
* The date defaults to the current date/time.
* The mask defaults to dateFormat.masks.default.
*/
var dateFormat = function () {
var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
timezoneClip = /[^-+\dA-Z]/g,
pad = function (val, len) {
val = String(val);
len = len || 2;
while (val.length < len) val = "0" + val;
return val;
};
// Regexes and supporting functions are cached through closure
return function (date, mask, utc) {
var dF = dateFormat;
// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
mask = date;
date = undefined;
}
// Passing date through Date applies Date.parse, if necessary
date = date ? new Date(date) : new Date;
if (isNaN(date)) throw SyntaxError("invalid date");
mask = String(dF.masks[mask] || mask || dF.masks["default"]);
// Allow setting the utc argument via the mask
if (mask.slice(0, 4) == "UTC:") {
mask = mask.slice(4);
utc = true;
}
var _ = utc ? "getUTC" : "get",
d = date[_ + "Date"](),
D = date[_ + "Day"](),
m = date[_ + "Month"](),
y = date[_ + "FullYear"](),
H = date[_ + "Hours"](),
M = date[_ + "Minutes"](),
s = date[_ + "Seconds"](),
L = date[_ + "Milliseconds"](),
o = utc ? 0 : date.getTimezoneOffset(),
flags = {
d: d,
dd: pad(d),
ddd: dF.i18n.dayNames[D],
dddd: dF.i18n.dayNames[D + 7],
m: m + 1,
mm: pad(m + 1),
mmm: dF.i18n.monthNames[m],
mmmm: dF.i18n.monthNames[m + 12],
yy: String(y).slice(2),
yyyy: y,
h: H % 12 || 12,
hh: pad(H % 12 || 12),
H: H,
HH: pad(H),
M: M,
MM: pad(M),
s: s,
ss: pad(s),
l: pad(L, 3),
L: pad(L > 99 ? Math.round(L / 10) : L),
t: H < 12 ? "a" : "p",
tt: H < 12 ? "am" : "pm",
T: H < 12 ? "A" : "P",
TT: H < 12 ? "AM" : "PM",
Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
};
return mask.replace(token, function ($0) {
return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
});
};
}();
// Some common format strings
dateFormat.masks = {
"default": "ddd mmm dd yyyy HH:MM:ss",
shortDate: "m/d/yy",
mediumDate: "mmm d, yyyy",
longDate: "mmmm d, yyyy",
fullDate: "dddd, mmmm d, yyyy",
shortTime: "h:MM TT",
mediumTime: "h:MM:ss TT",
longTime: "h:MM:ss TT Z",
isoDate: "yyyy-mm-dd",
isoTime: "HH:MM:ss",
isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};
// Internationalization strings
dateFormat.i18n = {
dayNames: [
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
],
monthNames: [
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
]
};
// For convenience...
Date.prototype.format = function (mask, utc) {
return dateFormat(this, mask, utc);
};

View File

@ -0,0 +1,42 @@
{if !$DISABLED_DASHBOARD and !$DISABLED_DASHBOARD_API}
<div class="col-lg-12">
<div class="panel panel-info">
<div class="panel-heading">
<h4 class="panel-title"><i class="fa fa-desktop fa-fw"></i> Last Found Blocks</h4>
</div>
<div class="panel-body no-padding table-responsive">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th class="text-right">Height</th>
<th class="text-center">Finder</th>
<th class="text-right">Time</th>
<th class="text-right">Difficulty</th>
<th class="text-right">Amount</th>
<th class="text-right">Expected Shares</th>
<th class="text-right">Actual Shares</th>
<th class="text-right">Percentage</th>
</tr>
</thead>
<tbody id="b-blocks">
{section block $BLOCKSFOUND}
<tr>
<td class="text-right">{$BLOCKSFOUND[block].height}</td>
<td>{if $BLOCKSFOUND[block].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$BLOCKSFOUND[block].finder|default:"unknown"|escape}{/if}</td>
<td class="text-right">{$BLOCKSFOUND[block].time|date_format:$GLOBAL.config.date}</td>
<td class="text-right">{$BLOCKSFOUND[block].difficulty|number_format:"4"}</td>
<td class="text-right">{$BLOCKSFOUND[block].amount|number_format:"2"}</td>
<td class="text-right">{$BLOCKSFOUND[block].estshares|number_format}</td>
<td class="text-right">{$BLOCKSFOUND[block].shares|number_format}</td>
<td class="text-right">
{math assign="percentage" equation="shares / estshares * 100" shares=$BLOCKSFOUND[block].shares|default:"0" estshares=$BLOCKSFOUND[block].estshares}
<font color="{if ($percentage <= 100)}green{else}red{/if}">{$percentage|number_format:"2"}</font>
</td>
</tr>
{/section}
</tbody>
</table>
</div>
</div>
</div>
{/if}

View File

@ -1,4 +1,5 @@
{if $smarty.session.AUTHENTICATED|default}
<script src="{$PATH}/js/plugins/date.format.js"></script>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-info">
@ -14,6 +15,7 @@
{include file="dashboard/round_statistics/$PAYOUT_SYSTEM/default.tpl"}
{include file="dashboard/account_data/default.tpl"}
{include file="dashboard/worker_information/default.tpl"}
{include file="dashboard/blocks/default.tpl"}
</div>
</div>
</div>

View File

@ -18,6 +18,7 @@ $(document).ready(function(){
null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null,
{/literal}{$GLOBAL.price}{literal} ];
var lastBlock = 0;
// Sparkline options applied to all graphs
var sparklineBarOptions = {
@ -152,6 +153,41 @@ $(document).ready(function(){
if (totalHashrate > 0) { $('#b-workers').append('<tr><td class="text-left"><b>Total</b></td><td class="text-right">' + number_format(totalHashrate, 2) + '</td><td></td></tr>'); }
}
function refreshBlockData(data) {
blocks = data.getdashboarddata.data.pool.blocks;
console.log(blocks);
if (blocks[0].height > lastBlock) {
lastBlock = blocks[0].height;
console.log('New block is higher, re-draw table');
var table_content = '<tbody id="b-blocks">';
for (index = 0; index < blocks.length; ++index) {
console.log(blocks[index]);
var time = new Date.UTC(blocks[index].time * 1000)
var table_row = '<tr>';
table_row += '<td class="text-right">' + blocks[index].height + '</td>';
table_row += '<td class="text-center">' + blocks[index].finder + '</td>';
table_row += '<td class="text-right">' + time.format("mm/dd/yy HH:MM:ss") + '</td>';
table_row += '<td class="text-right">' + blocks[index].difficulty + '</td>';
table_row += '<td class="text-right">' + blocks[index].amount + '</td>';
table_row += '<td class="text-right">' + blocks[index].estshares + '</td>';
table_row += '<td class="text-right">' + blocks[index].shares + '</td>';
percentage = parseFloat(blocks[index].shares / blocks[index].estshares * 100).toFixed(2);
if (percentage <= 100) {
color = 'green';
} else {
color = 'red';
}
table_row += '<td class="text-right"><font color="'+color+'">' + percentage + '</font></td>';
table_row += '</tr>';
table_content += table_row;
}
table_content += '</tbody>';
$("tbody#b-blocks").replaceWith(table_content);
} else {
console.log('No table update required');
}
}
// Refresh balance information
function refreshBalanceData(data) {
balance = data.getuserbalance.data
@ -170,6 +206,7 @@ $(document).ready(function(){
success: function(data) {
refreshInformation(data);
refreshStaticData(data);
refreshBlockData(data);
},
complete: function() {
setTimeout(worker1, {/literal}{($GLOBAL.config.statistics_ajax_refresh_interval * 1000)|default:"10000"}{literal})