added stats as different method

This commit is contained in:
cubedro
2015-06-02 00:04:34 +03:00
parent 0925b738b9
commit 28447d6c43
6 changed files with 83 additions and 5 deletions

View File

@@ -70,6 +70,16 @@ Collection.prototype.updatePending = function(id, stats)
return node.setPending(stats);
}
Collection.prototype.updateStats = function(id, stats)
{
var node = this.getNode({ id: id });
if (!node)
return false;
return node.setBasicStats(stats);
}
Collection.prototype.addHistory = function(id, blocks)
{
var node = this.getNode({ id: id });

View File

@@ -11,8 +11,8 @@ var Node = function Node(data)
this.geo = {}
this.stats = {
active: false,
listening: false,
mining: false,
hashrate: 0,
peers: 0,
pending: 0,
gasPrice: 0,
@@ -181,6 +181,23 @@ Node.prototype.setPending = function(stats)
return false;
}
Node.prototype.setBasicStats = function(stats)
{
if( !_.isUndefined(stats) )
{
this.stats.active = stats.active;
this.stats.mining = stats.mining;
this.stats.hashrate = stats.hashrate;
this.stats.peers = stats.peers;
this.stats.gasPrice = stats.gasPrice;
this.stats.uptime = stats.uptime;
return this.getBasicStats();
}
return false;
}
Node.prototype.setLatency = function(latency)
{
if( !_.isUndefined(latency) )
@@ -215,6 +232,21 @@ Node.prototype.getBlockStats = function()
};
}
Node.prototype.getBasicStats = function()
{
return {
id: this.id,
stats: {
active: this.stats.active,
mining: this.stats.mining,
hashrate: this.stats.hashrate,
peers: this.stats.peers,
gasPrice: this.stats.gasPrice,
uptime: this.stats.uptime
}
};
}
Node.prototype.setState = function(active)
{
this.stats.active = active;