From df878576927048c2280b4b04f18bf8fd4bf86ce1 Mon Sep 17 00:00:00 2001 From: cubedro Date: Wed, 29 Apr 2015 13:14:18 +0300 Subject: [PATCH] added hashrate filter --- public/css/style.css | 4 ++++ public/js/controllers.js | 7 ++++--- public/js/filters.js | 33 ++++++++++++++++++++------------- views/index.jade | 5 +++-- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/public/css/style.css b/public/css/style.css index be8cefe..9dbb794 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -133,6 +133,10 @@ span.small-title span.small { word-spacing: nowrap !important; } +.big-info .big-details .small-hash { + font-size: 87%; +} + .big-info .big-details-holder { position: absolute; top: 15px; diff --git a/public/js/controllers.js b/public/js/controllers.js index 6accc8d..bd5d4d8 100644 --- a/public/js/controllers.js +++ b/public/js/controllers.js @@ -178,7 +178,7 @@ function StatsCtrl($scope, $filter, socket, _, toastr) { break; case "inactive": - if(typeof data.stats !== 'undefined') + if( !_.isUndefined(data.stats) ) $scope.nodes[findIndex({id: data.id})].stats = data.stats; toastr['error']("Node "+ $scope.nodes[findIndex({id: data.id})].info.name +" went away!", "Node connection was lost!"); @@ -186,9 +186,10 @@ function StatsCtrl($scope, $filter, socket, _, toastr) { break; case "latency": - var node = $scope.nodes[findIndex({id: data.id})]; + if( !_.isUndefined(data.id) ) + var node = $scope.nodes[findIndex({id: data.id})]; - if(typeof node.stats !== 'undefined' && typeof node.stats.latency !== 'undefined') + if( !_.isUndefined(node) && !_.isUndefined(node.stats) && !_.isUndefined(node.stats.latency)) $scope.nodes[findIndex({id: data.id})].stats.latency = data.latency; break; diff --git a/public/js/filters.js b/public/js/filters.js index 3e2149d..1964a4b 100644 --- a/public/js/filters.js +++ b/public/js/filters.js @@ -231,35 +231,42 @@ angular.module('netStatsApp.filters', []) return moment.duration(Math.round(diff), 's').humanize() + ' ago'; }; }) -.filter('networkHashrateFilter', function($sce) { - return function(hashes) { +.filter('networkHashrateFilter', ['$sce', '$filter', function($sce, filter) { + return function(hashes, isMining) { var result = 0; + var unit = 'K'; - if(hashes < 1000) { - return $sce.trustAsHtml(result.toFixed(1) + ' H/s'); + if(hashes !== 0 && hashes < 1000) { + result = hashes; + unit = ''; } - if(hashes < Math.pow(1000, 2)) { + if(hashes >= 1000 && hashes < Math.pow(1000, 2)) { result = hashes / 1000; - return $sce.trustAsHtml(result.toFixed(1) + ' KH/s'); + unit = 'K'; } - if(hashes < Math.pow(1000, 3)) { + if(hashes >= Math.pow(1000, 2) && hashes < Math.pow(1000, 3)) { result = hashes / Math.pow(1000, 2); - return $sce.trustAsHtml(result.toFixed(1) + ' MH/s'); + unit = 'M'; } - if(hashes < Math.pow(1000, 4)) { + if(hashes >= Math.pow(1000, 3) && hashes < Math.pow(1000, 4)) { result = hashes / Math.pow(1000, 3); - return $sce.trustAsHtml(result.toFixed(1) + ' GH/s'); + unit = 'G'; } - if(hashes < Math.pow(1000, 5)) { + if(hashes >= Math.pow(1000, 4) && hashes < Math.pow(1000, 5)) { result = hashes / Math.pow(1000, 4); - return $sce.trustAsHtml(result.toFixed(1) + ' TH/s'); + unit = 'T'; } + + if( !isMining ) + return $sce.trustAsHtml(filter('number')(result.toFixed(1)) + ' ' + unit + 'H/s'); + + return $sce.trustAsHtml('? ' + unit + 'KH/s'); }; -}) +}]) .filter('blockPropagationFilter', function() { return function(ms, prefix) { if(typeof prefix === 'undefined') diff --git a/views/index.jade b/views/index.jade index f5f4360..5be106f 100644 --- a/views/index.jade +++ b/views/index.jade @@ -104,7 +104,7 @@ block content div.big-info.chart.xdouble-chart(class="{{ blockPropagationAvg | propagationAvgTimeClass : true }}") //- i.icon-gas span.small-title block propagation - span.small-value {{ blockPropagationAvg | blockPropagationFilter : '' }} + //- span.small-value {{ blockPropagationAvg | blockPropagationFilter : '' }} histogram.big-details.d3-blockpropagation(data="blockPropagationChart") div.col-xs-3.stat-holder.pull-right @@ -192,7 +192,8 @@ block content 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 {{node.stats.hashrate | hashrateFilter}} kH/s + span.small(ng-bind-html="node.stats.hashrate | networkHashrateFilter") + //- {{node.stats.hashrate | hashrateFilter}} kH/s 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 }}