improved arrival time

This commit is contained in:
cubedro
2015-03-27 11:44:07 +02:00
parent 51ab249429
commit 7d0994dc24
6 changed files with 23 additions and 14 deletions

View File

@@ -23,9 +23,7 @@ Collection.prototype.update = function(id, stats)
if(!node)
return false;
node.stats = stats;
return node.getStats();
return node.setStats(stats);
}
Collection.prototype.inactive = function(id)

View File

@@ -18,7 +18,8 @@ var Node = function Node(data)
gasLimit: 0,
timestamp: 0,
arrival: 0,
propagation: 0
propagation: 0,
received: 0
},
blocktimeAvg: 0,
blockTimes: [],
@@ -72,6 +73,24 @@ Node.prototype.getInfo = function()
return {id: this.id, info: this.info, geo: this.geo, stats: this.stats};
}
Node.prototype.setStats = function(stats)
{
if(typeof stats !== undefined && typeof stats.block !== undefined && typeof stats.block.number !== undefined)
{
if(stats.block.number !== this.stats.number){
stats.block.received == (new Date()).getTime() - stats.block.arrival;
} else {
stats.block.received = this.stats.block.received;
}
this.stats = stats;
return this.getStats();
}
return false;
}
Node.prototype.getStats = function()
{
return {id: this.id, stats: this.stats};