Merge pull request #39 from cubedro/develop

Moved popagation to backend fixes #38
pull/5/head
Marian OANCΞA 10 years ago
commit 391c0269e2
  1. 30
      models/collection.js
  2. 11
      models/node.js
  3. 10
      public/js/controllers.js
  4. 7
      public/js/filters.js
  5. 2
      views/index.jade

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

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

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

@ -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) {

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

Loading…
Cancel
Save