From 40cddc175db9f2b6f6cbf41599a1c989eaec5c72 Mon Sep 17 00:00:00 2001 From: cubedro Date: Sat, 4 Apr 2015 22:35:45 +0300 Subject: [PATCH] fixed block time math --- models/node.js | 2 +- public/css/style.css | 2 +- public/js/controllers.js | 61 ++++++++++++++++++++++------------------ public/js/filters.js | 15 ++++++---- views/index.jade | 12 ++++---- 5 files changed, 51 insertions(+), 41 deletions(-) diff --git a/models/node.js b/models/node.js index 1830e17..8edc66b 100644 --- a/models/node.js +++ b/models/node.js @@ -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; } diff --git a/public/css/style.css b/public/css/style.css index 265c0ae..76449a8 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -1,5 +1,5 @@ body { - min-width: 1920px; + min-width: 1900px; font-smooth: auto; -webkit-font-smoothing: antialiased; -moz-font-smoothing: antialiased; diff --git a/public/js/controllers.js b/public/js/controllers.js index 4f0c0e6..50d570a 100644 --- a/public/js/controllers.js +++ b/public/js/controllers.js @@ -124,49 +124,54 @@ 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.lastDifficulty = _.max($scope.nodes, function(node) { - return parseInt(node.stats.block.timestamp); - }).stats.block.difficulty; + $scope.lastBlock = _.max($scope.nodes, function(node) { + return parseInt(node.stats.block.number); + }).stats.block.received; - $scope.avgBlockTime = _.max($scope.nodes, function(node) { - return parseInt(node.stats.block.timestamp); - }).stats.blocktimeAvg; + $scope.lastBlocksTime = _.max($scope.nodes, function(node) { + return parseInt(node.stats.block.number); + }).stats.blockTimes; - $scope.upTimeTotal = _.reduce($scope.nodes, function(total, node) { - return total + node.stats.uptime; - }, 0) / $scope.nodes.length; + jQuery('.spark-blocktimes').sparkline($scope.lastBlocksTime.reverse(), {type: 'bar', tooltipSuffix: 's'}); - $scope.lastBlocksTime = _.max($scope.nodes, function(node) { - return parseInt(node.stats.block.number); - }).stats.blockTimes; + $scope.difficultyChange = _.max($scope.nodes, function(node) { + return parseInt(node.stats.block.number); + }).stats.difficulty; - jQuery('.spark-blocktimes').sparkline($scope.lastBlocksTime, {type: 'bar', tooltipSuffix: 's'}); + jQuery('.spark-difficulty').sparkline($scope.difficultyChange.reverse(), {type: 'bar'}); - $scope.difficultyChange = _.max($scope.nodes, function(node) { - return parseInt(node.stats.block.number); - }).stats.difficulty; + $scope.transactionDensity = _.max($scope.nodes, function(node) { + return parseInt(node.stats.block.number); + }).stats.txDensity; - jQuery('.spark-difficulty').sparkline($scope.difficultyChange, {type: 'bar'}); + jQuery('.spark-transactions').sparkline($scope.transactionDensity.reverse(), {type: 'bar'}); - $scope.transactionDensity = _.max($scope.nodes, function(node) { - return parseInt(node.stats.block.number); - }).stats.txDensity; + $scope.gasSpending = _.max($scope.nodes, function(node) { + return parseInt(node.stats.block.number); + }).stats.gasSpending; - jQuery('.spark-transactions').sparkline($scope.transactionDensity, {type: 'bar'}); + jQuery('.spark-gasspending').sparkline($scope.gasSpending.reverse(), {type: 'bar'}); + } - $scope.gasSpending = _.max($scope.nodes, function(node) { + $scope.lastDifficulty = _.max($scope.nodes, function(node) { return parseInt(node.stats.block.number); - }).stats.gasSpending; + }).stats.block.difficulty; - jQuery('.spark-gasspending').sparkline($scope.gasSpending, {type: 'bar'}); + $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) { if(node.geo != null) diff --git a/public/js/filters.js b/public/js/filters.js index 06a2e5c..f38d23b 100644 --- a/public/js/filters.js +++ b/public/js/filters.js @@ -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); diff --git a/views/index.jade b/views/index.jade index 9f9539f..2d57d49 100644 --- a/views/index.jade +++ b/views/index.jade @@ -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 }}