Merge pull request #136 from cubedro/develop
Improved nodes propagation chart & avg
This commit is contained in:
commit
d3c6e79205
2
dist/index.html
vendored
2
dist/index.html
vendored
File diff suppressed because one or more lines are too long
2
dist/js/netstats.min.js
vendored
2
dist/js/netstats.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/js/netstats.min.js.map
vendored
2
dist/js/netstats.min.js.map
vendored
File diff suppressed because one or more lines are too long
@ -158,22 +158,33 @@ History.prototype.getNodePropagation = function(id)
|
||||
{
|
||||
var propagation = new Array( MAX_PEER_PROPAGATION );
|
||||
var bestBlock = this.bestBlockNumber();
|
||||
var lastBlocktime = _.now();
|
||||
|
||||
_.fill(propagation, -1);
|
||||
|
||||
var sorted = _( this._items )
|
||||
.sortByOrder( 'height', false )
|
||||
.slice( 0, MAX_PEER_PROPAGATION )
|
||||
.reverse()
|
||||
.forEach(function (item, key)
|
||||
{
|
||||
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();
|
||||
|
||||
return propagation;
|
||||
|
@ -110,11 +110,17 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
|
||||
|
||||
switch(action) {
|
||||
case "init":
|
||||
var oldNodes = [];
|
||||
|
||||
if( $scope.nodes.length > 0 ){
|
||||
oldNodes = $scope.nodes;
|
||||
}
|
||||
|
||||
$scope.nodes = data;
|
||||
|
||||
_.forEach($scope.nodes, function(node, index) {
|
||||
// Init hashrate
|
||||
if(typeof node.stats.hashrate === 'undefined')
|
||||
if( _.isUndefined(node.stats.hashrate) )
|
||||
$scope.nodes[index].stats.hashrate = 0;
|
||||
|
||||
// Init history
|
||||
@ -124,8 +130,8 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
|
||||
_.fill(data.history, -1);
|
||||
}
|
||||
|
||||
// Init pin
|
||||
$scope.nodes[index].pinned = false;
|
||||
// Init or recover pin
|
||||
$scope.nodes[index].pinned = _.result(_.find(oldNodes, 'id', node.id), 'pinned', false);
|
||||
|
||||
$scope.$apply();
|
||||
|
||||
@ -271,7 +277,7 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
|
||||
height: 20,
|
||||
barWidth : 2,
|
||||
barSpacing : 1,
|
||||
tooltipSuffix: ' ms',
|
||||
tooltipSuffix: '',
|
||||
chartRangeMax: 8000,
|
||||
colorMap: jQuery.range_map({
|
||||
'0:1': '#10a0de',
|
||||
@ -279,7 +285,14 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
|
||||
'1001:3000': '#FFD162',
|
||||
'3001:7000': '#ff8a00',
|
||||
'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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -356,6 +356,40 @@ angular.module('netStatsApp.filters', [])
|
||||
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() {
|
||||
return function(time) {
|
||||
if(time < 60)
|
||||
|
@ -209,5 +209,5 @@ block content
|
||||
div.propagationBox
|
||||
span {{node.stats.block.propagation | blockPropagationFilter}}
|
||||
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 }}
|
||||
|
Loading…
Reference in New Issue
Block a user