moved popagation to backend fixes #38

This commit is contained in:
cubedro 2015-04-05 00:59:24 +03:00
parent 19646a71a7
commit ff5d8bd31a
5 changed files with 44 additions and 16 deletions

View File

@ -4,6 +4,7 @@ var Node = require('./node');
var Collection = function Collection() var Collection = function Collection()
{ {
this._list = []; this._list = [];
this._bestBlock = null;
return this; return this;
} }
@ -23,6 +24,35 @@ Collection.prototype.update = function(id, stats)
if(!node) if(!node)
return false; return false;
if(this._bestBlock === null)
{
stats.block.received = (new Date()).getTime();
stats.block.propagation = 0;
this._bestBlock = stats.block;
}
else
{
var oldStats = node.getStats();
if(stats.block.number !== oldStats.stats.block.number)
{
stats.block.received = (new Date()).getTime();
if(this._bestBlock.number < oldStats.stats.block.number)
{
stats.block.propagation = 0;
this._bestBlock = stats.block;
}
else
{
stats.block.propagation = stats.block.received - this._bestBlock.received;
}
} else {
stats.block.received = oldStats.stats.block.received;
stats.block.propagation = oldStats.stats.block.propagation;
}
}
return node.setStats(stats); return node.setStats(stats);
} }

View File

@ -90,11 +90,12 @@ Node.prototype.setStats = function(stats)
{ {
if(typeof stats !== 'undefined' && typeof stats.block !== 'undefined' && typeof stats.block.number !== 'undefined') if(typeof stats !== 'undefined' && typeof stats.block !== 'undefined' && typeof stats.block.number !== 'undefined')
{ {
if(stats.block.number !== this.stats.block.number) { // if(stats.block.number !== this.stats.block.number) {
stats.block.received = (new Date()).getTime(); // stats.block.received = (new Date()).getTime();
} else { // } else {
stats.block.received = this.stats.block.received; // stats.block.received = this.stats.block.received;
} // }
stats.block.hash = stats.block.hash.replace('0x', '');
this.stats = stats; this.stats = stats;

View File

@ -76,11 +76,11 @@ function StatsCtrl($scope, $filter, socket, _, toastr) {
case "update": case "update":
var index = findIndex({id: data.id}); var index = findIndex({id: data.id});
if(data.stats.block.number > $scope.nodes[index].stats.block.number) { // if(data.stats.block.number > $scope.nodes[index].stats.block.number) {
data.stats.block.firstarrived = (data.stats.block.number > $scope.bestBlock ? data.stats.block.received : $scope.lastBlock); // data.stats.block.firstarrived = (data.stats.block.number > $scope.bestBlock ? data.stats.block.received : $scope.lastBlock);
} else { // } else {
data.stats.block.firstarrived = $scope.nodes[index].stats.block.firstarrived; // data.stats.block.firstarrived = $scope.nodes[index].stats.block.firstarrived;
} // }
$scope.nodes[index].stats = data.stats; $scope.nodes[index].stats = data.stats;

View File

@ -75,9 +75,7 @@ angular.module('netStatsApp.filters', [])
}; };
}) })
.filter('propagationTimeClass', function() { .filter('propagationTimeClass', function() {
return function(arrival, best) { return function(propagation) {
var propagation = arrival - best;
if(propagation <= 3000) if(propagation <= 3000)
return 'text-success'; return 'text-success';
@ -125,8 +123,7 @@ angular.module('netStatsApp.filters', [])
}; };
}) })
.filter('blockPropagationFilter', function() { .filter('blockPropagationFilter', function() {
return function(arrival, best) { return function(ms) {
var ms = arrival - best;
var result = 0; var result = 0;
if(ms < 1000) { if(ms < 1000) {

View File

@ -140,5 +140,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}} //- 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.transactions.length || 0}} td(style="padding-left: 18px;") {{node.stats.block.transactions.length || 0}}
td(class="{{ node.stats.block.timestamp | timeClass }}") {{node.stats.block.received | blockTimeFilter }} td(class="{{ node.stats.block.timestamp | timeClass }}") {{node.stats.block.received | blockTimeFilter }}
td(class="{{ node.stats.block.received | propagationTimeClass : node.stats.block.firstarrived }}") {{node.stats.block.received | blockPropagationFilter : node.stats.block.firstarrived}} td(class="{{ node.stats.block.propagation | propagationTimeClass }}") {{node.stats.block.propagation | blockPropagationFilter}}
td(class="{{ node.stats.uptime | upTimeClass }}") {{ node.stats.uptime | upTimeFilter }} td(class="{{ node.stats.uptime | upTimeClass }}") {{ node.stats.uptime | upTimeFilter }}