From c83ed0704940b9e712eef1deaff7108c1444e864 Mon Sep 17 00:00:00 2001 From: joshuayabut Date: Mon, 26 Dec 2016 00:35:40 +0000 Subject: [PATCH] fixup! Bugfix: Hashrate incorrect --- libs/stats.js | 14 ++++++-------- website/static/stats.js | 12 ++++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/libs/stats.js b/libs/stats.js index 889f217..3fe468d 100644 --- a/libs/stats.js +++ b/libs/stats.js @@ -271,14 +271,12 @@ module.exports = function(logger, portalConfig, poolConfigs){ }; this.getReadableHashRateString = function(hashrate){ - var i = -1; - var byteUnits = [ ' Sol',' KSol', ' MSol', ' GSol', ' TSol', ' PSol' ]; - do { - hashrate = (hashrate * 2) / 1000000; - i++; - } while (hashrate > 1000); - + if (hashrate === 0) + return '0 Sol'; + var byteUnits = [ ' Sol', ' KSol', ' MSol', ' GSol', ' TSol', ' PSol' ]; + hashrate = (hashrate * 2); + var i = Math.floor((Math.log(hashrate/1000) / Math.log(1000)) - 1); + hashrate = (hashrate/1000) / Math.pow(1000, i + 1); return hashrate.toFixed(2) + byteUnits[i]; }; - }; diff --git a/website/static/stats.js b/website/static/stats.js index b4a5ec0..8337f0c 100644 --- a/website/static/stats.js +++ b/website/static/stats.js @@ -69,12 +69,12 @@ function buildChartData(){ } function getReadableHashRateString(hashrate){ - var i = -1; - var byteUnits = [ ' Sol',' KSol', ' MSol', ' GSol', ' TSol', ' PSol' ]; - do { - hashrate = (hashrate * 2) / 1000000; - i++; - } while (hashrate > 1000); + if (hashrate === 0) + return '0 Sol'; + var byteUnits = [ ' Sol', ' KSol', ' MSol', ' GSol', ' TSol', ' PSol' ]; + hashrate = (hashrate * 2); + var i = Math.floor((Math.log(hashrate/1000) / Math.log(1000)) - 1); + hashrate = (hashrate/1000) / Math.pow(1000, i + 1); return Math.round(hashrate) + byteUnits[i]; }