From 2b956f2d612415efb1f7a478a0a8420566efa836 Mon Sep 17 00:00:00 2001 From: cubedro Date: Mon, 4 May 2015 17:27:37 +0300 Subject: [PATCH] joined mining and hashrate columns --- public/js/filters.js | 40 ++++++++++++++++++++++++++++++++++------ views/index.jade | 8 +------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/public/js/filters.js b/public/js/filters.js index 34a2bc9..8fc2811 100644 --- a/public/js/filters.js +++ b/public/js/filters.js @@ -50,13 +50,41 @@ angular.module('netStatsApp.filters', []) return 'text-success'; }; }) -.filter('hashrateFilter', ['$filter', function(filter) { - return function(hashrate) { - if(typeof hashrate === 'undefined' || !hashrate) - return 0; +.filter('hashrateFilter', ['$sce', '$filter', function($sce, filter) { + return function(hashes, isMining) { + var result = 0; + var unit = 'K'; - return filter('number')((hashrate/1000).toFixed(2)); - } + if( !isMining ) + return $sce.trustAsHtml(''); + + if(hashes !== 0 && hashes < 1000) { + result = hashes; + unit = ''; + } + + if(hashes >= 1000 && hashes < Math.pow(1000, 2)) { + result = hashes / 1000; + unit = 'K'; + } + + if(hashes >= Math.pow(1000, 2) && hashes < Math.pow(1000, 3)) { + result = hashes / Math.pow(1000, 2); + unit = 'M'; + } + + if(hashes >= Math.pow(1000, 3) && hashes < Math.pow(1000, 4)) { + result = hashes / Math.pow(1000, 3); + unit = 'G'; + } + + if(hashes >= Math.pow(1000, 4) && hashes < Math.pow(1000, 5)) { + result = hashes / Math.pow(1000, 4); + unit = 'T'; + } + + return $sce.trustAsHtml('' + filter('number')(result.toFixed(1)) + ' ' + unit + 'H/s'); + }; }]) .filter('nodeVersion', function($sce) { return function(version) { diff --git a/views/index.jade b/views/index.jade index 50f0a14..4a6fa95 100644 --- a/views/index.jade +++ b/views/index.jade @@ -156,8 +156,6 @@ block content i.icon-clock(data-toggle="tooltip", data-placement="top", title="Node latency", ng-click="orderTable(['-stats.active', 'stats.latency'], false)") th i.icon-mining(data-toggle="tooltip", data-placement="top", title="Is mining", ng-click="orderTable(['-stats.active', '-stats.mining'], false)") - th - i.icon-hashrate(data-toggle="tooltip", data-placement="top", title="Hashrate", ng-click="orderTable(['-stats.active', '-stats.mining', '-stats.hashrate'], false)") th i.icon-group(data-toggle="tooltip", data-placement="top", title="Peers", ng-click="orderTable(['-stats.active', '-stats.peers'], false)") th @@ -189,11 +187,7 @@ block content div.small(ng-bind-html="node.info.node | nodeVersion") td(class="{{ node.stats | latencyClass }}") span.small {{node.stats | latencyFilter}} - td(class="{{ node.stats.mining | miningClass : node.stats.active }}") - i(class="{{ node.stats.mining | miningIconClass }}") - td(class="{{ node.stats.mining | hashrateClass : node.stats.active }}") - span.small(ng-bind-html="node.stats.hashrate | networkHashrateFilter") - //- {{node.stats.hashrate | hashrateFilter}} kH/s + td(class="{{ node.stats.mining | hashrateClass : node.stats.active }}", ng-bind-html="node.stats.hashrate | hashrateFilter : node.stats.mining") td(class="{{ node.stats.peers | peerClass : node.stats.active }}", style="padding-left: 11px;") {{node.stats.peers}} td(style="padding-left: 15px;") {{node.stats.pending}} td(class="{{ node.stats | blockClass : bestBlock }}") {{'#'}}{{ node.stats.block.number | number }}