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};

View File

@ -5,7 +5,7 @@
"private": true,
"engines": {
"node": "0.12.0",
"npm": "2.5.0"
"npm": "2.5.1"
},
"scripts": {
"start": "node ./bin/www"

View File

@ -69,13 +69,6 @@ function StatsCtrl($scope, $filter, socket, _, toastr) {
break;
case "update":
if(typeof $scope.nodes[findIndex({id: data.id})].stats !== 'undefined' && typeof $scope.nodes[findIndex({id: data.id})].stats.block !== 'undefined'){
if($scope.nodes[findIndex({id: data.id})].stats.block.number != data.stats.block.number){
data.stats.block.when = (new Date()).getTime() - data.stats.block.arrival;
} else {
data.stats.block.when = $scope.nodes[findIndex({id: data.id})].stats.block.when;
}
}
$scope.nodes[findIndex({id: data.id})].stats = data.stats;
break;

View File

@ -116,7 +116,6 @@ angular.module('netStatsApp.filters', [])
})
.filter('blockPropagationFilter', function() {
return function(ms) {
// ms = (new Date()).getTime() - ms;
var result = 0;
if(ms < 1000) {

View File

@ -128,5 +128,5 @@ block content
//- div.small Difficulty: {{node.stats.block.difficulty | gasFilter}} | Gas used: {{node.stats.block.gasUsed | gasFilter}} | Min gas price: {{node.stats.block.minGasPrice | gasFilter}} | Gas limit: {{node.stats.block.gasLimit | gasFilter}}
td(style="padding-left: 18px;") {{node.stats.block.txCount}}
td(class="{{ node.stats.block.timestamp | timeClass }}") {{node.stats.block.timestamp | blockTimeFilter }}
td(class="{{ node.stats.block.when | propagationTimeClass }}") {{node.stats.block.when | blockPropagationFilter}}
td(class="{{ node.stats.block.received | propagationTimeClass }}") {{node.stats.block.received | blockPropagationFilter}}
td(class="{{ node.stats.uptime | upTimeClass }}") {{ node.stats.uptime | upTimeFilter }}