diff --git a/src-lite/js/filters.js b/src-lite/js/filters.js
index c4aaed5..6ab886e 100644
--- a/src-lite/js/filters.js
+++ b/src-lite/js/filters.js
@@ -38,35 +38,17 @@ angular.module('netStatsApp.filters', [])
})
.filter('hashrateFilter', ['$sce', '$filter', function($sce, filter) {
return function(hashes, isMining) {
- var result = 0;
- var unit = 'K';
-
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';
- }
+ var result = hashes;
+ var units = ['', 'K', 'M', 'G', 'T', 'P'];
+ var unit = 'K';
- if(hashes >= Math.pow(1000, 4) && hashes < Math.pow(1000, 5)) {
- result = hashes / Math.pow(1000, 4);
- unit = 'T';
+ for(var i = 1; result > 1000; i++)
+ {
+ result /= 1000;
+ unit = units[i];
}
return $sce.trustAsHtml('' + filter('number')(result.toFixed(1)) + ' ' + unit + 'H/s');
@@ -273,32 +255,14 @@ angular.module('netStatsApp.filters', [])
if(hashes === null)
hashes = 0;
- var result = 0;
+ var result = hashes;
+ var units = ['', 'K', 'M', 'G', 'T', 'P'];
var unit = 'K';
- 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';
+ for(var i = 1; result > 1000; i++)
+ {
+ result /= 1000;
+ unit = units[i];
}
if( !isMining )
diff --git a/src/js/filters.js b/src/js/filters.js
index 40be828..cfd3eec 100644
--- a/src/js/filters.js
+++ b/src/js/filters.js
@@ -59,35 +59,17 @@ angular.module('netStatsApp.filters', [])
})
.filter('hashrateFilter', ['$sce', '$filter', function($sce, filter) {
return function(hashes, isMining) {
- var result = 0;
- var unit = 'K';
-
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';
- }
+ var result = hashes;
+ var units = ['', 'K', 'M', 'G', 'T', 'P'];
+ var unit = 'K';
- if(hashes >= Math.pow(1000, 4) && hashes < Math.pow(1000, 5)) {
- result = hashes / Math.pow(1000, 4);
- unit = 'T';
+ for(var i = 1; result > 1000; i++)
+ {
+ result /= 1000;
+ unit = units[i];
}
return $sce.trustAsHtml('' + filter('number')(result.toFixed(1)) + ' ' + unit + 'H/s');
@@ -95,32 +77,14 @@ angular.module('netStatsApp.filters', [])
}])
.filter('totalDifficultyFilter', function() {
return function(hashes) {
- var result = 0;
+ var result = hashes;
+ var units = ['', 'K', 'M', 'G', 'T', 'P'];
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';
+ for(var i = 1; result > 1000; i++)
+ {
+ result /= 1000;
+ unit = units[i];
}
return result.toFixed(2) + ' ' + unit + 'H';
@@ -327,32 +291,14 @@ angular.module('netStatsApp.filters', [])
if(hashes === null)
hashes = 0;
- var result = 0;
+ var result = hashes;
+ var units = ['', 'K', 'M', 'G', 'T', 'P'];
var unit = 'K';
- 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';
+ for(var i = 1; result > 1000; i++)
+ {
+ result /= 1000;
+ unit = units[i];
}
if( !isMining )