From 5ac1f302baf24d7d976fd526dbc1ffb794e12b92 Mon Sep 17 00:00:00 2001 From: cubedro Date: Tue, 4 Aug 2015 13:24:01 +0300 Subject: [PATCH] fixed total difficulty display --- src/js/filters.js | 33 +++++++++++++++++++++++++++++++++ src/views/index.jade | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/js/filters.js b/src/js/filters.js index 5c56a54..db0e31b 100644 --- a/src/js/filters.js +++ b/src/js/filters.js @@ -93,6 +93,39 @@ angular.module('netStatsApp.filters', []) return $sce.trustAsHtml('' + filter('number')(result.toFixed(1)) + ' ' + unit + 'H/s'); }; }]) +.filter('totalDifficultyFilter', function() { + return function(hashes) { + var result = 0; + var unit = ''; + + 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 result.toFixed(2) + ' ' + unit + 'H'; + }; +}) .filter('nodeVersion', function($sce) { return function(version) { if(typeof version !== 'undefined') diff --git a/src/views/index.jade b/src/views/index.jade index 42a87d9..9c0b0c5 100644 --- a/src/views/index.jade +++ b/src/views/index.jade @@ -53,7 +53,7 @@ block content div.big-details-holder span.small-title difficulty span.big-details - span.small-hash {{ lastDifficulty | number }} + span.small-hash {{ lastDifficulty | totalDifficultyFilter }} div.clearfix div.clearfix