From 80ec2e8bca2663b3df046569c9cb50a90f1b910c Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 20 Mar 2014 00:43:15 -0600 Subject: [PATCH] Fixed hashrate calculation by adding share multiplier per algo --- config.json | 2 +- libs/stats.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/config.json b/config.json index f602d64..ec88df7 100644 --- a/config.json +++ b/config.json @@ -20,7 +20,7 @@ "enabled": true, "siteTitle": "Cryppit", "port": 80, - "statUpdateInterval": 5, + "statUpdateInterval": 3, "hashrateWindow": 600 }, "proxy": { diff --git a/libs/stats.js b/libs/stats.js index b650cb9..7a6d491 100644 --- a/libs/stats.js +++ b/libs/stats.js @@ -10,6 +10,11 @@ module.exports = function(logger, portalConfig, poolConfigs){ var redisClients = []; + var algoMultipliers = { + 'scrypt': Math.pow(2, 16), + 'sha256': Math.pow(2, 32) + }; + Object.keys(poolConfigs).forEach(function(coin){ var poolConfig = poolConfigs[coin]; var internalConfig = poolConfig.shareProcessing.internal; @@ -37,13 +42,13 @@ module.exports = function(logger, portalConfig, poolConfigs){ var allCoinStats = []; async.each(redisClients, function(client, callback){ - var windowTime = (Date.now() / 1000 | 0) - portalConfig.website.hashrateWindow; + var windowTime = (((Date.now() / 1000) - portalConfig.website.hashrateWindow) | 0).toString(); var redisCommands = []; var commandsPerCoin = 4; //Clear out old hashrate stats for each coin from redis client.coins.forEach(function(coin){ - redisCommands.push(['zremrangebyscore', coin + '_hashrate', '-inf', windowTime]); + redisCommands.push(['zremrangebyscore', coin + '_hashrate', '-inf', '(' + windowTime]); redisCommands.push(['zrangebyscore', coin + '_hashrate', windowTime, '+inf']); redisCommands.push(['hgetall', coin + '_stats']); redisCommands.push(['scard', coin + '_blocks']); @@ -97,7 +102,9 @@ module.exports = function(logger, portalConfig, poolConfigs){ else coinStats.workers[worker] = workerShares }); - coinStats.hashrate = (coinStats.shares * 4294967296 / portalConfig.website.hashrateWindow) / 100000000 | 0; + var shareMultiplier = algoMultipliers[poolConfigs[coinStats.coinName].coin.algorithm]; + var hashratePre = shareMultiplier * coinStats.shares / portalConfig.website.hashrateWindow; + coinStats.hashrate = hashratePre / 1e3 | 0; delete coinStats.hashrates; portalStats.global.hashrate += coinStats.hashrate; portalStats.global.workers += Object.keys(coinStats.workers).length;