From fa4b32e420f7cb4225c7b79bb951361387a3b9f5 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 4 May 2014 09:58:44 +0200 Subject: [PATCH] [ADDED] Most recent found blocks to dashboard --- include/pages/api/getdashboarddata.inc.php | 12 ++ include/pages/dashboard.inc.php | 12 ++ include/pages/statistics/blocks.inc.php | 10 +- .../bootstrap/js/plugins/date.format.js | 126 ++++++++++++++++++ .../bootstrap/dashboard/blocks/default.tpl | 42 ++++++ templates/bootstrap/dashboard/default.tpl | 2 + templates/bootstrap/dashboard/js/api.tpl | 37 +++++ 7 files changed, 236 insertions(+), 5 deletions(-) create mode 100644 public/site_assets/bootstrap/js/plugins/date.format.js create mode 100644 templates/bootstrap/dashboard/blocks/default.tpl diff --git a/include/pages/api/getdashboarddata.inc.php b/include/pages/api/getdashboarddata.inc.php index b4b3575b..b351ec64 100644 --- a/include/pages/api/getdashboarddata.inc.php +++ b/include/pages/api/getdashboarddata.inc.php @@ -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, diff --git a/include/pages/dashboard.inc.php b/include/pages/dashboard.inc.php index 7047cfb8..c0ac2403 100644 --- a/include/pages/dashboard.inc.php +++ b/include/pages/dashboard.inc.php @@ -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)); diff --git a/include/pages/statistics/blocks.inc.php b/include/pages/statistics/blocks.inc.php index 90ea8425..3fd0d616 100644 --- a/include/pages/statistics/blocks.inc.php +++ b/include/pages/statistics/blocks.inc.php @@ -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)); diff --git a/public/site_assets/bootstrap/js/plugins/date.format.js b/public/site_assets/bootstrap/js/plugins/date.format.js new file mode 100644 index 00000000..3992c50f --- /dev/null +++ b/public/site_assets/bootstrap/js/plugins/date.format.js @@ -0,0 +1,126 @@ +/* + * Date Format 1.2.3 + * (c) 2007-2009 Steven Levithan + * MIT license + * + * Includes enhancements by Scott Trenda + * and 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); +}; + diff --git a/templates/bootstrap/dashboard/blocks/default.tpl b/templates/bootstrap/dashboard/blocks/default.tpl new file mode 100644 index 00000000..46467cd6 --- /dev/null +++ b/templates/bootstrap/dashboard/blocks/default.tpl @@ -0,0 +1,42 @@ +{if !$DISABLED_DASHBOARD and !$DISABLED_DASHBOARD_API} +
+
+
+

Last Found Blocks

+
+
+ + + + + + + + + + + + + + +{section block $BLOCKSFOUND} + + + + + + + + + + +{/section} + +
HeightFinderTimeDifficultyAmountExpected SharesActual SharesPercentage
{$BLOCKSFOUND[block].height}{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:$GLOBAL.config.date}{$BLOCKSFOUND[block].difficulty|number_format:"4"}{$BLOCKSFOUND[block].amount|number_format:"2"}{$BLOCKSFOUND[block].estshares|number_format}{$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"} +
+
+
+
+{/if} diff --git a/templates/bootstrap/dashboard/default.tpl b/templates/bootstrap/dashboard/default.tpl index 16bd9cd6..78d9781c 100644 --- a/templates/bootstrap/dashboard/default.tpl +++ b/templates/bootstrap/dashboard/default.tpl @@ -1,4 +1,5 @@ {if $smarty.session.AUTHENTICATED|default} +
@@ -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"}
diff --git a/templates/bootstrap/dashboard/js/api.tpl b/templates/bootstrap/dashboard/js/api.tpl index fa8d7253..a384a980 100644 --- a/templates/bootstrap/dashboard/js/api.tpl +++ b/templates/bootstrap/dashboard/js/api.tpl @@ -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('Total' + number_format(totalHashrate, 2) + ''); } } + 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 = ''; + for (index = 0; index < blocks.length; ++index) { + console.log(blocks[index]); + var time = new Date.UTC(blocks[index].time * 1000) + var table_row = ''; + table_row += '' + blocks[index].height + ''; + table_row += '' + blocks[index].finder + ''; + table_row += '' + time.format("mm/dd/yy HH:MM:ss") + ''; + table_row += '' + blocks[index].difficulty + ''; + table_row += '' + blocks[index].amount + ''; + table_row += '' + blocks[index].estshares + ''; + table_row += '' + blocks[index].shares + ''; + percentage = parseFloat(blocks[index].shares / blocks[index].estshares * 100).toFixed(2); + if (percentage <= 100) { + color = 'green'; + } else { + color = 'red'; + } + table_row += '' + percentage + ''; + table_row += ''; + table_content += table_row; + } + table_content += ''; + $("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})