From 3a813723297186dc699753f11f9a86fca87c3dd5 Mon Sep 17 00:00:00 2001 From: cubedro Date: Wed, 29 Apr 2015 12:39:51 +0300 Subject: [PATCH] added hashrate units --- models/history.js | 4 ++-- public/js/filters.js | 29 +++++++++++++++++++++++++++++ views/index.jade | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/models/history.js b/models/history.js index a075df9..26fa9ed 100644 --- a/models/history.js +++ b/models/history.js @@ -334,9 +334,9 @@ History.prototype.getAvgHashrate = function() }) .value(); - var avgBlocktime = _.sum(blocktimeHistory) / blocktimeHistory.length; + var avgBlocktime = (_.sum(blocktimeHistory) / blocktimeHistory.length)/1000; - return avgDifficulty / 1000 * 12 * ( 12 / avgBlocktime ); + return avgDifficulty * 12 * ( 12 / avgBlocktime ); } History.prototype.getMinersCount = function() diff --git a/public/js/filters.js b/public/js/filters.js index abae0c9..3e2149d 100644 --- a/public/js/filters.js +++ b/public/js/filters.js @@ -231,6 +231,35 @@ angular.module('netStatsApp.filters', []) return moment.duration(Math.round(diff), 's').humanize() + ' ago'; }; }) +.filter('networkHashrateFilter', function($sce) { + return function(hashes) { + var result = 0; + + if(hashes < 1000) { + return $sce.trustAsHtml(result.toFixed(1) + ' H/s'); + } + + if(hashes < Math.pow(1000, 2)) { + result = hashes / 1000; + return $sce.trustAsHtml(result.toFixed(1) + ' KH/s'); + } + + if(hashes < Math.pow(1000, 3)) { + result = hashes / Math.pow(1000, 2); + return $sce.trustAsHtml(result.toFixed(1) + ' MH/s'); + } + + if(hashes < Math.pow(1000, 4)) { + result = hashes / Math.pow(1000, 3); + return $sce.trustAsHtml(result.toFixed(1) + ' GH/s'); + } + + if(hashes < Math.pow(1000, 5)) { + result = hashes / Math.pow(1000, 4); + return $sce.trustAsHtml(result.toFixed(1) + ' TH/s'); + } + }; +}) .filter('blockPropagationFilter', function() { return function(ms, prefix) { if(typeof prefix === 'undefined') diff --git a/views/index.jade b/views/index.jade index 3a24542..f5f4360 100644 --- a/views/index.jade +++ b/views/index.jade @@ -42,7 +42,7 @@ block content i.icon-hashrate div.big-details-holder span.small-title avg network hashrate - span.big-details {{ avgHashrate | number : 1 }} MH/s + span.big-details(ng-bind-html="avgHashrate | networkHashrateFilter") div.clearfix div.col-xs-2.stat-holder div.big-info.difficulty.text-danger