Merge pull request #136 from cubedro/develop

Improved nodes propagation chart & avg
This commit is contained in:
Marian OANCΞA 2015-05-19 08:35:14 +03:00
commit d3c6e79205
7 changed files with 70 additions and 12 deletions

2
dist/index.html vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -158,22 +158,33 @@ History.prototype.getNodePropagation = function(id)
{ {
var propagation = new Array( MAX_PEER_PROPAGATION ); var propagation = new Array( MAX_PEER_PROPAGATION );
var bestBlock = this.bestBlockNumber(); var bestBlock = this.bestBlockNumber();
var lastBlocktime = _.now();
_.fill(propagation, -1); _.fill(propagation, -1);
var sorted = _( this._items ) var sorted = _( this._items )
.sortByOrder( 'height', false ) .sortByOrder( 'height', false )
.slice( 0, MAX_PEER_PROPAGATION ) .slice( 0, MAX_PEER_PROPAGATION )
.reverse()
.forEach(function (item, key) .forEach(function (item, key)
{ {
var index = MAX_PEER_PROPAGATION - 1 - bestBlock + item.height; var index = MAX_PEER_PROPAGATION - 1 - bestBlock + item.height;
if(index > 0) if(index >= 0)
{ {
propagation[index] = _.result(_.find(item.propagTimes, 'node', id), 'propagation', -1); var tmpPropagation = _.result(_.find(item.propagTimes, 'node', id), 'propagation', false);
if (_.result(_.find(item.propagTimes, 'node', id), 'propagation', false) !== false)
{
propagation[index] = tmpPropagation;
lastBlocktime = item.block.arrived;
}
else
{
propagation[index] = Math.max(0, lastBlocktime - item.block.arrived);
}
} }
}) })
.reverse()
.value(); .value();
return propagation; return propagation;

View File

@ -110,11 +110,17 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
switch(action) { switch(action) {
case "init": case "init":
var oldNodes = [];
if( $scope.nodes.length > 0 ){
oldNodes = $scope.nodes;
}
$scope.nodes = data; $scope.nodes = data;
_.forEach($scope.nodes, function(node, index) { _.forEach($scope.nodes, function(node, index) {
// Init hashrate // Init hashrate
if(typeof node.stats.hashrate === 'undefined') if( _.isUndefined(node.stats.hashrate) )
$scope.nodes[index].stats.hashrate = 0; $scope.nodes[index].stats.hashrate = 0;
// Init history // Init history
@ -124,8 +130,8 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
_.fill(data.history, -1); _.fill(data.history, -1);
} }
// Init pin // Init or recover pin
$scope.nodes[index].pinned = false; $scope.nodes[index].pinned = _.result(_.find(oldNodes, 'id', node.id), 'pinned', false);
$scope.$apply(); $scope.$apply();
@ -271,7 +277,7 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
height: 20, height: 20,
barWidth : 2, barWidth : 2,
barSpacing : 1, barSpacing : 1,
tooltipSuffix: ' ms', tooltipSuffix: '',
chartRangeMax: 8000, chartRangeMax: 8000,
colorMap: jQuery.range_map({ colorMap: jQuery.range_map({
'0:1': '#10a0de', '0:1': '#10a0de',
@ -279,7 +285,14 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
'1001:3000': '#FFD162', '1001:3000': '#FFD162',
'3001:7000': '#ff8a00', '3001:7000': '#ff8a00',
'7001:': '#F74B4B' '7001:': '#F74B4B'
}) }),
tooltipFormatter: function (spark, opt, ms) {
var tooltip = '<div class="tooltip-arrow"></div><div class="tooltip-inner">';
tooltip += $filter('blockPropagationFilter')(ms[0].value, '');
tooltip += '</div>';
return tooltip;
}
}); });
} }

View File

@ -356,6 +356,40 @@ angular.module('netStatsApp.filters', [])
return prefix + Math.round(result) + " days"; return prefix + Math.round(result) + " days";
}; };
}) })
.filter('blockPropagationAvgFilter', function() {
return function(stats, bestBlock) {
var ms = stats.propagationAvg;
if(bestBlock - stats.block.number > 40)
ms = _.now() - stats.block.received;
prefix = '';
var result = 0;
if(ms < 1000) {
return (ms === 0 ? "" : prefix) + ms + " ms";
}
if(ms < 1000*60) {
result = ms/1000;
return prefix + result.toFixed(1) + " s";
}
if(ms < 1000*60*60) {
result = ms/1000/60;
return prefix + Math.round(result) + " min";
}
if(ms < 1000*60*60*24) {
result = ms/1000/60/60;
return prefix + Math.round(result) + " h";
}
result = ms/1000/60/60/24;
return prefix + Math.round(result) + " days";
};
})
.filter('avgTimeFilter', function() { .filter('avgTimeFilter', function() {
return function(time) { return function(time) {
if(time < 60) if(time < 60)

View File

@ -209,5 +209,5 @@ block content
div.propagationBox div.propagationBox
span {{node.stats.block.propagation | blockPropagationFilter}} span {{node.stats.block.propagation | blockPropagationFilter}}
td.peerPropagationChart(class="{{node.id}}") td.peerPropagationChart(class="{{node.id}}")
td(class="{{ node.stats | propagationNodeAvgTimeClass : bestBlock }}") {{ node.stats.propagationAvg | blockPropagationFilter : '' }} td(class="{{ node.stats | propagationNodeAvgTimeClass : bestBlock }}") {{ node.stats | blockPropagationAvgFilter : bestBlock }}
td(class="{{ node.stats.uptime | upTimeClass : node.stats.active }}") {{ node.stats.uptime | upTimeFilter }} td(class="{{ node.stats.uptime | upTimeClass : node.stats.active }}") {{ node.stats.uptime | upTimeFilter }}