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(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.arrival; stats.block.received = (new Date()).getTime();
} else { } else {
stats.block.received = this.stats.block.received; stats.block.received = this.stats.block.received;
} }

View File

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

View File

@ -124,49 +124,54 @@ function StatsCtrl($scope, $filter, socket, _, toastr) {
return node.stats.active == true; return node.stats.active == true;
}).length; }).length;
$scope.bestBlock = _.max($scope.nodes, function(node) { var bestBlock = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number); return parseInt(node.stats.block.number);
}).stats.block.number; }).stats.block.number;
if(bestBlock > $scope.bestBlock)
{
$scope.bestBlock = bestBlock;
$scope.lastBlock = _.max($scope.nodes, function(node) { $scope.lastBlock = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.timestamp); return parseInt(node.stats.block.number);
}).stats.block.timestamp; }).stats.block.received;
$scope.lastDifficulty = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.timestamp);
}).stats.block.difficulty;
$scope.avgBlockTime = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.timestamp);
}).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) { $scope.lastBlocksTime = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number); return parseInt(node.stats.block.number);
}).stats.blockTimes; }).stats.blockTimes;
jQuery('.spark-blocktimes').sparkline($scope.lastBlocksTime, {type: 'bar', tooltipSuffix: 's'}); jQuery('.spark-blocktimes').sparkline($scope.lastBlocksTime.reverse(), {type: 'bar', tooltipSuffix: 's'});
$scope.difficultyChange = _.max($scope.nodes, function(node) { $scope.difficultyChange = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number); return parseInt(node.stats.block.number);
}).stats.difficulty; }).stats.difficulty;
jQuery('.spark-difficulty').sparkline($scope.difficultyChange, {type: 'bar'}); jQuery('.spark-difficulty').sparkline($scope.difficultyChange.reverse(), {type: 'bar'});
$scope.transactionDensity = _.max($scope.nodes, function(node) { $scope.transactionDensity = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number); return parseInt(node.stats.block.number);
}).stats.txDensity; }).stats.txDensity;
jQuery('.spark-transactions').sparkline($scope.transactionDensity, {type: 'bar'}); jQuery('.spark-transactions').sparkline($scope.transactionDensity.reverse(), {type: 'bar'});
$scope.gasSpending = _.max($scope.nodes, function(node) { $scope.gasSpending = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number); return parseInt(node.stats.block.number);
}).stats.gasSpending; }).stats.gasSpending;
jQuery('.spark-gasspending').sparkline($scope.gasSpending, {type: 'bar'}); jQuery('.spark-gasspending').sparkline($scope.gasSpending.reverse(), {type: 'bar'});
}
$scope.lastDifficulty = _.max($scope.nodes, function(node) {
return parseInt(node.stats.block.number);
}).stats.block.difficulty;
$scope.avgBlockTime = _.max($scope.nodes, function(node) {
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.map = _.map($scope.nodes, function(node) { $scope.map = _.map($scope.nodes, function(node) {
if(node.geo != null) if(node.geo != null)

View File

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

View File

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