From 7f2f722d5dc2b461954ad70368c49df1c602e42f Mon Sep 17 00:00:00 2001 From: cubedro Date: Mon, 6 Apr 2015 02:20:14 +0300 Subject: [PATCH] added miners chart --- lib/node.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/node.js b/lib/node.js index 446101b..c3ca9fa 100644 --- a/lib/node.js +++ b/lib/node.js @@ -76,6 +76,7 @@ function Node() txDensity: [], blockTimes: [], gasSpending: [], + miners: [], uptime: 0, errors: [] }; @@ -235,6 +236,7 @@ Node.prototype.getLatestBlocks = function() this.stats.difficulty = this.difficultyChart(); this.stats.txDensity = this.txDensityChart(); this.stats.gasSpending = this.gasSpendingChart(); + this.stats.miners = this.minersChart(); } Node.prototype.addBlockHistory = function(block) @@ -297,6 +299,22 @@ Node.prototype.gasSpendingChart = function() }); } +Node.prototype.minersChart = function() +{ + var miners = _.countBy(this.blocks, function(block) + { + return block.miner; + }); + + var minersArray = []; + + _.forEach(miners, function(cnt, miner) { + minersArray.push({miner: miner, blocks: cnt}); + }); + + return _.sortBy(minersArray, 'blocks').reverse(); +} + Node.prototype.uptime = function() { this.stats.uptime = ((this._tries - this._down) / this._tries) * 100;