added human readable auto-scaling hash rate strings to stats

This commit is contained in:
Jerry Brady 2014-04-02 23:36:36 +00:00
parent df5ed6d29b
commit 5918baac2f
1 changed files with 26 additions and 9 deletions

View File

@ -144,7 +144,8 @@ module.exports = function(logger, portalConfig, poolConfigs){
if (!portalStats.algos.hasOwnProperty(algo)){
portalStats.algos[algo] = {
workers: 0,
hashrate: 0
hashrate: 0,
hashrateString: null
};
}
portalStats.algos[algo].hashrate += coinStats.hashrate;
@ -152,6 +153,11 @@ module.exports = function(logger, portalConfig, poolConfigs){
delete coinStats.hashrates;
delete coinStats.shares;
coinStats.hashrateString = _this.getReadableHashRateString(coinStats.hashrate);
});
Object.keys(portalStats.algos).forEach(function(algo){
algo.hashrateString = _this.getReadableHashRateString(algo.hashrate);
});
_this.stats = portalStats;
@ -160,5 +166,16 @@ module.exports = function(logger, portalConfig, poolConfigs){
});
};
this.getReadableHashRateString = function(hashrate){
var i = -1;
var byteUnits = [' KH', ' MH', ' GH', ' TH', 'PH' ];
do {
hashrate = hashrate / 1024;
i++;
} while (hashrate > 1024);
return hashrate.toFixed(2) + byteUnits[i];
};
};