fixed block time math

This commit is contained in:
cubedro 2015-04-04 22:35:45 +03:00
parent 503dd93641
commit 40cddc175d
5 changed files with 53 additions and 43 deletions

View File

@ -91,7 +91,7 @@ Node.prototype.setStats = function(stats)
if(typeof stats !== 'undefined' && typeof stats.block !== 'undefined' && typeof stats.block.number !== 'undefined')
{
if(stats.block.number !== this.stats.block.number) {
stats.block.received = (new Date()).getTime() - stats.block.arrival;
stats.block.received = (new Date()).getTime();
} else {
stats.block.received = this.stats.block.received;
}

View File

@ -1,5 +1,5 @@
body {
min-width: 1920px;
min-width: 1900px;
font-smooth: auto;
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased;

View File

@ -124,50 +124,55 @@ function StatsCtrl($scope, $filter, socket, _, toastr) {
return node.stats.active == true;
}).length;
$scope.bestBlock = _.max($scope.nodes, function(node) {
var bestBlock = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number);
}).stats.block.number;
$scope.lastBlock = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.timestamp);
}).stats.block.timestamp;
if(bestBlock > $scope.bestBlock)
{
$scope.bestBlock = bestBlock;
$scope.lastBlock = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number);
}).stats.block.received;
$scope.lastBlocksTime = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number);
}).stats.blockTimes;
jQuery('.spark-blocktimes').sparkline($scope.lastBlocksTime.reverse(), {type: 'bar', tooltipSuffix: 's'});
$scope.difficultyChange = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number);
}).stats.difficulty;
jQuery('.spark-difficulty').sparkline($scope.difficultyChange.reverse(), {type: 'bar'});
$scope.transactionDensity = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number);
}).stats.txDensity;
jQuery('.spark-transactions').sparkline($scope.transactionDensity.reverse(), {type: 'bar'});
$scope.gasSpending = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number);
}).stats.gasSpending;
jQuery('.spark-gasspending').sparkline($scope.gasSpending.reverse(), {type: 'bar'});
}
$scope.lastDifficulty = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.timestamp);
return parseInt(node.stats.block.number);
}).stats.block.difficulty;
$scope.avgBlockTime = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.timestamp);
return parseInt(node.stats.block.number);
}).stats.blocktimeAvg;
$scope.upTimeTotal = _.reduce($scope.nodes, function(total, node) {
return total + node.stats.uptime;
}, 0) / $scope.nodes.length;
$scope.lastBlocksTime = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number);
}).stats.blockTimes;
jQuery('.spark-blocktimes').sparkline($scope.lastBlocksTime, {type: 'bar', tooltipSuffix: 's'});
$scope.difficultyChange = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number);
}).stats.difficulty;
jQuery('.spark-difficulty').sparkline($scope.difficultyChange, {type: 'bar'});
$scope.transactionDensity = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number);
}).stats.txDensity;
jQuery('.spark-transactions').sparkline($scope.transactionDensity, {type: 'bar'});
$scope.gasSpending = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number);
}).stats.gasSpending;
jQuery('.spark-gasspending').sparkline($scope.gasSpending, {type: 'bar'});
$scope.map = _.map($scope.nodes, function(node) {
if(node.geo != null)
return {

View File

@ -75,7 +75,9 @@ angular.module('netStatsApp.filters', [])
};
})
.filter('propagationTimeClass', function() {
return function(propagation) {
return function(arrival, best) {
var propagation = arrival - best;
if(propagation <= 3000)
return 'text-success';
@ -112,8 +114,9 @@ angular.module('netStatsApp.filters', [])
if(timestamp === 0)
return '∞';
var time = Math.floor((new Date()).getTime() / 1000);
var diff = time - timestamp;
// var time = Math.floor((new Date()).getTime() / 1000);
var time = (new Date()).getTime();
var diff = Math.floor((time - timestamp)/1000);
if(diff < 60)
return Math.round(diff) + ' s ago';
@ -122,7 +125,8 @@ angular.module('netStatsApp.filters', [])
};
})
.filter('blockPropagationFilter', function() {
return function(ms) {
return function(arrival, best) {
var ms = arrival - best;
var result = 0;
if(ms < 1000) {
@ -210,7 +214,8 @@ function peerClass(peers)
function timeClass(timestamp)
{
var time = Math.floor((new Date()).getTime() / 1000);
// var time = Math.floor((new Date()).getTime() / 1000);
var time = (new Date()).getTime();
var diff = time - timestamp;
return blockTimeClass(diff);

View File

@ -67,22 +67,22 @@ block content
div.col-xs-3.stat-holder
div.row.big-info.chart
span.small-title block time
span.big-details.spark-blocktimes {{ lastBlocksTime.join(',') }}
span.big-details.spark-blocktimes
div.col-xs-3.stat-holder
div.row.big-info.chart
span.small-title difficulty
span.big-details.spark-difficulty {{ difficultyChange.join(',') }}
span.big-details.spark-difficulty
div.col-xs-3.stat-holder
div.row.big-info.chart
span.small-title transactions
span.big-details.spark-transactions {{ transactionDensity.join(',') }}
span.big-details.spark-transactions
div.col-xs-3.stat-holder
div.row.big-info.chart
span.small-title gas spending
span.big-details.spark-gasspending {{ gasSpending.join(',') }}
span.big-details.spark-gasspending
//- div.clearfix
@ -139,6 +139,6 @@ block content
span.small {{node.stats.block.hash | hashFilter}}
//- 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(class="{{ node.stats.block.timestamp | timeClass }}") {{node.stats.block.timestamp | blockTimeFilter }}
td(class="{{ node.stats.block.propagation | propagationTimeClass }}") {{node.stats.block.propagation | blockPropagationFilter}}
td(class="{{ node.stats.block.timestamp | timeClass }}") {{node.stats.block.received | blockTimeFilter }}
td(class="{{ node.stats.block.received | propagationTimeClass : lastBlock }}") {{node.stats.block.received | blockPropagationFilter : lastBlock}}
td(class="{{ node.stats.uptime | upTimeClass }}") {{ node.stats.uptime | upTimeFilter }}